Skip to content

Commit

Permalink
RuboCop Rails supports Rails 4 or higher
Browse files Browse the repository at this point in the history
This PR drops Rails 3 support.

RuboCop core was supported Rails 4+.
https://github.com/rubocop-hq/rubocop/tree/v0.71.0#compatibility

> The Rails cops support the following versions:
>
> - Rails 4.0+

It conforms to the expected behavior of RuboCop core originally.

And Rails is maintained at 4.2.Z or higher.

> 4 Severe Security Issues
> For severe security issues all releases in the current major series, and
> also the last major release series will receive patches and new
> versions. The classification of the security issue is judged by the core
> team.
>
> Currently included series: 5.2.Z, 5.1.Z, 5.0.Z, 4.2.Z.

https://guides.rubyonrails.org/maintenance_policy.html

The following is the RuboCop Rails and Rails 4 use case.
rubocop#68
  • Loading branch information
koic committed Jun 15, 2019
1 parent 65429d9 commit 74eba93
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 161 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* [#43](https://github.com/rubocop-hq/rubocop-rails/issues/43): Remove `change_column_null` method from `BulkChangeTable` cop offenses. ([@anthony-robin][])

### Changes

* [#74](https://github.com/rubocop-hq/rubocop-rails/pull/74): Drop Rails 3 support. ([@koic][])

## 2.0.1 (2019-06-08)

### Changes
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ Rails/FindBy:
- lib/example.rb
```

## Compatibility

Rails cops support the following versions:

- Rails 4.0+

## Contributing

Checkout the [contribution guidelines](CONTRIBUTING.md).
Expand Down
3 changes: 0 additions & 3 deletions lib/rubocop/cop/rails/action_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module Rails
# append_around_filter :do_stuff
# skip_after_filter :do_stuff
class ActionFilter < Cop
extend TargetRailsVersion
include ConfigurableEnforcedStyle

MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
Expand Down Expand Up @@ -70,8 +69,6 @@ class ActionFilter < Cop
skip_action_callback
].freeze

minimum_target_rails_version 4.0

def on_block(node)
check_method_node(node.send_node)
end
Expand Down
7 changes: 1 addition & 6 deletions lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,7 @@ def check_remove_foreign_key_node(node)

def check_change_table_node(node, block)
change_table_call(node) do |arg|
if target_rails_version < 4.0
add_offense(
node,
message: format(MSG, action: 'change_table')
)
elsif block.send_type?
if block.send_type?
check_change_table_offense(arg, block)
else
block.each_child_node(:send) do |child_node|
Expand Down
138 changes: 42 additions & 96 deletions spec/rubocop/cop/rails/action_filter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Rails::ActionFilter, :config do
subject(:cop) { described_class.new(config) }

let(:cop_config) { { 'Include' => nil } }

describe '::FILTER_METHODS' do
it 'contains all of the filter methods' do
expect(described_class::FILTER_METHODS).to eq(%i[
Expand Down Expand Up @@ -41,121 +45,63 @@
end
end

context 'Rails <= 4.0', :rails3 do
subject(:cop) { described_class.new(config) }

let(:cop_config) { { 'Include' => nil } }

context 'when using action methods' do
described_class::FILTER_METHODS.each do |method|
it "does not register an offense for #{method}" do
expect_no_offenses("#{method} :name")
end

it "does not register an offense for #{method} with block" do
expect_no_offenses("#{method} { |controller| something }")
end
end
context 'when style is action' do
before do
cop_config['EnforcedStyle'] = 'action'
end

described_class::ACTION_METHODS.each do |method|
it "accepts #{method}" do
expect_no_offenses("#{method} :something")
end
described_class::FILTER_METHODS.each do |method|
it "registers an offense for #{method}" do
inspect_source_file("#{method} :name")
expect(cop.offenses.size).to eq(1)
end

it 'does not auto-correct to preferred method' do
new_source = autocorrect_source_file('before_filter :test')
expect(new_source).to eq('before_filter :test')
it "registers an offense for #{method} with block" do
inspect_source_file("#{method} { |controller| something }")
expect(cop.offenses.size).to eq(1)
end
end

context 'when using filter methods' do
described_class::ACTION_METHODS.each do |method|
it "does not register an offense for #{method}" do
expect_no_offenses("#{method} :name")
end

it "does not register an offense for #{method} with block" do
expect_no_offenses("#{method} { |controller| something }")
end
end

described_class::FILTER_METHODS.each do |method|
it "accepts #{method}" do
expect_no_offenses("#{method} :something")
end
described_class::ACTION_METHODS.each do |method|
it "accepts #{method}" do
inspect_source_file("#{method} :something")
expect(cop.offenses.empty?).to be(true)
end
end

it 'does not auto-correct to preferred method' do
new_source = autocorrect_source_file('before_action :test')
expect(new_source).to eq('before_action :test')
end
it 'auto-corrects to preferred method' do
new_source = autocorrect_source_file('before_filter :test')
expect(new_source).to eq('before_action :test')
end
end

context 'Rails >= 4.0', :rails4 do
subject(:cop) { described_class.new(config) }

let(:cop_config) { { 'Include' => nil } }

context 'when style is action' do
before do
cop_config['EnforcedStyle'] = 'action'
end

described_class::FILTER_METHODS.each do |method|
it "registers an offense for #{method}" do
inspect_source_file("#{method} :name")
expect(cop.offenses.size).to eq(1)
end

it "registers an offense for #{method} with block" do
inspect_source_file("#{method} { |controller| something }")
expect(cop.offenses.size).to eq(1)
end
end

described_class::ACTION_METHODS.each do |method|
it "accepts #{method}" do
inspect_source_file("#{method} :something")
expect(cop.offenses.empty?).to be(true)
end
end

it 'auto-corrects to preferred method' do
new_source = autocorrect_source_file('before_filter :test')
expect(new_source).to eq('before_action :test')
end
context 'when style is filter' do
before do
cop_config['EnforcedStyle'] = 'filter'
end

context 'when style is filter' do
before do
cop_config['EnforcedStyle'] = 'filter'
described_class::ACTION_METHODS.each do |method|
it "registers an offense for #{method}" do
inspect_source_file("#{method} :name")
expect(cop.offenses.size).to eq(1)
end

described_class::ACTION_METHODS.each do |method|
it "registers an offense for #{method}" do
inspect_source_file("#{method} :name")
expect(cop.offenses.size).to eq(1)
end

it "registers an offense for #{method} with block" do
inspect_source_file("#{method} { |controller| something }")
expect(cop.offenses.size).to eq(1)
end
it "registers an offense for #{method} with block" do
inspect_source_file("#{method} { |controller| something }")
expect(cop.offenses.size).to eq(1)
end
end

described_class::FILTER_METHODS.each do |method|
it "accepts #{method}" do
inspect_source_file("#{method} :something")
expect(cop.offenses.empty?).to be(true)
end
described_class::FILTER_METHODS.each do |method|
it "accepts #{method}" do
inspect_source_file("#{method} :something")
expect(cop.offenses.empty?).to be(true)
end
end

it 'auto-corrects to preferred method' do
new_source = autocorrect_source_file('before_action :test')
expect(new_source).to eq('before_filter :test')
end
it 'auto-corrects to preferred method' do
new_source = autocorrect_source_file('before_action :test')
expect(new_source).to eq('before_filter :test')
end
end
end
74 changes: 22 additions & 52 deletions spec/rubocop/cop/rails/reversible_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,60 +151,30 @@ def change
end

context 'change_table' do
context 'Rails < 4.0', :rails3 do
it_behaves_like 'offense', 'change_table', <<-RUBY
change_table :users do |t|
t.column :name, :string
t.text :description
t.boolean :authorized
end
RUBY

it_behaves_like 'offense', 'change_table', <<-RUBY
change_table :users do |t|
t.change :description, :text
end
RUBY

it_behaves_like 'offense', 'change_table', <<-RUBY
change_table :users do |t|
t.change_default :authorized, 1
end
RUBY

it_behaves_like 'offense', 'change_table', <<-RUBY
change_table :users do |t|
t.remove :qualification
end
RUBY
end

context 'Rails >= 4.0', :rails4 do
it_behaves_like 'accepts', 'change_table(with reversible calls)', <<-RUBY
change_table :users do |t|
t.column :name, :string
t.text :description
t.boolean :authorized
end
RUBY
it_behaves_like 'accepts', 'change_table(with reversible calls)', <<-RUBY
change_table :users do |t|
t.column :name, :string
t.text :description
t.boolean :authorized
end
RUBY

it_behaves_like 'offense', 'change_table(with change)', <<-RUBY
change_table :users do |t|
t.change :description, :text
end
RUBY
it_behaves_like 'offense', 'change_table(with change)', <<-RUBY
change_table :users do |t|
t.change :description, :text
end
RUBY

it_behaves_like 'offense', 'change_table(with change_default)', <<-RUBY
change_table :users do |t|
t.change_default :authorized, 1
end
RUBY
it_behaves_like 'offense', 'change_table(with change_default)', <<-RUBY
change_table :users do |t|
t.change_default :authorized, 1
end
RUBY

it_behaves_like 'offense', 'change_table(with remove)', <<-RUBY
change_table :users do |t|
t.remove :qualification
end
RUBY
end
it_behaves_like 'offense', 'change_table(with remove)', <<-RUBY
change_table :users do |t|
t.remove :qualification
end
RUBY
end
end
4 changes: 0 additions & 4 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

RSpec.shared_context 'with Rails 3', :rails3 do
let(:rails_version) { 3.0 }
end

RSpec.shared_context 'with Rails 4', :rails4 do
let(:rails_version) { 4.0 }
end
Expand Down

0 comments on commit 74eba93

Please sign in to comment.