Skip to content
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

Cleanup of Rails 6.1 code #2791

Merged
merged 7 commits into from
Sep 3, 2024
Merged
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
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Bug Fixes:

* Remove mutation of Rails constant in favour of public api. (Petrik de Heus, #2789)
* Cleanup Rails scaffold for unsupported versions. (Matt Jankowski, #2790)
* Remove deprecated scaffold that was unintentionally included in 7.0.0
(Jon Rowe, #2791)

### 7.0.0 / 2024-09-02
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.5...v7.0.0)
Expand Down
6 changes: 1 addition & 5 deletions Gemfile-rails-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ def add_sqlite3_gem_dependency
end
end

if RUBY_VERSION.to_f < 2.7
gem 'puma', '< 6.0.0'
else
gem 'puma'
end
gem 'puma'

case version = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ''
when /main/
Expand Down
2 changes: 1 addition & 1 deletion example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

copy_file capybara_backport_path, 'spec/support/capybara.rb'

if Rails::VERSION::STRING > '7' && Rails::VERSION::STRING < '7.2'
if Rails::VERSION::STRING < '7.2'
create_file 'app/assets/config/manifest.js' do
"//= link application.css"
end
Expand Down
4 changes: 1 addition & 3 deletions example_app_generator/spec/support/default_preview_path
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ require_file_stub 'config/environment' do
module ExampleApp
class Application < Rails::Application
config.eager_load = false
if Rails::VERSION::STRING.to_f >= 7.0
config.active_support.cache_format_version = 7.0
end
config.active_support.cache_format_version = 7.0

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false unless ENV['NO_ACTION_MAILER']
Expand Down
13 changes: 1 addition & 12 deletions example_app_generator/spec/verify_mailer_preview_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def capture_exec(*ops)

if ENV['RAILS_VERSION'] == 'main' && Rails::VERSION::STRING == "8.0.0.alpha"
before do
skip('This is broken on Rails main but is skipped for green builds of 7.1.x, please fix')
skip('This is broken on Rails main but is skipped for green builds, please fix')
end
end

Expand Down Expand Up @@ -139,17 +139,6 @@ def have_no_preview(_opts = {})
)
).to eq('test-host')
end

it 'handles action mailer not being available' do
skip "Rails 7 forces eager loading on CI, loads app/mailers and fails" if Rails::VERSION::STRING.to_f >= 7.0

expect(
capture_exec(
custom_env.merge('NO_ACTION_MAILER' => 'true'),
exec_script
)
).to have_no_preview
end
end
else
context 'in the development environment' do
Expand Down
1 change: 0 additions & 1 deletion features/file_fixture.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Feature: Using `file_fixture`
When I run `rspec spec/lib/file_spec.rb`
Then the examples should all pass

