aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-12-12 11:42:16 -0500
committerGitHub <noreply@github.com>2018-12-12 11:42:16 -0500
commit662f14814eacdc100d0cd511aa05db34119de18a (patch)
tree53d41bd296bd2e51930c9f35520709b77ee90530 /railties/lib/rails
parentb0ac3694e6a760f483fec4895a7b86f400498848 (diff)
parentea89b4588b829934ac9d2e8040ad7e87f398eb4a (diff)
downloadrails-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
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb5
-rw-r--r--railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt8
2 files changed, 13 insertions, 0 deletions
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"