diff --git a/CHANGELOG.md b/CHANGELOG.md index a370e31219..c9b72b65ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 34221ec5fb..81f70c2df1 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/lib/rubocop/cop/rails/action_filter.rb b/lib/rubocop/cop/rails/action_filter.rb index a667c8cb4f..0a03f47ab2 100644 --- a/lib/rubocop/cop/rails/action_filter.rb +++ b/lib/rubocop/cop/rails/action_filter.rb @@ -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 `%s` over `%s`.' @@ -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 diff --git a/lib/rubocop/cop/rails/reversible_migration.rb b/lib/rubocop/cop/rails/reversible_migration.rb index b0611835d2..3484c6b59d 100644 --- a/lib/rubocop/cop/rails/reversible_migration.rb +++ b/lib/rubocop/cop/rails/reversible_migration.rb @@ -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| diff --git a/spec/rubocop/cop/rails/action_filter_spec.rb b/spec/rubocop/cop/rails/action_filter_spec.rb index 95f6780af1..ae9017204c 100644 --- a/spec/rubocop/cop/rails/action_filter_spec.rb +++ b/spec/rubocop/cop/rails/action_filter_spec.rb @@ -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[ @@ -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 diff --git a/spec/rubocop/cop/rails/reversible_migration_spec.rb b/spec/rubocop/cop/rails/reversible_migration_spec.rb index d9187489ab..45dfb9dcde 100644 --- a/spec/rubocop/cop/rails/reversible_migration_spec.rb +++ b/spec/rubocop/cop/rails/reversible_migration_spec.rb @@ -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 diff --git a/spec/support/shared_contexts.rb b/spec/support/shared_contexts.rb index 01ff275204..963b588a1d 100644 --- a/spec/support/shared_contexts.rb +++ b/spec/support/shared_contexts.rb @@ -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