@rails_post_7
Scenario: Creating a ActiveStorage::Blob from a file fixture
Given a file named "spec/fixtures/files/sample.txt" with:
"""
Expand Down
21 changes: 0 additions & 21 deletions features/generator_specs/integration_specs.feature

This file was deleted.

15 changes: 0 additions & 15 deletions features/support/rails_versions.rb

This file was deleted.

29 changes: 0 additions & 29 deletions lib/generators/rspec/integration/integration_generator.rb

This file was deleted.

15 changes: 0 additions & 15 deletions lib/generators/rspec/scaffold/templates/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,10 @@
end
context "with invalid params" do
<% if Rails.version.to_f < 7.0 %>
it "returns a success response (i.e. to display the 'new' template)" do
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
expect(response).to be_successful
end
<% else %>
it "renders a response with 422 status (i.e. to display the 'new' template)" do
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
expect(response).to have_http_status(:unprocessable_entity)
end
<% end %>
end
end
Expand All @@ -125,19 +118,11 @@
end
context "with invalid params" do
<% if Rails.version.to_f < 7.0 %>
it "returns a success response (i.e. to display the 'edit' template)" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
expect(response).to be_successful
end
<% else %>
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
put :update, params: {id: <%= file_name %>.to_param, <%= singular_table_name %>: invalid_attributes}, session: valid_session
expect(response).to have_http_status(:unprocessable_entity)
end
<% end %>
end
end
Expand Down
15 changes: 0 additions & 15 deletions lib/generators/rspec/scaffold/templates/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@
}.to change(<%= class_name %>, :count).by(0)
end
<% if Rails.version.to_f < 7.0 %>
it "renders a successful response (i.e. to display the 'new' template)" do
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
expect(response).to be_successful
end
<% else %>
it "renders a response with 422 status (i.e. to display the 'new' template)" do
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
expect(response).to have_http_status(:unprocessable_entity)
end
<% end %>
end
end
Expand All @@ -119,19 +112,11 @@
end

context "with invalid parameters" do
<% if Rails.version.to_f < 7.0 %>
it "renders a successful response (i.e. to display the 'edit' template)" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
expect(response).to be_successful
end
<% else %>
it "renders a response with 422 status (i.e. to display the 'edit' template)" do
<%= file_name %> = <%= class_name %>.create! valid_attributes
patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
expect(response).to have_http_status(:unprocessable_entity)
end
<% end %>
end
end

Expand Down
14 changes: 5 additions & 9 deletions lib/rspec/rails/example/rails_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
# suite and ammeter.
require 'rspec/rails/matchers'

if ::Rails::VERSION::MAJOR >= 7
require 'active_support/current_attributes/test_helper'
require 'active_support/execution_context/test_helper'
end
require 'active_support/current_attributes/test_helper'
require 'active_support/execution_context/test_helper'

module RSpec
module Rails
Expand All @@ -17,11 +15,9 @@ module RailsExampleGroup
include RSpec::Rails::MinitestLifecycleAdapter
include RSpec::Rails::MinitestAssertionAdapter
include RSpec::Rails::FixtureSupport
if ::Rails::VERSION::MAJOR >= 7
include RSpec::Rails::TaggedLoggingAdapter
include ActiveSupport::CurrentAttributes::TestHelper
include ActiveSupport::ExecutionContext::TestHelper
end
include RSpec::Rails::TaggedLoggingAdapter
include ActiveSupport::CurrentAttributes::TestHelper
include ActiveSupport::ExecutionContext::TestHelper
end
end
end
14 changes: 1 addition & 13 deletions script/update_rubygems_and_install_bundler
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,10 @@ function is_ruby_3_plus {
fi
}

function is_ruby_26_plus {
if ruby -e "exit(RUBY_VERSION.to_f >= 2.6)"; then
return 0
else
return 1
fi
}

if is_ruby_3_plus; then
gem update --no-document --system
gem install --no-document bundler
elif is_ruby_26_plus; then
else
gem update --no-document --system '3.4.22'
gem install --no-document bundler
else
echo "Warning installing older versions of Rubygems / Bundler"
gem update --system '3.3.26'
gem install bundler -v '2.3.26'
fi
14 changes: 0 additions & 14 deletions spec/generators/rspec/integration/integration_generator_spec.rb

This file was deleted.

30 changes: 8 additions & 22 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@
.and(contain(/"redirects to the \w+ list"/))
)

if ::Rails::VERSION::STRING >= '7.0.0'
expect(
filename
).to(
contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/)
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))
)
else
expect(
filename
).to(
contain(/renders a successful response \(i.e. to display the 'new' template\)/)
.and(contain(/renders a successful response \(i.e. to display the 'edit' template\)/))
)
end
expect(
filename
).to(
contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/)
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))
)
end
end

Expand Down Expand Up @@ -105,13 +96,8 @@
.and(contain(/"redirects to the \w+ list"/))
)

if ::Rails::VERSION::STRING >= '7.0.0'
expect(filename).to contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/)
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))
else
expect(filename).to contain(/returns a success response \(i.e. to display the 'new' template\)/)
.and(contain(/returns a success response \(i.e. to display the 'edit' template\)/))
end
expect(filename).to contain(/renders a response with 422 status \(i.e. to display the 'new' template\)/)
.and(contain(/renders a response with 422 status \(i.e. to display the 'edit' template\)/))

expect(filename).not_to contain(/"renders a JSON response with the new \w+"/)
expect(filename).not_to contain(/"renders a JSON response with errors for the new \w+"/)
Expand Down
6 changes: 3 additions & 3 deletions spec/rspec/rails/example/rails_example_group_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module RSpec::Rails
RSpec.describe RailsExampleGroup do
it 'supports tagged_logger', if: ::Rails::VERSION::MAJOR >= 7 do
it 'supports tagged_logger' do
expect(described_class.private_instance_methods).to include(:tagged_logger)
end

it 'does not leak context between example groups', if: ::Rails::VERSION::MAJOR >= 7 do
it 'does not leak context between example groups' do
groups =
[
RSpec::Core::ExampleGroup.describe("A group") do
Expand All @@ -31,7 +31,7 @@ module RSpec::Rails
expect(results).to all be true
end

it 'will not leak ActiveSupport::CurrentAttributes between examples', if: ::Rails::VERSION::MAJOR >= 7 do
it 'will not leak ActiveSupport::CurrentAttributes between examples' do
group =
RSpec::Core::ExampleGroup.describe("A group", order: :defined) do
include RSpec::Rails::RailsExampleGroup
Expand Down