blob: b5e2e83e788446f985e0b13afde157dc27198054 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# frozen_string_literal: true
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/batch_migrations_post_only'
RSpec.describe RuboCop::Cop::Migration::BatchMigrationsPostOnly do
let(:cop) { described_class.new }
before do
allow(cop).to receive(:in_post_deployment_migration?).and_return post_migration?
end
context 'when methods appear in a regular migration' do
let(:post_migration?) { false }
it "does not allow 'ensure_batched_background_migration_is_finished' to be called" do
expect_offense(<<~CODE)
ensure_batched_background_migration_is_finished
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This method must only be used in post-deployment migrations.
CODE
end
it "does not allow 'queue_batched_background_migration' to be called" do
expect_offense(<<~CODE)
queue_batched_background_migration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This method must only be used in post-deployment migrations.
CODE
end
it "does not allow 'delete_batched_background_migration' to be called" do
expect_offense(<<~CODE)
delete_batched_background_migration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This method must only be used in post-deployment migrations.
CODE
end
it "does not allow 'ensure_batched_background_migration_is_finished' to be called" do
expect_offense(<<~CODE)
finalize_batched_background_migration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This method must only be used in post-deployment migrations.
CODE
end
it 'allows arbitrary other method to be called' do
expect_no_offenses(<<~CODE)
foo
CODE
end
end
context 'when methods appear in a post-deployment migration' do
let(:post_migration?) { true }
it "allows 'ensure_batched_background_migration_is_finished' to be called" do
expect_no_offenses(<<~CODE)
ensure_batched_background_migration_is_finished
CODE
end
it "allows 'queue_batched_background_migration' to be called" do
expect_no_offenses(<<~CODE)
queue_batched_background_migration
CODE
end
it "allows 'delete_batched_background_migration' to be called" do
expect_no_offenses(<<~CODE)
delete_batched_background_migration
CODE
end
it "allows 'ensure_batched_background_migration_is_finished' to be called" do
expect_no_offenses(<<~CODE)
finalize_batched_background_migration
CODE
end
it 'allows arbitrary other method to be called' do
expect_no_offenses(<<~CODE)
foo
CODE
end
end
end
|