From bf3d379e8f4704b6e12036cefc1bd61be1592570 Mon Sep 17 00:00:00 2001 From: Tony Arra Date: Tue, 28 Dec 2021 09:08:32 -0500 Subject: [PATCH] [Fix #604] Remove `remove_reference` checks from `Rails/ReversibleMigration` This reverts commit 798b39e5395331f88db9d790cf825e1224cca836. Remove `belongs_to` and `remove_reference` checks from `Rails/ReversibleMigration`. --- CHANGELOG.md | 1 + ...nge_remove_remove_reference_checks_from.md | 1 + lib/rubocop/cop/rails/reversible_migration.rb | 2 +- .../cop/rails/reversible_migration_spec.rb | 28 ------------------- 4 files changed, 3 insertions(+), 29 deletions(-) create mode 100644 changelog/change_remove_remove_reference_checks_from.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9c65628e..aa3c202c9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -503,3 +503,4 @@ [@vitormd]: https://github.com/vitormd [@mattmccormick]: https://github.com/mattmccormick [@leoarnold]: https://github.com/leoarnold +[@TonyArra]: https://github.com/TonyArra diff --git a/changelog/change_remove_remove_reference_checks_from.md b/changelog/change_remove_remove_reference_checks_from.md new file mode 100644 index 0000000000..4a2eaaff61 --- /dev/null +++ b/changelog/change_remove_remove_reference_checks_from.md @@ -0,0 +1 @@ +* [#604](https://github.com/rubocop/rubocop-rails/issues/604): Remove `remove_reference` and `remove_belongs_to` methods from `Rails/ReversibleMigration` cop offenses. ([@TonyArra][]) diff --git a/lib/rubocop/cop/rails/reversible_migration.rb b/lib/rubocop/cop/rails/reversible_migration.rb index 1b44954ff4..a0827162ce 100644 --- a/lib/rubocop/cop/rails/reversible_migration.rb +++ b/lib/rubocop/cop/rails/reversible_migration.rb @@ -179,7 +179,7 @@ class ReversibleMigration < Base MSG = '%s is not reversible.' def_node_matcher :irreversible_schema_statement_call, <<~PATTERN - (send nil? ${:change_column :execute :remove_belongs_to :remove_reference} ...) + (send nil? ${:change_column :execute} ...) PATTERN def_node_matcher :drop_table_call, <<~PATTERN diff --git a/spec/rubocop/cop/rails/reversible_migration_spec.rb b/spec/rubocop/cop/rails/reversible_migration_spec.rb index 2554bafb67..9fda4d4914 100644 --- a/spec/rubocop/cop/rails/reversible_migration_spec.rb +++ b/spec/rubocop/cop/rails/reversible_migration_spec.rb @@ -171,20 +171,6 @@ def change RUBY end - context 'remove_belongs_to' do - it_behaves_like 'accepts', 'up_only', <<~RUBY - up_only { remove_belongs_to(:products, :user, index: false) } - RUBY - - it_behaves_like 'offense', 'remove_belongs_to', <<~RUBY - remove_belongs_to(:products, :user, index: false) - RUBY - - it_behaves_like 'offense', 'remove_belongs_to', <<~RUBY - remove_belongs_to(:products, :supplier, polymorphic: true) - RUBY - end - context 'remove_column' do it_behaves_like 'accepts', 'remove_column(with type)', <<~RUBY remove_column(:suppliers, :qualification, :string) @@ -213,20 +199,6 @@ def change RUBY end - context 'remove_reference' do - it_behaves_like 'accepts', 'up_only', <<~RUBY - up_only { remove_reference(:products, :user, index: false) } - RUBY - - it_behaves_like 'offense', 'remove_reference', <<~RUBY - remove_reference(:products, :user, index: false) - RUBY - - it_behaves_like 'offense', 'remove_reference', <<~RUBY - remove_reference(:products, :supplier, polymorphic: true) - RUBY - end - context 'change_table' do it_behaves_like 'accepts', 'change_table(with reversible calls)', <<~RUBY change_table :users do |t|