Skip to content

Commit

Permalink
Extract cell_selector method in scaffold index view spec generator (#…
Browse files Browse the repository at this point in the history
…2777)

Move conditional `cell_selector` out of generated view spec
  • Loading branch information
mjankowski authored Aug 10, 2024
1 parent dc0abdb commit 4aad064
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Enhancements:
* Verify ActiveJob arguments by comparing to the method signature. (Oli Peate, #2745)
* Add suggestion to rails_helper.rb to skip when not in test most. (Glauco Custódio, #2751)
* Add `at_priority` qualifier to `have_enqueued_job` set of matchers. (mbajur, #2759)
* Remove Rails version-specific conditional from index scaffold generation. (Matt Jankowski, #2777)

Bug Fixes:

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it "renders a list of <%= ns_table_name %>" do
render
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
cell_selector = <%= Rails::VERSION::STRING >= '7' ? "'div>p'" : "'tr>td'" %>
<% for attribute in output_attributes -%>
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
<% end -%>
Expand Down
6 changes: 6 additions & 0 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@
.and(contain(/^RSpec.describe "(.*)\/index", #{type_metatag(:view)}/))
.and(contain(/assign\(:posts, /))
.and(contain(/it "renders a list of (.*)"/))

if ::Rails::VERSION::STRING >= '7.0.0'
expect(filename).to contain(/'div>p'/)
else
expect(filename).to contain(/'tr>td'/)
end
end
end

Expand Down

0 comments on commit 4aad064

Please sign in to comment.