Skip to content

use the tag itself instead of the variable #2619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/generators/rspec/scaffold/templates/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

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.to_f >= 7.0 ? 'div>p' : 'tr>td' -%>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we need the parent Rails version

Suggested change
<% cell_selector = Rails::VERSION::STRING.to_f >= 7.0 ? 'div>p' : 'tr>td' -%>
<% cell_selector = ::Rails::VERSION::STRING.to_f >= 7.0 ? 'div>p' : 'tr>td' -%>

<% for attribute in output_attributes -%>
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
assert_select <%= cell_selector %>.to_s, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
<% end -%>
end
end
14 changes: 10 additions & 4 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,22 @@
before { run_generator %w[posts upvotes:integer downvotes:integer] }
subject { file("spec/views/posts/index.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.to_s), count: 2') }
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.to_s), count: 2') }
context "rails 7 or greater" do
before { allow(Rails::VERSION::STRING).to receive(:to_f).and_return(7.0) }
it { is_expected.to contain('assert_select div>p.to_s, text: Regexp.new(2.to_s), count: 2') }
it { is_expected.to contain('assert_select div>p.to_s, text: Regexp.new(3.to_s), count: 2') }
end
end

describe 'with multiple float attributes index' do
before { run_generator %w[posts upvotes:float downvotes:float] }
subject { file("spec/views/posts/index.html.erb_spec.rb") }
it { is_expected.to exist }
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.5.to_s), count: 2') }
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.5.to_s), count: 2') }
context "rails 7 or greater" do
before { allow(Rails::VERSION::STRING).to receive(:to_f).and_return(7.0) }
it { is_expected.to contain('assert_select div>p.to_s, text: Regexp.new(2.5.to_s), count: 2') }
it { is_expected.to contain('assert_select div>p.to_s, text: Regexp.new(3.5.to_s), count: 2') }
end
end

describe 'with reference attribute' do
Expand Down