Skip to content

Commit 2a2c065

Browse files
committed
Fixed view specs for Rails 7
1 parent 96a08e0 commit 2a2c065

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ jobs:
2828

2929
# Rails 7.0 builds >= 2.7
3030
- ruby: 3.1
31-
allow_failure: true
3231
env:
3332
RAILS_VERSION: '~> 7.0.0'
3433
- ruby: '3.0'
35-
allow_failure: true
3634
env:
3735
RAILS_VERSION: '~> 7.0.0'
3836
- ruby: 2.7
39-
allow_failure: true
4037
env:
4138
RAILS_VERSION: '~> 7.0.0'
4239

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
1919
it "renders a list of <%= ns_table_name %>" do
2020
render
21+
<% if Rails.version >= "7.0.0" %>
22+
<% for attribute in output_attributes -%>
23+
assert_select %{p:contains(<%= raw_value_for(attribute).to_s.inspect %>)}, count: 2
24+
<% end -%>
25+
<% else -%>
2126
<% for attribute in output_attributes -%>
2227
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
28+
<% end -%>
2329
<% end -%>
2430
end
2531
end

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,28 @@
208208
before { run_generator %w[posts upvotes:integer downvotes:integer] }
209209
subject { file("spec/views/posts/index.html.erb_spec.rb") }
210210
it { is_expected.to exist }
211-
it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') }
212-
it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') }
211+
212+
if Rails.version >= "7.0.0"
213+
it { is_expected.to contain('assert_select %{p:contains("2")}, count: 2') }
214+
it { is_expected.to contain('assert_select %{p:contains("3")}, count: 2') }
215+
else
216+
it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') }
217+
it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') }
218+
end
213219
end
214220

215221
describe 'with multiple float attributes index' do
216222
before { run_generator %w[posts upvotes:float downvotes:float] }
217223
subject { file("spec/views/posts/index.html.erb_spec.rb") }
218224
it { is_expected.to exist }
219-
it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') }
220-
it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') }
225+
226+
if Rails.version >= "7.0.0"
227+
it { is_expected.to contain('assert_select %{p:contains("2.5")}, count: 2') }
228+
it { is_expected.to contain('assert_select %{p:contains("3.5")}, count: 2') }
229+
else
230+
it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') }
231+
it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') }
232+
end
221233
end
222234

223235
describe 'with reference attribute' do

0 commit comments

Comments
 (0)