diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 78f192831..0993a6ca5 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -1,81 +1,204 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapCheckboxTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "check_box is wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms') end test "disabled check_box has proper wrapper classes" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true) end test "check_box label allows html" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: %{I agree to the terms}.html_safe) end test "check_box accepts a block to define the label" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms) { "I agree to the terms" } end test "check_box accepts a custom label class" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, label_class: 'btn') end test "check_box responds to checked_value and unchecked_value arguments" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') end test "inline checkboxes" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) end test "disabled inline check_box" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true) end test "inline checkboxes with custom label class" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.check_box(:terms, inline: true, label_class: 'btn') end test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end test 'collection_check_boxes renders multiple checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street) end test 'collection_check_boxes renders inline checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true) end test 'collection_check_boxes renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first) @@ -83,7 +206,24 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection) @@ -91,42 +231,136 @@ def setup test 'collection_check_boxes sanitizes values when generating label `for`' do collection = [Address.new(id: 1, street: 'Foo St')] - expected = %{
} - + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :street, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} - + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first) @@ -134,29 +368,70 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc + +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) end test "check_box is wrapped correctly with custom option set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms', custom: true}) end test "check_box is wrapped correctly with custom and inline options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms', inline: true, custom: true}) end test "check_box is wrapped correctly with custom and disabled options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms', disabled: true, custom: true}) end test "check_box is wrapped correctly with custom, inline and disabled options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms', inline: true, disabled: true, custom: true}) end end diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index 021c8a0e5..dcba190b9 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -1,39 +1,67 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapFieldsTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "color fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.color_field(:misc) end test "date fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.date_field(:misc) end test "date time fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.datetime_field(:misc) end test "date time local fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.datetime_local_field(:misc) end test "email fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.email_field(:misc) end test "file fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.file_field(:misc) end @@ -43,58 +71,114 @@ def setup end test "month local fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.month_field(:misc) end test "number fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.number_field(:misc) end test "password fields are wrapped correctly" do - expected = %{
A good password should be at least six characters long
} + expected = <<-HTML.strip_heredoc +
+ + + A good password should be at least six characters long +
+ HTML assert_equivalent_xml expected, @builder.password_field(:password) end test "phone/telephone fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.phone_field(:misc) assert_equivalent_xml expected, @builder.telephone_field(:misc) end test "range fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.range_field(:misc) end test "search fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.search_field(:misc) end test "text areas are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_area(:comments) end test "text fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email) end test "time fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.time_field(:misc) end test "url fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.url_field(:misc) end test "week fields are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.week_field(:misc) end @@ -107,7 +191,15 @@ def setup end end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, output end @@ -120,7 +212,15 @@ def setup end end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, output end @@ -133,7 +233,17 @@ def setup end end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, output end @@ -146,7 +256,15 @@ def setup end end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, output end end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index b41407e54..d0332578c 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -1,59 +1,116 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapFormGroupTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "changing the label text via the label option parameter" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, label: 'Email Address') end test "changing the label text via the html_options label hash" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, label: {text: 'Email Address'}) end test "hiding a label" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, hide_label: true) end test "adding a custom label class via the label_class parameter" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, label_class: 'btn') end test "adding a custom label class via the html_options label hash" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn'}) end test "adding a custom label and changing the label text via the html_options label hash" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"}) end test "skipping a label" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, skip_label: true) end test "preventing a label from having the required class" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, skip_required: true) end test "adding prepend text" do - expected = %{
@
} + expected = <<-HTML.strip_heredoc +
+ +
+
+ @ +
+ +
+
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, prepend: '@') end test "adding append text" do - expected = %{
.00
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ .00 +
+
+
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, append: '.00') end @@ -73,22 +130,55 @@ def setup end test "adding both prepend and append text" do - expected = %{
$
.00
} + expected = <<-HTML.strip_heredoc +
+ +
+
+ $
+
+ +
+ .00 +
+
+ + HTML assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00') end test "help messages for default forms" do - expected = %{
This is required
} + expected = <<-HTML.strip_heredoc +
+ + + This is required +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do - expected = %{
This is required
} + expected = <<-HTML.strip_heredoc +
+ +
+ + This is required +
+
+ HTML assert_equivalent_xml expected, @horizontal_builder.text_field(:email, help: "This is required") end test "help messages to look up I18n automatically" do - expected = %{
A good password should be at least six characters long
} + expected = <<-HTML.strip_heredoc +
+ + + A good password should be at least six characters long +
+ HTML assert_equivalent_xml expected, @builder.text_field(:password) end @@ -111,7 +201,12 @@ def setup end test "help messages to ignore translation when user disables help" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:password, help: false) end @@ -120,7 +215,14 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+ +
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -129,7 +231,13 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -138,7 +246,14 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+ +
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -147,7 +262,13 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -156,7 +277,13 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -165,7 +292,14 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+ +
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -177,12 +311,22 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+

