|
11 | 11 |
|
12 | 12 | RSpec.shared_examples 'a cop that validates explicit names are added to the index' do |method_name|
|
13 | 13 | it 'registers an offense if index is called without a name' do
|
14 |
| - inspect_source(<<~RUBY) |
| 14 | + result = inspect_source(<<~RUBY) |
15 | 15 | create_table :jobs do
|
16 | 16 | #{method_name} :foo
|
17 | 17 | end
|
18 | 18 | RUBY
|
19 | 19 |
|
20 |
| - expect(cop.offenses.size).to eq(1) |
21 |
| - expect(cop.messages).to eq(['Please explicitly name your index or constraint.']) |
| 20 | + expect(result.size).to eq(1) |
| 21 | + expect(result.map(&:message)).to eq(['Please explicitly name your index or constraint.']) |
22 | 22 | end
|
23 | 23 |
|
24 | 24 | it 'does not register an offense if index is called with a name' do
|
25 |
| - inspect_source(<<~RUBY) |
| 25 | + result = inspect_source(<<~RUBY) |
26 | 26 | create_table :jobs do
|
27 | 27 | #{method_name} :foo, name: :bar
|
28 | 28 | end
|
29 | 29 | RUBY
|
30 | 30 |
|
31 |
| - expect(cop.offenses.size).to eq(0) |
32 |
| - expect(cop.messages).to be_empty |
| 31 | + expect(result.size).to eq(0) |
33 | 32 | end
|
34 | 33 | end
|
35 | 34 |
|
36 | 35 | RSpec.shared_examples 'a cop that validates explicit names are used when adding a column with an index' do |method_name|
|
37 | 36 | context 'and the column is adding an index' do
|
38 | 37 | it 'registers an offense if index is called without a name' do
|
39 |
| - inspect_source(<<~RUBY) |
| 38 | + result = inspect_source(<<~RUBY) |
40 | 39 | create_table :jobs do
|
41 | 40 | #{method_name} :foo, :index
|
42 | 41 | end
|
43 | 42 | RUBY
|
44 | 43 |
|
45 |
| - expect(cop.offenses.size).to eq(1) |
46 |
| - expect(cop.messages).to eq(['Please explicitly name your index or constraint.']) |
| 44 | + expect(result.size).to eq(1) |
| 45 | + expect(result.map(&:message)).to eq(['Please explicitly name your index or constraint.']) |
47 | 46 | end
|
48 | 47 |
|
49 | 48 | it 'does not register an offense if index is called with a name' do
|
50 |
| - inspect_source(<<~RUBY) |
| 49 | + result = inspect_source(<<~RUBY) |
51 | 50 | create_table :jobs do
|
52 | 51 | #{method_name} :foo, index: {name: 'foo'}
|
53 | 52 | end
|
54 | 53 | RUBY
|
55 | 54 |
|
56 |
| - expect(cop.offenses.size).to eq(0) |
57 |
| - expect(cop.messages).to be_empty |
| 55 | + expect(result.size).to eq(0) |
58 | 56 | end
|
59 | 57 | end
|
60 | 58 |
|
61 | 59 | context 'and the column is adding a unique constraint' do
|
62 | 60 | it 'registers an offense if unique is called without a unique_constraint_name' do
|
63 |
| - inspect_source(<<~RUBY) |
| 61 | + result = inspect_source(<<~RUBY) |
64 | 62 | create_table :jobs do
|
65 | 63 | #{method_name} :foo, unique: true
|
66 | 64 | end
|
67 | 65 | RUBY
|
68 | 66 |
|
69 |
| - expect(cop.offenses.size).to eq(1) |
70 |
| - expect(cop.messages).to eq(['Please explicitly name your index or constraint.']) |
| 67 | + expect(result.size).to eq(1) |
| 68 | + expect(result.map(&:message)).to eq(['Please explicitly name your index or constraint.']) |
71 | 69 | end
|
72 | 70 |
|
73 | 71 | it 'does not register an offense if unique is called with a unique_constraint_name' do
|
74 |
| - inspect_source(<<~RUBY) |
| 72 | + result = inspect_source(<<~RUBY) |
75 | 73 | create_table :jobs do
|
76 | 74 | #{method_name} :foo, unique: true, unique_constraint_name: 'something_real_unique'
|
77 | 75 | end
|
78 | 76 | RUBY
|
79 | 77 |
|
80 |
| - expect(cop.offenses.size).to eq(0) |
81 |
| - expect(cop.messages).to be_empty |
| 78 | + expect(result.size).to eq(0) |
82 | 79 | end
|
83 | 80 | end
|
84 | 81 |
|
85 | 82 | context 'and the column is adding a primary_key constraint' do
|
86 | 83 | it 'registers an offense if unique is called without a primary_key_constraint_name' do
|
87 |
| - inspect_source(<<~RUBY) |
| 84 | + result = inspect_source(<<~RUBY) |
88 | 85 | create_table :jobs do
|
89 | 86 | #{method_name} :foo, primary_key: true
|
90 | 87 | end
|
91 | 88 | RUBY
|
92 | 89 |
|
93 |
| - expect(cop.offenses.size).to eq(1) |
94 |
| - expect(cop.messages).to eq(['Please explicitly name your index or constraint.']) |
| 90 | + expect(result.size).to eq(1) |
| 91 | + expect(result.map(&:message)).to eq(['Please explicitly name your index or constraint.']) |
95 | 92 | end
|
96 | 93 |
|
97 | 94 | it 'does not register an offense if primary_key is called with a primary_key_constraint_name' do
|
98 |
| - inspect_source(<<~RUBY) |
| 95 | + result = inspect_source(<<~RUBY) |
99 | 96 | create_table :jobs do
|
100 | 97 | #{method_name} :foo, primary_key: true, primary_key_constraint_name: 'something_real_unique'
|
101 | 98 | end
|
102 | 99 | RUBY
|
103 | 100 |
|
104 |
| - expect(cop.offenses.size).to eq(0) |
105 |
| - expect(cop.messages).to be_empty |
| 101 | + expect(result.size).to eq(0) |
106 | 102 | end
|
107 | 103 | end
|
108 | 104 |
|
109 | 105 | context 'and the column is not adding any index or constraint' do
|
110 | 106 | it 'does not register an offense' do
|
111 |
| - inspect_source(<<~RUBY) |
| 107 | + result = inspect_source(<<~RUBY) |
112 | 108 | create_table :jobs do
|
113 | 109 | #{method_name} :foo
|
114 | 110 | end
|
115 | 111 | RUBY
|
116 | 112 |
|
117 |
| - expect(cop.offenses.size).to eq(0) |
118 |
| - expect(cop.messages).to be_empty |
| 113 | + expect(result.size).to eq(0) |
119 | 114 | end
|
120 | 115 | end
|
121 | 116 | end
|
|
0 commit comments