Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ class BootstrapFieldsTest < ActionView::TestCase
assert_equivalent_xml expected, @builder.file_field(:misc)
end

test "file fields are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" enctype="multipart/form-data" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_misc">Misc</label>
<input class="form-control-file is-invalid" id="user_misc" name="user[misc]" type="file" />
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.file_field(:misc) }
end

test "hidden fields are supported" do
expected = %{<input id="user_misc" name="user[misc]" type="hidden" />}
assert_equivalent_xml expected, @builder.hidden_field(:misc)
Expand Down
135 changes: 135 additions & 0 deletions test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
assert_equivalent_xml expected, @builder.time_zone_select(:misc)
end

test "time zone selects are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_misc">Misc</label>
<select class="form-control is-invalid" id="user_misc" name="user[misc]">#{time_zone_options_for_select}</select>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.time_zone_select(:misc) }
end

test "selects are wrapped correctly" do
expected = <<-HTML.strip_heredoc
<div class="form-group">
Expand Down Expand Up @@ -150,6 +165,21 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name)
end

test "collection_selects are wrapped correctly with error" do
@user.errors.add(:status, "error for test")
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_status">Status</label>
<select class="form-control is-invalid" id="user_status" name="user[status]"></select>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.collection_select(:status, [], :id, :name) }
end

test "collection_selects with options are wrapped correctly" do
expected = <<-HTML.strip_heredoc
<div class="form-group">
Expand Down Expand Up @@ -184,6 +214,21 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s)
end

test "grouped_collection_selects are wrapped correctly with error" do
@user.errors.add(:status, "error for test")
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_status">Status</label>
<select class="form-control is-invalid" id="user_status" name="user[status]"></select>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s) }
end

test "grouped_collection_selects with options are wrapped correctly" do
expected = <<-HTML.strip_heredoc
<div class="form-group">
Expand Down Expand Up @@ -230,6 +275,33 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
end
end

test "date selects are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
Timecop.freeze(Time.utc(2012, 2, 3)) do
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-date-select">
<select class="form-control is-invalid" id="user_misc_1i" name="user[misc(1i)]">
#{options_range(start: 2007, stop: 2017, selected: 2012)}
</select>
<select class="form-control is-invalid" id="user_misc_2i" name="user[misc(2i)]">
#{options_range(start: 1, stop: 12, selected: 2, months: true)}
</select>
<select class="form-control is-invalid" id="user_misc_3i" name="user[misc(3i)]">
#{options_range(start: 1, stop: 31, selected: 3)}
</select>
</div>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.date_select(:misc) }
end
end

test "date selects with options are wrapped correctly" do
Timecop.freeze(Time.utc(2012, 2, 3)) do
expected = <<-HTML.strip_heredoc
Expand Down Expand Up @@ -304,6 +376,34 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
end
end

test "time selects are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-time-select">
<input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />
<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />
<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />
<select class="form-control is-invalid" id="user_misc_4i" name="user[misc(4i)]">
#{options_range(start: "00", stop: "23", selected: "12")}
</select>
:
<select class="form-control is-invalid" id="user_misc_5i" name="user[misc(5i)]">
#{options_range(start: "00", stop: "59", selected: "00")}
</select>
</div>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.time_select(:misc) }
end
end

test "time selects with options are wrapped correctly" do
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
expected = <<-HTML.strip_heredoc
Expand Down Expand Up @@ -384,6 +484,41 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
end
end

test "datetime selects are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group">
<label for="user_misc">Misc</label>
<div class="rails-bootstrap-forms-datetime-select">
<select class="form-control is-invalid" id="user_misc_1i" name="user[misc(1i)]">
#{options_range(start: 2007, stop: 2017, selected: 2012)}
</select>
<select class="form-control is-invalid" id="user_misc_2i" name="user[misc(2i)]">
#{options_range(start: 1, stop: 12, selected: 2, months: true)}
</select>
<select class="form-control is-invalid" id="user_misc_3i" name="user[misc(3i)]">
#{options_range(start: 1, stop: 31, selected: 3)}
</select>
&mdash;
<select class="form-control is-invalid" id="user_misc_4i" name="user[misc(4i)]">
#{options_range(start: "00", stop: "23", selected: "12")}
</select>
:
<select class="form-control is-invalid" id="user_misc_5i" name="user[misc(5i)]">
#{options_range(start: "00", stop: "59", selected: "00")}
</select>
</div>
<div class="invalid-feedback">error for test</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| f.datetime_select(:misc) }
end
end

test "datetime selects with options are wrapped correctly" do
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
expected = <<-HTML.strip_heredoc
Expand Down