Bar

+
can't be blank, is too short (minimum is 5 characters)
+
+ HTML assert_equivalent_xml expected, output end test "adds class to wrapped form_group by a field" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.search_field(:misc, wrapper_class: 'none-margin') end @@ -190,7 +334,17 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+
+ +
+
+ +
+
can't be blank, is too short (minimum is 5 characters)
+
+ HTML assert_equivalent_xml expected, @builder.email_field(:email, wrapper_class: 'none-margin') end @@ -202,7 +356,16 @@ def setup f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
can't be blank, is too short (minimum is 5 characters)
+
+
+ HTML assert_equivalent_xml expected, output end @@ -211,7 +374,13 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+
+ +
+
+ HTML assert_equivalent_xml expected, output end @@ -220,12 +389,24 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+
+ +
+
+ HTML assert_equivalent_xml expected, output end test "adding an icon to a field" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.email_field(:misc, icon: 'ok') end @@ -237,17 +418,37 @@ def setup output = output + @horizontal_builder.text_field(:email) - expected = %{
Hallo
} + expected = <<-HTML.strip_heredoc +
+
Hallo
+
+
+ +
+ +
+
+ HTML assert_equivalent_xml expected, output end test "adds data-attributes (or any other options) to wrapper" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } }) end test "passing options to a form control get passed through" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.text_field(:email, autofocus: true) end @@ -256,12 +457,24 @@ def setup nil end - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, output end test "custom form group layout option" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline } end @@ -271,7 +484,13 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = <<-HTML.strip_heredoc +
+
+

Bar

+
+
+ HTML assert_equivalent_xml expected, output end @@ -284,7 +503,17 @@ def setup end test ":input_group_class should apply to input-group" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, @builder.email_field(:email, append: @builder.primary('Subscribe'), input_group_class: 'input-group-lg') end end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index cf4fb5c60..b96850b2a 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -1,47 +1,94 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapFormTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "default-style forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| nil } end test "inline-style forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :inline) { |f| nil } end test "horizontal-style forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email } end test "existing styles aren't clobbered when specifying a form style" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email } end test "given role attribute should not be covered by default role attribute" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, html: { role: 'not-a-form'}) {|f| nil} end test "bootstrap_form_tag acts like a form tag" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, label: "Your Email" } end test "bootstrap_form_tag does not clobber custom options" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, name: 'NAME', id: "ID" } end + # TODO: difference in rendering between 5.0 and 5.1? test "bootstrap_form_tag allows an empty name for checkboxes" do checkbox = if ::Rails::VERSION::STRING >= '5.1' %{
} @@ -56,7 +103,15 @@ def setup @user.email = nil @user.valid? - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, label_errors: true) { |f| f.text_field :email } end @@ -64,33 +119,72 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
can't be blank, is too short (minimum is 5 characters) +
+ + HTML assert_equivalent_xml expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } end test "label error messages use humanized attribute names" do - I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: 'Your e-mail address'}}}}) - - @user.email = nil - @user.valid? - - expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equivalent_xml expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } - - I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) + begin + I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: 'Your e-mail address'}}}}) + + @user.email = nil + @user.valid? + + expected = <<-HTML.strip_heredoc +
+ +
+ + +
can't be blank, is too short (minimum is 5 characters)
+
+
+ HTML + assert_equivalent_xml expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } + + ensure + I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) + end end test "alert message is wrapped correctly" do @user.email = nil @user.valid? - expected = %{

Please fix the following errors:

  • Email can't be blank
  • Email is too short (minimum is 5 characters)
  • Terms must be accepted
} + expected = <<-HTML.strip_heredoc +
+

Please fix the following errors:

+
    +
  • Email can't be blank
  • +
  • Email is too short (minimum is 5 characters)
  • +
  • Terms must be accepted
  • +
+
+ HTML assert_equivalent_xml expected, @builder.alert_message('Please fix the following errors:') end test "changing the class name for the alert message" do @user.email = nil @user.valid? - expected = %{

Please fix the following errors:

  • Email can't be blank
  • Email is too short (minimum is 5 characters)
  • Terms must be accepted
} + expected = <<-HTML.strip_heredoc +
+

Please fix the following errors:

+
    +
  • Email can't be blank
  • +
  • Email is too short (minimum is 5 characters)
  • +
  • Terms must be accepted
  • +
+
+ HTML assert_equivalent_xml expected, @builder.alert_message('Please fix the following errors:', class: 'my-css-class') end @@ -102,7 +196,19 @@ def setup f.alert_message('Please fix the following errors:') end - expected = %{

Please fix the following errors:

  • Email can't be blank
  • Email is too short (minimum is 5 characters)
  • Terms must be accepted
} + expected = <<-HTML.strip_heredoc +
+ +
+

