Skip to content

Commit 9cb6f44

Browse files
authored
Merge pull request rails#49409 from stevepolitodesign/sp-datetime-local-scaffold
Ensure system test scaffold supports `datetime` and `time` attributes
2 parents 6c9967f + d0d1a1b commit 9cb6f44

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def virtual?(name)
6363
attribute = attributes.find { |attr| attr.name == name }
6464
attribute&.virtual?
6565
end
66+
67+
def datetime?(name)
68+
attribute = attributes.find { |attr| attr.name == name }
69+
attribute&.type == :datetime
70+
end
71+
72+
def time?(name)
73+
attribute = attributes.find { |attr| attr.name == name }
74+
attribute&.type == :time
75+
end
6676
end
6777
end
6878
end

railties/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
3535
<%- attributes_hash.each do |attr, value| -%>
3636
<%- if boolean?(attr) -%>
3737
check "<%= attr.humanize %>" if <%= value %>
38+
<%- elsif datetime?(attr) || time?(attr) -%>
39+
fill_in "<%= attr.humanize %>", with: <%= value %>.to_s
3840
<%- else -%>
3941
fill_in "<%= attr.humanize %>", with: <%= value %>
4042
<%- end -%>

0 commit comments

Comments
 (0)