diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-12-12 11:42:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 11:42:16 -0500 |
commit | 662f14814eacdc100d0cd511aa05db34119de18a (patch) | |
tree | 53d41bd296bd2e51930c9f35520709b77ee90530 | |
parent | b0ac3694e6a760f483fec4895a7b86f400498848 (diff) | |
parent | ea89b4588b829934ac9d2e8040ad7e87f398eb4a (diff) | |
download | rails-662f14814eacdc100d0cd511aa05db34119de18a.tar.gz rails-662f14814eacdc100d0cd511aa05db34119de18a.tar.bz2 rails-662f14814eacdc100d0cd511aa05db34119de18a.zip |
Merge pull request #34681 from gmcgibbon/fix_boolean_system_test_scaffold
Fix boolean interaction in scaffold system tests
4 files changed, 22 insertions, 3 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 19fec654c4..d2992dbbdb 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix boolean interaction in scaffold system tests. + + *Gannon McGibbon* + * Remove redundant suffixes on generated system tests. *Gannon McGibbon* diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index e2e8b18eab..662b5e206e 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -54,6 +54,11 @@ module TestUnit # :nodoc: end end.sort.to_h end + + def boolean?(name) + attribute = attributes.find { |attribute| attribute.name == name } + attribute&.type == :boolean + end end end end diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt b/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt index 15bd7956b6..4f5bbf1108 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt @@ -16,8 +16,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase click_on "New <%= class_name.titleize %>" <%- attributes_hash.each do |attr, value| -%> + <%- if boolean?(attr) -%> + check "<%= attr.humanize %>" if <%= value %> + <%- else -%> fill_in "<%= attr.humanize %>", with: <%= value %> <%- end -%> + <%- end -%> click_on "Create <%= human_name %>" assert_text "<%= human_name %> was successfully created" @@ -29,8 +33,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase click_on "Edit", match: :first <%- attributes_hash.each do |attr, value| -%> + <%- if boolean?(attr) -%> + check "<%= attr.humanize %>" if <%= value %> + <%- else -%> fill_in "<%= attr.humanize %>", with: <%= value %> <%- end -%> + <%- end -%> click_on "Update <%= human_name %>" assert_text "<%= human_name %> was successfully updated" diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 3cffdddd38..f672e301a7 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -5,7 +5,7 @@ require "rails/generators/rails/scaffold/scaffold_generator" class ScaffoldGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper - arguments %w(product_line title:string product:belongs_to user:references) + arguments %w(product_line title:string approved:boolean product:belongs_to user:references) setup :copy_routes @@ -17,6 +17,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/models/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/ assert_file "test/fixtures/product_lines.yml" assert_migration "db/migrate/create_product_lines.rb", /belongs_to :product/ + assert_migration "db/migrate/create_product_lines.rb", /boolean :approved/ assert_migration "db/migrate/create_product_lines.rb", /references :user/ # Route @@ -60,8 +61,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/controllers/product_lines_controller_test.rb" do |test| assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, test) - assert_match(/post product_lines_url, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test) - assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test) + assert_match(/post product_lines_url, params: \{ product_line: \{ approved: @product_line\.approved, product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test) + assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ approved: @product_line\.approved, product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test) end # System tests @@ -69,6 +70,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/class ProductLinesTest < ApplicationSystemTestCase/, test) assert_match(/visit product_lines_url/, test) assert_match(/fill_in "Title", with: @product_line\.title/, test) + assert_match(/check "Approved" if @product_line\.approved/, test) assert_match(/assert_text "Product line was successfully updated"/, test) end |