Please fix the following errors:

+
    +
  • Email can't be blank
  • +
  • Email is too short (minimum is 5 characters)
  • +
  • Terms must be accepted
  • +
+
+
+ HTML assert_equivalent_xml expected, output end @@ -114,7 +220,14 @@ def setup f.alert_message('Please fix the following errors:', error_summary: false) end - expected = %{

Please fix the following errors:

} + expected = <<-HTML.strip_heredoc +
+ +
+

Please fix the following errors:

+
+
+ HTML assert_equivalent_xml expected, output end @@ -126,7 +239,19 @@ def setup f.alert_message('Please fix the following errors:', error_summary: true) end - expected = %{

Please fix the following errors:

  • Email can't be blank
  • Email is too short (minimum is 5 characters)
  • Terms must be accepted
} + expected = <<-HTML.strip_heredoc +
+ +
+

Please fix the following errors:

+
    +
  • Email can't be blank
  • +
  • Email is too short (minimum is 5 characters)
  • +
  • Terms must be accepted
  • +
+
+
+ HTML assert_equivalent_xml expected, output end @@ -134,7 +259,13 @@ def setup @user.email = nil @user.valid? - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.error_summary end @@ -142,22 +273,53 @@ def setup @user.email = nil @user.valid? - expected = %{
Email can't be blank, Email is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
Email can't be blank, Email is too short (minimum is 5 characters)
+ HTML assert_equivalent_xml expected, @builder.errors_on(:email) end test "custom label width for horizontal forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' } end test "offset for form group without label respects label width for horizontal forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+
+ +
+
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10') { |f| f.form_group { f.submit } } end test "custom input width for horizontal forms" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ +
+
+
+ HTML assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' } end @@ -169,7 +331,16 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+ +
+ + +
can't be blank, is too short (minimum is 5 characters)
+
+
+ HTML assert_equivalent_xml expected, output end @@ -181,7 +352,20 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = <<-HTML.strip_heredoc +
+ +
+
+ +
+
+ +
+
can't be blank, is too short (minimum is 5 characters) +
+ + HTML assert_equivalent_xml expected, output end @@ -193,26 +377,51 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
This is required
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + This is required +
+
+ HTML assert_equivalent_xml expected, output end test "help translations do not escape HTML when _html is appended to the name" do - I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: "This is useful help"}}}}) - - output = bootstrap_form_for(@user) do |f| - f.text_field(:email) + begin + I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: "This is useful help"}}}}) + + output = bootstrap_form_for(@user) do |f| + f.text_field(:email) + end + + expected = <<-HTML.strip_heredoc +
+ +
+ + + This is useful help +
+
+ HTML + assert_equivalent_xml expected, output + ensure + I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: nil}}}}) end - - expected = %{
This is useful help
} - assert_equivalent_xml expected, output - - I18n.backend.store_translations(:en, {activerecord: {help: {user: {email_html: nil}}}}) end test "allows the form object to be nil" do builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {} - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, builder.text_field(:email) end diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index ea92ae609..f8e1d840a 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -1,16 +1,21 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapOtherComponentsTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "static control" do output = @horizontal_builder.static_control :email - expected = %{

steve@example.com

} + expected = <<-HTML.strip_heredoc +
+ +
+

steve@example.com

+
+
+ HTML assert_equivalent_xml expected, output end @@ -19,7 +24,14 @@ def setup "this is a test" end - expected = %{

this is a test

} + expected = <<-HTML.strip_heredoc +
+ +
+

this is a test

+
+
+ HTML assert_equivalent_xml expected, output end @@ -28,7 +40,14 @@ def setup "Custom Control" end - expected = %{

Custom Control

} + expected = <<-HTML.strip_heredoc +
+ +
+

Custom Control

