|
5 | 5 | describe RuboCop::Cop::Sequel::NotValidConstraint do |
6 | 6 | subject(:cop) { described_class.new } |
7 | 7 |
|
8 | | - it 'registers an offense when add_constraint used without valid option' do |
9 | | - offenses = inspect_source(<<~RUBY) |
10 | | - add_constraint :not_valid, Sequel.lit("jsonb_typeof(column) = 'object'") |
11 | | - add_constraint({name: "not_valid"}, Sequel.lit("jsonb_typeof(column) = 'object'")) |
12 | | - RUBY |
13 | | - |
14 | | - expect(offenses.size).to eq(2) |
| 8 | + context 'when add_constraint used' do |
| 9 | + it 'registers an offense when used without `not_valid: true` option' do |
| 10 | + offenses = inspect_source(<<~RUBY) |
| 11 | + add_constraint :not_valid, Sequel.lit("jsonb_typeof(column) = 'object'") |
| 12 | + add_constraint({name: "not_valid"}, Sequel.lit("jsonb_typeof(column) = 'object'")) |
| 13 | + RUBY |
| 14 | + |
| 15 | + expect(offenses.size).to eq(2) |
| 16 | + end |
| 17 | + |
| 18 | + it 'does not register an offense when using `not_valid: true` option' do |
| 19 | + offenses = inspect_source(<<~RUBY) |
| 20 | + add_constraint({name: "name", not_valid: true }, Sequel.lit("jsonb_typeof(column) = 'object'")) |
| 21 | + RUBY |
| 22 | + |
| 23 | + expect(offenses.size).to eq(0) |
| 24 | + end |
15 | 25 | end |
16 | 26 |
|
17 | | - it 'registers an offense when add_foregn_key used without valid option' do |
18 | | - offenses = inspect_source(<<~RUBY) |
19 | | - add_foreign_key(:not_valid, :table) |
20 | | - add_foreign_key(:not_valid, :table, name: "not_valid") |
21 | | - RUBY |
| 27 | + context 'when add_foreign_key used' do |
| 28 | + it 'registers an offense when used without `not_valid: true` option' do |
| 29 | + offenses = inspect_source(<<~RUBY) |
| 30 | + add_foreign_key(:not_valid, :table) |
| 31 | + add_foreign_key(:not_valid, :table, name: "not_valid") |
| 32 | + RUBY |
22 | 33 |
|
23 | | - expect(offenses.size).to eq(2) |
24 | | - end |
| 34 | + expect(offenses.size).to eq(2) |
| 35 | + end |
25 | 36 |
|
26 | | - it 'does not register an offense when using not valid option' do |
27 | | - offenses = inspect_source(<<~RUBY) |
28 | | - add_constraint({name: "name", not_valid: true }, Sequel.lit("jsonb_typeof(column) = 'object'")) |
29 | | - add_foreign_key(:not_valid, :table, name: "not_valid", not_valid: true) |
30 | | - RUBY |
| 37 | + it 'does not register an offense when using `not_valid: true` option' do |
| 38 | + offenses = inspect_source(<<~RUBY) |
| 39 | + add_foreign_key(:not_valid, :table, name: "not_valid", not_valid: true) |
| 40 | + RUBY |
31 | 41 |
|
32 | | - expect(offenses.size).to eq(0) |
| 42 | + expect(offenses.size).to eq(0) |
| 43 | + end |
33 | 44 | end |
34 | 45 | end |
0 commit comments