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

Drop support for Rails 4.1 or lower #236

Merged
merged 1 commit into from
Apr 24, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changes

* [#233](https://github.com/rubocop-hq/rubocop-rails/pull/233): **(BREAKING)** Drop support for Ruby 2.3. ([@koic][])
* [#236](https://github.com/rubocop-hq/rubocop-rails/pull/236): **(BREAKING)** Drop support for Rails 4.1 or lower. ([@koic][])

## 2.5.2 (2020-04-09)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ You can read a lot more about RuboCop Rails in its [official docs](https://docs.

Rails cops support the following versions:

- Rails 4.0+
- Rails 4.2+

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/http_positional_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Rails
# change them to use keyword args. This cop only applies to Rails >= 5.
# If you are running Rails < 5 you should disable the
# Rails/HttpPositionalArguments cop or set your TargetRailsVersion in your
# .rubocop.yml file to 4.0, etc.
# .rubocop.yml file to 4.2.
#
# @example
# # bad
Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/rails/inverse_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ module Rails
# @see https://guides.rubyonrails.org/association_basics.html#bi-directional-associations
# @see https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
class InverseOf < Cop
extend TargetRailsVersion

minimum_target_rails_version 4.1

SPECIFY_MSG = 'Specify an `:inverse_of` option.'
NIL_MSG = 'You specified `inverse_of: nil`, you probably meant to ' \
'use `inverse_of: false`.'
Expand Down
3 changes: 0 additions & 3 deletions lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ module Rails
# end
# end
class RedundantReceiverInWithOptions < Cop
extend TargetRailsVersion
include RangeHelp

minimum_target_rails_version 4.2

MSG = 'Redundant receiver in `with_options`.'

def_node_matcher :with_options?, <<~PATTERN
Expand Down
2 changes: 1 addition & 1 deletion manual/cops_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ This cop is used to identify usages of http methods like `get`, `post`,
change them to use keyword args. This cop only applies to Rails >= 5.
If you are running Rails < 5 you should disable the
Rails/HttpPositionalArguments cop or set your TargetRailsVersion in your
.rubocop.yml file to 4.0, etc.
.rubocop.yml file to 4.2.

### Examples

Expand Down
2 changes: 1 addition & 1 deletion rubocop-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |s|
'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-rails/issues'
}

s.add_runtime_dependency 'activesupport'
s.add_runtime_dependency 'activesupport', '>= 4.2.0'
# Rack::Utils::SYMBOL_TO_STATUS_CODE, which is used by HttpStatus cop, was
# introduced in rack 1.1
s.add_runtime_dependency 'rack', '>= 1.1'
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end

context 'correctly' do
let(:rails_version) { 4.0 }
let(:rails_version) { 6.0 }

it 'uses TargetRailsVersion' do
expect(configuration.target_rails_version).to eq rails_version
Expand Down
166 changes: 74 additions & 92 deletions spec/rubocop/cop/rails/redundant_receiver_in_with_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,92 @@
RSpec.describe RuboCop::Cop::Rails::RedundantReceiverInWithOptions, :config do
subject(:cop) { described_class.new(config) }

context 'Rails >= 4.2', :rails42 do
it 'registers an offense and corrects using explicit receiver ' \
it 'registers an offense and corrects using explicit receiver ' \
'in `with_options`' do
expect_offense(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do |assoc|
assoc.has_many :customers
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :products
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :invoices
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :expenses
^^^^^ Redundant receiver in `with_options`.
end
expect_offense(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do |assoc|
assoc.has_many :customers
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :products
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :invoices
^^^^^ Redundant receiver in `with_options`.
assoc.has_many :expenses
^^^^^ Redundant receiver in `with_options`.
end
RUBY
end
RUBY

expect_correction(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do
has_many :customers
has_many :products
has_many :invoices
has_many :expenses
end
expect_correction(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do
has_many :customers
has_many :products
has_many :invoices
has_many :expenses
end
RUBY
end

it 'does not register an offense when using inplicit receiver ' \
'in `with_options`' do
expect_no_offenses(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do
has_many :customers
has_many :products
has_many :invoices
has_many :expenses
end
end
RUBY
end
end
RUBY
end

it 'registers an offense and corrects when including multiple ' \
'redendant receivers in single line' do
expect_offense(<<~RUBY)
with_options options: false do |merger|
merger.invoke(merger.something)
^^^^^^ Redundant receiver in `with_options`.
^^^^^^ Redundant receiver in `with_options`.
it 'does not register an offense when using inplicit receiver ' \
'in `with_options`' do
expect_no_offenses(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do
has_many :customers
has_many :products
has_many :invoices
has_many :expenses
end
RUBY
end
RUBY
end

expect_correction(<<~RUBY)
with_options options: false do
invoke(something)
end
RUBY
end
it 'registers an offense and corrects when including multiple ' \
'redendant receivers in single line' do
expect_offense(<<~RUBY)
with_options options: false do |merger|
merger.invoke(merger.something)
^^^^^^ Redundant receiver in `with_options`.
^^^^^^ Redundant receiver in `with_options`.
end
RUBY

it 'does not register an offense when including method invocations ' \
'to different receivers' do
expect_no_offenses(<<~RUBY)
client = ApplicationClient.new
with_options options: false do |merger|
client.invoke(merger.something, something)
end
RUBY
end
expect_correction(<<~RUBY)
with_options options: false do
invoke(something)
end
RUBY
end

it 'does not register an offense when including block node' \
'in `with_options`' do
expect_no_offenses(<<~RUBY)
with_options options: false do |merger|
merger.invoke
with_another_method do |another_receiver|
merger.invoke(another_receiver)
end
end
RUBY
end
it 'does not register an offense when including method invocations ' \
'to different receivers' do
expect_no_offenses(<<~RUBY)
client = ApplicationClient.new
with_options options: false do |merger|
client.invoke(merger.something, something)
end
RUBY
end

it 'does not register an offense when empty' do
expect_no_offenses(<<~RUBY)
with_options options: false do |merger|
it 'does not register an offense when including block node' \
'in `with_options`' do
expect_no_offenses(<<~RUBY)
with_options options: false do |merger|
merger.invoke
with_another_method do |another_receiver|
merger.invoke(another_receiver)
end
RUBY
end
end
RUBY
end

context 'Rails <= 4.1', :rails41 do
it 'does not register an offense when using explicit receiver in ' \
'`with_options`' do
expect_no_offenses(<<~RUBY)
class Account < ApplicationRecord
with_options dependent: :destroy do |assoc|
assoc.has_many :customers
assoc.has_many :products
assoc.has_many :invoices
assoc.has_many :expenses
end
end
RUBY
end
it 'does not register an offense when empty' do
expect_no_offenses(<<~RUBY)
with_options options: false do |merger|
end
RUBY
end
end
8 changes: 0 additions & 8 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# frozen_string_literal: true

RSpec.shared_context 'with Rails 4.0', :rails40 do
let(:rails_version) { 4.0 }
end

RSpec.shared_context 'with Rails 4.1', :rails41 do
let(:rails_version) { 4.1 }
end

RSpec.shared_context 'with Rails 4.2', :rails42 do
let(:rails_version) { 4.2 }
end
Expand Down