+
+
+ HTML assert_equivalent_xml expected, output end @@ -37,7 +56,12 @@ def setup "this is a test" end - expected = %{
this is a test
} + expected = <<-HTML.strip_heredoc +
+ +
this is a test
+
+ HTML assert_equivalent_xml expected, output end @@ -46,7 +70,12 @@ def setup "this is a test" end - expected = %{
this is a test
} + expected = <<-HTML.strip_heredoc +
+ +
this is a test
+
+ HTML assert_equivalent_xml expected, output end @@ -55,7 +84,12 @@ def setup "Custom Control" end - expected = %{
Custom Control
} + expected = <<-HTML.strip_heredoc +
+ +
Custom Control
+
+ HTML assert_equivalent_xml expected, output end diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index cd4ca68b1..1def08c20 100644 --- a/test/bootstrap_radio_button_test.rb +++ b/test/bootstrap_radio_button_test.rb @@ -1,142 +1,342 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapRadioButtonTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture - end + setup :setup_test_fixture test "radio_button is wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button') end test "radio_button disabled label is set correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', disabled: true) end test "radio_button label class is set correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', label_class: 'btn') end test "radio_button inline label is set correctly" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true) end test "radio_button disabled inline label is set correctly" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true, disabled: true) end test "radio_button inline label class is set correctly" do - expected = %{} + expected = <<-HTML.strip_heredoc + + HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true, label_class: 'btn') end test 'collection_radio_buttons renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders multiple radios correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street) end test 'collection_radio_buttons renders inline radios correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + + +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, inline: true) end test 'collection_radio_buttons renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, checked: 1) end test 'collection_radio_buttons renders label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders multiple radios with label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_radio_buttons renders multiple radios with value defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_radio_buttons renders label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+ With a help! +
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders multiple radios with label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_radio_buttons renders multiple radios with value defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ +
+ +
+
+ +
+
+ HTML assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end test "radio_button is wrapped correctly with custom option set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', {label: 'This is a radio button', custom: true}) end test "radio_button is wrapped correctly with custom and inline options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', {label: 'This is a radio button', inline: true, custom: true}) end test "radio_button is wrapped correctly with custom and disabled options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', {label: 'This is a radio button', disabled: true, custom: true}) end test "radio_button is wrapped correctly with custom, inline and disabled options set" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.radio_button(:misc, '1', {label: 'This is a radio button', inline: true, disabled: true, custom: true}) end + end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index a701a289b..5dd9dc2b0 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -1,34 +1,83 @@ -require 'test_helper' +require_relative "./test_helper" class BootstrapSelectsTest < ActionView::TestCase include BootstrapForm::Helper - def setup - setup_test_fixture + setup :setup_test_fixture + + # Helper to generate options + def options_range(start: 1, stop: 31, selected: nil, months: false) + (start..stop).map do |n| + attr = (n == selected) ? 'selected="selected"' : "" + label = months ? Date::MONTHNAMES[n] : n + "" + end.join("\n") end test "time zone selects are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.time_zone_select(:misc) end test "selects are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]]) end test "bootstrap_specific options are handled correctly" do - expected = %{
Help!
} + expected = <<-HTML.strip_heredoc +
+ + + Help! +
+ HTML assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) end test "selects with options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prompt: "Please Select") end test "selects with both options and html_options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select") end @@ -51,7 +100,15 @@ def setup if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0") test "selects with block use block as content" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML select = @builder.select(:status) do content_tag(:option) { 'Option 1' } + content_tag(:option) { 'Option 2' } @@ -61,99 +118,328 @@ def setup end test "selects render labels properly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "User Status") end test "collection_selects are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name) end test "collection_selects with options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name, prompt: "Please Select") end test "collection_selects with options and html_options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select") end test "grouped_collection_selects are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s) end test "grouped_collection_selects with options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, prompt: "Please Select") end test "grouped_collection_selects with options and html_options are wrapped correctly" do - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, { prompt: "Please Select" }, class: "my-select") end test "date selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + +
+
+ HTML assert_equivalent_xml expected, @builder.date_select(:misc) end end test "date selects with options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + +
+
+ HTML + assert_equivalent_xml expected, @builder.date_select(:misc, include_blank: true) end end test "date selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + +
+
+ HTML assert_equivalent_xml expected, @builder.date_select(:misc, { include_blank: true }, class: "my-date-select") end end test "time selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n\n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.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 = %{
\n\n\n\n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.time_select(:misc, include_blank: true) end end test "time selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n\n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.time_select(:misc, { include_blank: true }, class: "my-time-select") end end test "datetime selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n — \n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + — + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.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 = %{
\n\n\n — \n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + — + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.datetime_select(:misc, include_blank: true) end end test "datetime selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n — \n : \n
} + expected = <<-HTML.strip_heredoc +
+ +
+ + + + — + + : + +
+
+ HTML assert_equivalent_xml expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select") end end diff --git a/test/special_form_class_models_test.rb b/test/special_form_class_models_test.rb index 5c3e428e0..d53017d8d 100644 --- a/test/special_form_class_models_test.rb +++ b/test/special_form_class_models_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require_relative "./test_helper" class SpecialFormClassModelsTest < ActionView::TestCase include BootstrapForm::Helper @@ -14,7 +14,12 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.date_field(:misc) end @@ -24,7 +29,12 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.date_field(:misc) end @@ -36,7 +46,12 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {faux_user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = <<-HTML.strip_heredoc +
+ + +
+ HTML assert_equivalent_xml expected, @builder.date_field(:misc) end