From 5036997408dc73dfedf561cb326c187a0f0e2fb7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 8 Aug 2024 14:05:15 -0400 Subject: [PATCH 1/2] Move conditional `cell_selector` out of generated view spec --- lib/generators/rspec/scaffold/templates/index_spec.rb | 2 +- spec/generators/rspec/scaffold/scaffold_generator_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/generators/rspec/scaffold/templates/index_spec.rb b/lib/generators/rspec/scaffold/templates/index_spec.rb index 4abbc0da0..627b475cf 100644 --- a/lib/generators/rspec/scaffold/templates/index_spec.rb +++ b/lib/generators/rspec/scaffold/templates/index_spec.rb @@ -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 -%> diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index edbc23934..4e02682e3 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -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 From f785f7ad327f5024670657bc248546d80aea0530 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 11 Aug 2024 00:08:06 +0300 Subject: [PATCH 2/2] Add changelog entry for #2777 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 2da298ebb..53bd6961c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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: