From ea89b4588b829934ac9d2e8040ad7e87f398eb4a Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 11 Dec 2018 17:11:45 -0500 Subject: Fix boolean interaction in scaffold system tests --- .../lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 5 +++++ .../generators/test_unit/scaffold/templates/system_test.rb.tt | 8 ++++++++ 2 files changed, 13 insertions(+) (limited to 'railties/lib/rails/generators/test_unit/scaffold') 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" -- cgit v1.2.3