1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Generate the same value as a label of view in system test template

In the system test template, enter a value based on label.
However, since `label` method does not use `titleize` by default.
If generate a value including underscore, cannot find a label and the test
will fail.

```
$ ./bin/rails g scaffold user name:string phone_number:string
$ ./bin/rails t test/system/users_test.rb

E

Error:
UsersTest#test_creating_a_User:
Capybara::ElementNotFound: Unable to find field "Phone Number"
    test/system/users_test.rb:18:in `block in <class:UsersTest>'
```

This removes unnecessary `titleize` so that the generated file will pass
even if the attribute contains an underscore.
This commit is contained in:
yuuji.yaginuma 2018-08-29 09:58:21 +09:00
parent a8fff60814
commit 28e5085070
2 changed files with 3 additions and 3 deletions

View file

@ -16,7 +16,7 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
click_on "New <%= class_name.titleize %>" click_on "New <%= class_name.titleize %>"
<%- attributes_hash.each do |attr, value| -%> <%- attributes_hash.each do |attr, value| -%>
fill_in "<%= attr.humanize.titleize %>", with: <%= value %> fill_in "<%= attr.humanize %>", with: <%= value %>
<%- end -%> <%- end -%>
click_on "Create <%= human_name %>" click_on "Create <%= human_name %>"
@ -29,7 +29,7 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
click_on "Edit", match: :first click_on "Edit", match: :first
<%- attributes_hash.each do |attr, value| -%> <%- attributes_hash.each do |attr, value| -%>
fill_in "<%= attr.humanize.titleize %>", with: <%= value %> fill_in "<%= attr.humanize %>", with: <%= value %>
<%- end -%> <%- end -%>
click_on "Update <%= human_name %>" click_on "Update <%= human_name %>"

View file

@ -514,7 +514,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "test/system/users_test.rb" do |content| assert_file "test/system/users_test.rb" do |content|
assert_match(/fill_in "Password", with: 'secret'/, content) assert_match(/fill_in "Password", with: 'secret'/, content)
assert_match(/fill_in "Password Confirmation", with: 'secret'/, content) assert_match(/fill_in "Password confirmation", with: 'secret'/, content)
end end
assert_file "test/fixtures/users.yml" do |content| assert_file "test/fixtures/users.yml" do |content|