diff options
Diffstat (limited to 'spec/rubocop/cop/migration/drop_table_spec.rb')
-rw-r--r-- | spec/rubocop/cop/migration/drop_table_spec.rb | 74 |
1 files changed, 62 insertions, 12 deletions
diff --git a/spec/rubocop/cop/migration/drop_table_spec.rb b/spec/rubocop/cop/migration/drop_table_spec.rb index 4fe7fc8c5a5..44a1106ba62 100644 --- a/spec/rubocop/cop/migration/drop_table_spec.rb +++ b/spec/rubocop/cop/migration/drop_table_spec.rb @@ -7,7 +7,7 @@ require 'rubocop/rspec/support' require_relative '../../../../rubocop/cop/migration/drop_table' -describe RuboCop::Cop::Migration::DropTable do +RSpec.describe RuboCop::Cop::Migration::DropTable do include CopHelper subject(:cop) { described_class.new } @@ -17,20 +17,70 @@ describe RuboCop::Cop::Migration::DropTable do allow(cop).to receive(:in_deployment_migration?).and_return(true) end - it 'registers an offense' do - expect_offense(<<~PATTERN) - def change - drop_table :table - ^^^^^^^^^^ #{described_class::MSG} - - add_column(:users, :username, :text) + context 'with drop_table DSL method' do + context 'when in down method' do + it 'does not register an offense' do + expect_no_offenses(<<~PATTERN) + def down + drop_table :table + end + PATTERN + end + end - execute "DROP TABLE table" - ^^^^^^^ #{described_class::MSG} + context 'when in up method' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + def up + drop_table :table + ^^^^^^^^^^ #{described_class::MSG} + end + PATTERN + end + end - execute "CREATE UNIQUE INDEX email_index ON users (email);" + context 'when in change method' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + def change + drop_table :table + ^^^^^^^^^^ #{described_class::MSG} + end + PATTERN end - PATTERN + end + end + + context 'with DROP TABLE SQL literal' do + it 'does not register an offense' do + expect_no_offenses(<<~PATTERN) + def down + execute "DROP TABLE table" + end + PATTERN + end + end + + context 'when in up method' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + def up + execute "DROP TABLE table" + ^^^^^^^ #{described_class::MSG} + end + PATTERN + end + end + + context 'when in change method' do + it 'registers an offense' do + expect_offense(<<~PATTERN) + def change + execute "DROP TABLE table" + ^^^^^^^ #{described_class::MSG} + end + PATTERN + end end end |