Skip to content

Commit 64699a4

Browse files
yui-knksebjacobs
authored andcommitted
Omit an id attribute from "scaffold/templates"
From Rails 5.1, a form view which is generated by scaffold command uses `form_with`. `form_with` does not append id attribute for form tags or input tags. So our templates should not use id selectors. rails/rails@d3b798b
1 parent edfb301 commit 64699a4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/generators/rspec/scaffold/templates/edit_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
1717
<% for attribute in output_attributes -%>
1818
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
19+
<% if Rails.version.to_f >= 5.1 -%>
20+
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
21+
<% else -%>
1922
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
23+
<% end -%>
2024
<% end -%>
2125
end
2226
end

lib/generators/rspec/scaffold/templates/new_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
1616
<% for attribute in output_attributes -%>
1717
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
18+
<% if Rails.version.to_f >= 5.1 -%>
19+
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
20+
<% else -%>
1821
assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= name %>[name=?]", "<%= ns_file_name %>[<%= name %>]"
22+
<% end -%>
1923
<% end -%>
2024
end
2125
end

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,23 @@
111111
it { is_expected.to contain('assert_select "tr>td", :text => 3.5.to_s, :count => 2') }
112112
end
113113

114-
if Rails.version.to_f >= 4.0
114+
case
115+
when Rails.version.to_f >= 5.1
116+
describe 'with reference attribute' do
117+
before { run_generator %w(posts title:string author:references) }
118+
describe 'edit' do
119+
subject { file("spec/views/posts/edit.html.erb_spec.rb") }
120+
it { is_expected.to contain(/assert_select "input\[name=\?\]", "post\[author_id\]/) }
121+
it { is_expected.to contain(/assert_select "input\[name=\?\]", "post\[title\]/) }
122+
end
123+
124+
describe 'new' do
125+
subject { file("spec/views/posts/new.html.erb_spec.rb") }
126+
it { is_expected.to contain(/assert_select "input\[name=\?\]", "post\[author_id\]"/) }
127+
it { is_expected.to contain(/assert_select "input\[name=\?\]", "post\[title\]/) }
128+
end
129+
end
130+
when Rails.version.to_f >= 4.0
115131
describe 'with reference attribute' do
116132
before { run_generator %w(posts title:string author:references) }
117133
describe 'edit' do

0 commit comments

Comments
 (0)