diff --git a/.gitignore b/.gitignore index f77c265de..ca20e21f3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ test/dummy/tmp/ *.gem .rbenv-gemsets *.swp +gemfiles/*.lock +Gemfile.lock diff --git a/.travis.yml b/.travis.yml index cbe0f6462..f0fa6eec9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,19 @@ rvm: - 2.1 - 2.2 - 2.3.0 +gemfile: + - gemfiles/4.0.gemfile + - gemfiles/4.1.gemfile + - gemfiles/4.2.gemfile + - gemfiles/5.0.gemfile +matrix: + exclude: + - rvm: 1.9 + gemfile: gemfiles/5.0.gemfile + - rvm: 2.0 + gemfile: gemfiles/5.0.gemfile + - rvm: 2.1 + gemfile: gemfiles/5.0.gemfile before_install: - gem install bundler --conservative --version '~> 1.10' before_script: diff --git a/Appraisals b/Appraisals new file mode 100644 index 000000000..d7bec14c3 --- /dev/null +++ b/Appraisals @@ -0,0 +1,19 @@ +appraise "4.0" do + gem "rails", "~> 4.0.0" + gemspec +end + +appraise "4.1" do + gem "rails", "~> 4.1.0" + gemspec +end + +appraise "4.2" do + gem "rails", "~> 4.2" + gemspec +end + +appraise "5.0" do + gem "rails", "~> 5.0" + gemspec +end diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e51ef160..32cf03c1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Bugfixes: - Your contribution here! Features: + - The project is now tested against and compatible with the following Rails versions 4.0, 4.1, 4.2 and 5.0 (#278). - Your contribution here! ## [2.5.2][] (2016-10-08) diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 6ba43273b..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,92 +0,0 @@ -PATH - remote: . - specs: - bootstrap_form (2.5.2) - -GEM - remote: http://rubygems.org/ - specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) - mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) - rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) - builder (3.1.4) - concurrent-ruby (1.0.2) - erubis (2.7.0) - i18n (0.7.0) - jquery-rails (3.1.4) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) - mail (2.6.4) - mime-types (>= 1.16, < 4) - metaclass (0.0.4) - mime-types (2.6.2) - minitest (4.7.5) - mocha (1.1.0) - metaclass (~> 0.0.1) - multi_json (1.12.1) - rack (1.5.5) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) - bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) - sprockets-rails (~> 2.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (11.2.2) - sprockets (3.6.3) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.11) - thor (0.19.1) - thread_safe (0.3.5) - timecop (0.7.4) - tzinfo (0.3.50) - -PLATFORMS - ruby - -DEPENDENCIES - bootstrap_form! - jquery-rails - mime-types (~> 2.6.2) - mocha - rails (~> 4.0) - sqlite3 - timecop (~> 0.7.1) - -BUNDLED WITH - 1.13.2 diff --git a/README.md b/README.md index 1bf9ab036..c1404a130 100644 --- a/README.md +++ b/README.md @@ -586,24 +586,31 @@ We love pull requests! Here's a quick guide for contributing: 1. Fork the repo. -2. Run the existing test suite: +2. Install the required dependencies. + +``` +bundle install +bundle exec appraisal install +``` + +3. Run the existing test suite: ``` $ bundle exec rake -f test/dummy/Rakefile db:create db:migrate RAILS_ENV=test -$ bundle exec rake +$ bundle exec appraisal rake test ``` -3. Add tests for your change. +4. Add tests for your change. -4. Add your changes and make your test(s) pass. Following the conventions you +5. Add your changes and make your test(s) pass. Following the conventions you see used in the source will increase the chance that your pull request is accepted right away. -5. Update the README if necessary. +6. Update the README if necessary. -6. Add a line to the CHANGELOG for your bug fix or feature. +7. Add a line to the CHANGELOG for your bug fix or feature. -7. Push to your fork and submit a pull request. +8. Push to your fork and submit a pull request. ## Contributors diff --git a/bootstrap_form.gemspec b/bootstrap_form.gemspec index e00d20390..2510a7eaa 100644 --- a/bootstrap_form.gemspec +++ b/bootstrap_form.gemspec @@ -17,8 +17,12 @@ Gem::Specification.new do |s| s.test_files = Dir["test/**/*"] s.add_development_dependency "mime-types", "~> 2.6.2" - s.add_development_dependency "rails", "~> 4.0" + s.add_development_dependency "rails", ">= 4.0" s.add_development_dependency "sqlite3" s.add_development_dependency "timecop", "~> 0.7.1" s.add_development_dependency "mocha" + s.add_development_dependency "appraisal" + s.add_development_dependency "equivalent-xml" + s.add_development_dependency "nokogiri" + s.add_development_dependency "diffy" end diff --git a/gemfiles/4.0.gemfile b/gemfiles/4.0.gemfile new file mode 100644 index 000000000..8dfafacf4 --- /dev/null +++ b/gemfiles/4.0.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "jquery-rails" +gem "rails", "~> 4.0.0" + +gemspec :path => "../" diff --git a/gemfiles/4.1.gemfile b/gemfiles/4.1.gemfile new file mode 100644 index 000000000..0b050c008 --- /dev/null +++ b/gemfiles/4.1.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "jquery-rails" +gem "rails", "~> 4.1.0" + +gemspec :path => "../" diff --git a/gemfiles/4.2.gemfile b/gemfiles/4.2.gemfile new file mode 100644 index 000000000..9cfae860b --- /dev/null +++ b/gemfiles/4.2.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "jquery-rails" +gem "rails", "~> 4.2" + +gemspec :path => "../" diff --git a/gemfiles/5.0.gemfile b/gemfiles/5.0.gemfile new file mode 100644 index 000000000..1615046de --- /dev/null +++ b/gemfiles/5.0.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "jquery-rails" +gem "rails", "~> 5.0" + +gemspec :path => "../" diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index e9ae6eab9..0d2832690 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -9,135 +9,135 @@ def setup test "check_box is wrapped correctly" do expected = %{
} - assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms') + 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 = %{
} - assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true) + 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 = %{
} - assert_equal expected, @builder.check_box(:terms, label: %{I agree to the terms}.html_safe) + 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 = %{
} - assert_equal expected, @builder.check_box(:terms) { "I agree to the terms" } + assert_equivalent_xml expected, @builder.check_box(:terms) { "I agree to the terms" } end test "check_box accepts a custom label class" do expected = %{
} - assert_equal expected, @builder.check_box(:terms, label_class: 'btn') + 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 = %{
} - assert_equal expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') + assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') end test "inline checkboxes" do expected = %{} - assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) + assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) end test "disabled inline check_box" do expected = %{} - assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true) + 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 = %{} - assert_equal expected, @builder.check_box(:terms, inline: true, label_class: 'btn') + 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!
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first) + 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) end 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection) + 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) end test 'collection_check_boxes sanitizes values when generating label `for`' do collection = [Address.new(id: 1, street: 'Foo St')] expected = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :street, :street) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse }) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse }) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) + 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") - assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first) + 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) end 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 = %{
} - assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) - assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) + 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 diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index 41d889c4b..3eaec8ece 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -9,93 +9,93 @@ def setup test "color fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.color_field(:misc) + assert_equivalent_xml expected, @builder.color_field(:misc) end test "date fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.date_field(:misc) + assert_equivalent_xml expected, @builder.date_field(:misc) end test "date time fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.datetime_field(:misc) + assert_equivalent_xml expected, @builder.datetime_field(:misc) end test "date time local fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.datetime_local_field(:misc) + assert_equivalent_xml expected, @builder.datetime_local_field(:misc) end test "email fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.email_field(:misc) + assert_equivalent_xml expected, @builder.email_field(:misc) end test "file fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.file_field(:misc) + assert_equivalent_xml expected, @builder.file_field(:misc) end test "hidden fields are supported" do expected = %{} - assert_equal expected, @builder.hidden_field(:misc) + assert_equivalent_xml expected, @builder.hidden_field(:misc) end test "month local fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.month_field(:misc) + assert_equivalent_xml expected, @builder.month_field(:misc) end test "number fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.number_field(:misc) + 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
} - assert_equal expected, @builder.password_field(:password) + assert_equivalent_xml expected, @builder.password_field(:password) end test "phone/telephone fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.phone_field(:misc) - assert_equal expected, @builder.telephone_field(:misc) + 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 = %{
} - assert_equal expected, @builder.range_field(:misc) + assert_equivalent_xml expected, @builder.range_field(:misc) end test "search fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.search_field(:misc) + assert_equivalent_xml expected, @builder.search_field(:misc) end test "text areas are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.text_area(:comments) + assert_equivalent_xml expected, @builder.text_area(:comments) end test "text fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.text_field(:email) + assert_equivalent_xml expected, @builder.text_field(:email) end test "time fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.time_field(:misc) + assert_equivalent_xml expected, @builder.time_field(:misc) end test "url fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.url_field(:misc) + assert_equivalent_xml expected, @builder.url_field(:misc) end test "week fields are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.week_field(:misc) + assert_equivalent_xml expected, @builder.week_field(:misc) end test "bootstrap_form_for helper works for associations" do @@ -108,7 +108,7 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "bootstrap_form_for helper works for serialized hash attributes" do @@ -121,7 +121,7 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "fields_for correctly passes horizontal style from parent builder" do @@ -134,7 +134,7 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "fields_for correctly passes inline style from parent builder" do @@ -147,6 +147,6 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 72b0e93c9..26a0a62fb 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -9,52 +9,52 @@ def setup test "changing the label text via the label option parameter" do expected = %{
} - assert_equal expected, @builder.text_field(:email, label: 'Email Address') + 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 = %{
} - assert_equal expected, @builder.text_field(:email, label: {text: 'Email Address'}) + assert_equivalent_xml expected, @builder.text_field(:email, label: {text: 'Email Address'}) end test "hiding a label" do expected = %{
} - assert_equal expected, @builder.text_field(:email, hide_label: true) + 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 = %{
} - assert_equal expected, @builder.text_field(:email, label_class: 'btn') + 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 = %{
} - assert_equal expected, @builder.text_field(:email, label: {class: 'btn'}) + 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 = %{
} - assert_equal expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"}) + assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"}) end test "skipping a label" do expected = %{
} - assert_equal expected, @builder.text_field(:email, skip_label: true) + assert_equivalent_xml expected, @builder.text_field(:email, skip_label: true) end test "preventing a label from having the required class" do expected = %{
} - assert_equal expected, @builder.text_field(:email, skip_required: true) + assert_equivalent_xml expected, @builder.text_field(:email, skip_required: true) end test "adding prepend text" do expected = %{
@
} - assert_equal expected, @builder.text_field(:email, prepend: '@') + assert_equivalent_xml expected, @builder.text_field(:email, prepend: '@') end test "adding append text" do expected = %{
.00
} - assert_equal expected, @builder.text_field(:email, append: '.00') + assert_equivalent_xml expected, @builder.text_field(:email, append: '.00') end test "append and prepend button" do @@ -66,29 +66,29 @@ def setup before_button = prefix + button + field + suffix both_button = prefix + button + field + button + suffix button_src = link_to("Click", "#", class: "btn btn-default") - assert_equal after_button, @builder.text_field(:email, append: button_src) - assert_equal before_button, @builder.text_field(:email, prepend: button_src) - assert_equal both_button, @builder.text_field(:email, append: button_src, prepend: button_src) + assert_equivalent_xml after_button, @builder.text_field(:email, append: button_src) + assert_equivalent_xml before_button, @builder.text_field(:email, prepend: button_src) + assert_equivalent_xml both_button, @builder.text_field(:email, append: button_src, prepend: button_src) end test "adding both prepend and append text" do expected = %{
$.00
} - assert_equal expected, @builder.text_field(:email, prepend: '$', append: '.00') + assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00') end test "help messages for default forms" do expected = %{
This is required
} - assert_equal expected, @builder.text_field(:email, help: 'This is required') + assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do expected = %{
This is required
} - assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required") + 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
} - assert_equal expected, @builder.text_field(:password) + assert_equivalent_xml expected, @builder.text_field(:password) end test "help messages to warn about deprecated I18n key" do @@ -111,7 +111,7 @@ def setup test "help messages to ignore translation when user disables help" do expected = %{
} - assert_equal expected, @builder.text_field(:password, help: false) + assert_equivalent_xml expected, @builder.text_field(:password, help: false) end test "form_group creates a valid structure and allows arbitrary html to be added via a block" do @@ -120,7 +120,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "form_group adds a spacer when no label exists for a horizontal form" do @@ -129,7 +129,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "form_group renders the label correctly" do @@ -138,7 +138,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "form_group accepts class thorugh options hash" do @@ -147,7 +147,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "form_group accepts class thorugh options hash without needing a name" do @@ -156,7 +156,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do @@ -165,7 +165,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test 'form_group renders the "error" class and message corrrectly when object is invalid' do @@ -177,12 +177,12 @@ def setup end expected = %{

Bar

can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "adds class to wrapped form_group by a field" do expected = %{
} - assert_equal expected, @builder.search_field(:misc, wrapper_class: 'none-margin') + assert_equivalent_xml expected, @builder.search_field(:misc, wrapper_class: 'none-margin') end test "adds class to wrapped form_group by a field with errors" do @@ -190,7 +190,7 @@ def setup @user.valid? expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, @builder.email_field(:email, wrapper_class: 'none-margin') + assert_equivalent_xml expected, @builder.email_field(:email, wrapper_class: 'none-margin') end test "adds class to wrapped form_group by a field with errors when bootstrap_form_for is used" do @@ -202,7 +202,7 @@ def setup end expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "adds offset for form_group without label" do @@ -211,7 +211,7 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "adds offset for form_group without label but specific label_col" do @@ -220,12 +220,12 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "adding an icon to a field" do expected = %{
} - assert_equal expected, @builder.email_field(:misc, icon: 'ok') + assert_equivalent_xml expected, @builder.email_field(:misc, icon: 'ok') end test "single form_group call in horizontal form should not be smash design" do @@ -237,17 +237,17 @@ def setup output = output + @horizontal_builder.text_field(:email) expected = %{
Hallo
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "adds data-attributes (or any other options) to wrapper" do expected = %{
} - assert_equal expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } }) + 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 = %{
} - assert_equal expected, @builder.text_field(:email, autofocus: true) + assert_equivalent_xml expected, @builder.text_field(:email, autofocus: true) end test "doesn't throw undefined method error when the content block returns nil" do @@ -256,12 +256,12 @@ def setup end expected = %{
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "custom form group layout option" do expected = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline } + assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline } end test "non-default column span on form is reflected in form_group" do @@ -271,7 +271,7 @@ def setup end expected = %{

Bar

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "non-default column span on form isn't mutated" do @@ -279,11 +279,11 @@ def setup output = frozen_horizontal_builder.form_group { 'test' } expected = %{
test
} - assert_equal expected, output + assert_equivalent_xml expected, output end test ":input_group_class should apply to input-group" do expected = %{
} - assert_equal expected, @builder.email_field(:email, append: @builder.primary('Subscribe'), input_group_class: 'input-group-lg') + 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 f9485e86d..b2bcd5c32 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -9,42 +9,42 @@ def setup test "default-style forms" do expected = %{
} - assert_equal expected, bootstrap_form_for(@user) { |f| nil } + assert_equivalent_xml expected, bootstrap_form_for(@user) { |f| nil } end test "inline-style forms" do expected = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :inline) { |f| nil } + assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :inline) { |f| nil } end test "horizontal-style forms" do expected = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email } + 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 = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email } + 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 = %{
} - assert_equal expected, bootstrap_form_for(@user, html: { role: 'not-a-form'}) {|f| nil} + 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 = %{
} - assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, label: "Your Email" } + 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 = %{
} - assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, name: 'NAME', id: "ID" } + assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, name: 'NAME', id: "ID" } end test "bootstrap_form_tag allows an empty name for checkboxes" do expected = %{
} - assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc } + assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc } end test "errors display correctly and inline_errors are turned off by default when label_errors is true" do @@ -52,7 +52,7 @@ def setup @user.valid? expected = %{
} - assert_equal expected, bootstrap_form_for(@user, label_errors: true) { |f| f.text_field :email } + assert_equivalent_xml expected, bootstrap_form_for(@user, label_errors: true) { |f| f.text_field :email } end test "errors display correctly and inline_errors can also be on when label_errors is true" do @@ -60,7 +60,7 @@ def setup @user.valid? expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } + 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 @@ -70,7 +70,7 @@ def setup @user.valid? expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } + 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}}}}) end @@ -79,14 +79,14 @@ def setup @user.email = nil @user.valid? expected = %{

Please fix the following errors:

} - assert_equal expected, @builder.alert_message('Please fix the following errors:') + 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:

} - assert_equal expected, @builder.alert_message('Please fix the following errors:', class: 'my-css-class') + assert_equivalent_xml expected, @builder.alert_message('Please fix the following errors:', class: 'my-css-class') end test "alert_message contains the error summary when inline_errors are turned off" do @@ -98,7 +98,7 @@ def setup end expected = %{

Please fix the following errors:

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "alert_message allows the error_summary to be turned off" do @@ -110,7 +110,7 @@ def setup end expected = %{

Please fix the following errors:

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "alert_message allows the error_summary to be turned on with inline_errors also turned on" do @@ -122,7 +122,7 @@ def setup end expected = %{

Please fix the following errors:

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "error_summary returns an unordered list of errors" do @@ -130,7 +130,7 @@ def setup @user.valid? expected = %{} - assert_equal expected, @builder.error_summary + assert_equivalent_xml expected, @builder.error_summary end test 'errors_on renders the errors for a specific attribute when invalid' do @@ -138,22 +138,22 @@ def setup @user.valid? expected = %{
Email can't be blank, Email is too short (minimum is 5 characters)
} - assert_equal expected, @builder.errors_on(:email) + assert_equivalent_xml expected, @builder.errors_on(:email) end test "custom label width for horizontal forms" do expected = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' } + 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 = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10') { |f| f.form_group { f.submit } } + 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 = %{
} - assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' } + assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' } end test "the field contains the error and is not wrapped in div.field_with_errors when bootstrap_form_for is used" do @@ -165,7 +165,7 @@ def setup end expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "the field is wrapped with div.field_with_errors when form_for is used" do @@ -177,7 +177,7 @@ def setup end expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "help is preserved when inline_errors: false is passed to bootstrap_form_for" do @@ -189,13 +189,13 @@ def setup end expected = %{
This is required
} - assert_equal expected, output + assert_equivalent_xml expected, output end test "allows the form object to be nil" do builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {} expected = %{
} - assert_equal expected, builder.text_field(:email) + assert_equivalent_xml expected, builder.text_field(:email) end test 'errors_on hide attribute name in message' do @@ -204,6 +204,6 @@ def setup expected = %{
can't be blank, is too short (minimum is 5 characters)
} - assert_equal expected, @builder.errors_on(:email, hide_attribute_name: true) + assert_equivalent_xml expected, @builder.errors_on(:email, hide_attribute_name: true) end end diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index b86fb9d63..1e9f2af6f 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -11,7 +11,7 @@ def setup output = @horizontal_builder.static_control :email expected = %{

steve@example.com

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "static control doesn't require an actual attribute" do @@ -20,7 +20,7 @@ def setup end expected = %{

this is a test

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "static control doesn't require a name" do @@ -29,31 +29,31 @@ def setup end expected = %{

Custom Control

} - assert_equal expected, output + assert_equivalent_xml expected, output end test "submit button defaults to rails action name" do expected = %{} - assert_equal expected, @builder.submit + assert_equivalent_xml expected, @builder.submit end test "submit button uses default button classes" do expected = %{} - assert_equal expected, @builder.submit("Submit Form") + assert_equivalent_xml expected, @builder.submit("Submit Form") end test "override submit button classes" do expected = %{} - assert_equal expected, @builder.submit("Submit Form", class: "btn btn-primary") + assert_equivalent_xml expected, @builder.submit("Submit Form", class: "btn btn-primary") end test "primary button uses proper css classes" do expected = %{} - assert_equal expected, @builder.primary("Submit Form") + assert_equivalent_xml expected, @builder.primary("Submit Form") end test "override primary button classes" do expected = %{} - assert_equal expected, @builder.primary("Submit Form", class: "btn btn-primary disabled") + assert_equivalent_xml expected, @builder.primary("Submit Form", class: "btn btn-primary disabled") end end diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index a1204c879..b420c1e01 100644 --- a/test/bootstrap_radio_button_test.rb +++ b/test/bootstrap_radio_button_test.rb @@ -9,116 +9,116 @@ def setup test "radio_button is wrapped correctly" do expected = %{
} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button') + 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 = %{
} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', disabled: true) + 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 = %{
} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', label_class: 'btn') + 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 = %{} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true) + 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 = %{} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true, disabled: true) + 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 = %{} - assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true, label_class: 'btn') + 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!
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!') + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street) + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, inline: true) + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, checked: 1) + 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!
} - assert_equal 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!') + 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!
} - assert_equal 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!') + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }) + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) + 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!
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') + 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!
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }) + 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 = %{
} - assert_equal expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) + assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 8812d6f2a..80846bcd1 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -9,27 +9,27 @@ def setup test "time zone selects are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.time_zone_select(:misc) + assert_equivalent_xml expected, @builder.time_zone_select(:misc) end test "selects are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]]) + assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]]) end test "bootstrap_specific options are handled correctly" do expected = %{
Help!
} - assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) + 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 = %{
} - assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prompt: "Please Select") + 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 = %{
} - assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select") + assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select") end if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0") @@ -39,105 +39,105 @@ def setup content_tag(:option) { 'Option 1' } + content_tag(:option) { 'Option 2' } end - assert_equal expected, select + assert_equivalent_xml expected, select end end test "selects render labels properly" do expected = %{
} - assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "User Status") + assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "User Status") end test "collection_selects are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.collection_select(:status, [], :id, :name) + assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name) end test "collection_selects with options are wrapped correctly" do expected = %{
} - assert_equal expected, @builder.collection_select(:status, [], :id, :name, prompt: "Please Select") + 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 = %{
} - assert_equal expected, @builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select") + 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 = %{
} - assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s) + 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 = %{
} - assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, prompt: "Please Select") + 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 = %{
} - assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, { prompt: "Please Select" }, class: "my-select") + 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
} - assert_equal expected, @builder.date_select(:misc) + 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
} - assert_equal expected, @builder.date_select(:misc, include_blank: true) + 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
} - assert_equal expected, @builder.date_select(:misc, { include_blank: true }, class: "my-date-select") + 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
} - assert_equal expected, @builder.time_select(:misc) + 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
} - assert_equal expected, @builder.time_select(:misc, include_blank: true) + 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
} - assert_equal expected, @builder.time_select(:misc, { include_blank: true }, class: "my-time-select") + 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
} - assert_equal expected, @builder.datetime_select(:misc) + 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
} - assert_equal expected, @builder.datetime_select(:misc, include_blank: true) + 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
} - assert_equal expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select") + assert_equivalent_xml expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select") end end end diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index 4135d7a46..03926c32f 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -4,3 +4,7 @@ require File.expand_path('../config/application', __FILE__) Dummy::Application.load_tasks + +if Rake::Task.task_defined?(:'db:check_protected_environments') + Rake::Task[:'db:check_protected_environments'].clear +end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index afbc0ae77..aeb6b5550 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -12,9 +12,23 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + version = Rails.version.to_f + # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" + if version < 4.2 + config.serve_static_assets = true + elsif version < 5 + config.serve_static_files = true + end + + if version < 5 + config.static_cache_control = "public, max-age=3600" + else + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=3600" + } + end # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -33,4 +47,7 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # In Rails 5, the default value of this option will change from `:sorted` to `:random`. + config.active_support.test_order = :sorted end diff --git a/test/special_form_class_models_test.rb b/test/special_form_class_models_test.rb index 6e40bed01..2579c9a48 100644 --- a/test/special_form_class_models_test.rb +++ b/test/special_form_class_models_test.rb @@ -15,7 +15,7 @@ def user_klass.model_name I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) expected = %{
} - assert_equal expected, @builder.date_field(:misc) + assert_equivalent_xml expected, @builder.date_field(:misc) end test "Nil models are supported for form builder" do @@ -25,7 +25,7 @@ def user_klass.model_name I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) expected = %{
} - assert_equal expected, @builder.date_field(:misc) + assert_equivalent_xml expected, @builder.date_field(:misc) end test "Objects without model names are supported for form builder" do @@ -37,7 +37,7 @@ def user_klass.model_name I18n.backend.store_translations(:en, {activerecord: {help: {faux_user: {password: "A good password should be at least six characters long"}}}}) expected = %{
} - assert_equal expected, @builder.date_field(:misc) + assert_equivalent_xml expected, @builder.date_field(:misc) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index af00d9d9e..e38085c2c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,7 @@ require 'timecop' +require 'diffy' +require 'nokogiri' +require 'equivalent-xml' require 'mocha/mini_test' # Configure Rails Environment @@ -16,5 +19,68 @@ def setup_test_fixture @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment') @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {}) @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"}}}}) + I18n.backend.store_translations(:en, { + activerecord: { + attributes: { + user: { + email: "Email" + } + }, + help: { + user: { + password: "A good password should be at least six characters long" + } + } + } + }) +end + +def sort_attributes doc + doc.dup.traverse do |node| + if node.is_a?(Nokogiri::XML::Element) + attributes = node.attribute_nodes.sort_by(&:name) + attributes.each do |attribute| + node.delete(attribute.name) + node[attribute.name] = attribute.value + end + end + node + end +end + +class ActionView::TestCase + def assert_equivalent_xml(expected, actual) + expected_xml = Nokogiri::XML(expected) + actual_xml = Nokogiri::XML(actual) + ignored_attributes = %w(style data-disable-with) + equivalent = EquivalentXml.equivalent?(expected_xml, actual_xml, { + ignore_attr_values: ignored_attributes + }) do |a, b, result| + if result === false && b.is_a?(Nokogiri::XML::Element) + if b.attr('name') == 'utf8' + # Handle wrapped utf8 hidden field for Rails 4.2+ + result = EquivalentXml.equivalent?(a.child, b) + end + if b.delete('data-disable-with') + # Remove data-disable-with for Rails 5+ + # Workaround because ignoring in EquivalentXml doesn't work + result = EquivalentXml.equivalent?(a, b) + end + if a.attr('type') == 'datetime' && b.attr('type') == 'datetime-local' + a.delete('type') + b.delete('type') + # Handle new datetime type for Rails 5+ + result = EquivalentXml.equivalent?(a, b) + end + end + result + end + assert equivalent, lambda { + # using a lambda because diffing is expensive + Diffy::Diff.new( + sort_attributes(expected_xml.root), + sort_attributes(actual_xml.root) + ).to_s(:color) + } + end end