Skip to content

Commit

Permalink
Refactor specs
Browse files Browse the repository at this point in the history
  • Loading branch information
numbata committed May 7, 2024
1 parent 0a3325f commit 0f9cb6a
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions spec/rubocop/cop/sequel/not_valid_constraint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,41 @@
describe RuboCop::Cop::Sequel::NotValidConstraint do
subject(:cop) { described_class.new }

it 'registers an offense when add_constraint used without valid option' do
offenses = inspect_source(<<~RUBY)
add_constraint :not_valid, Sequel.lit("jsonb_typeof(column) = 'object'")
add_constraint({name: "not_valid"}, Sequel.lit("jsonb_typeof(column) = 'object'"))
RUBY

expect(offenses.size).to eq(2)
context 'when add_constraint used' do
it 'registers an offense when used without `not_valid: true` option' do
offenses = inspect_source(<<~RUBY)
add_constraint :not_valid, Sequel.lit("jsonb_typeof(column) = 'object'")
add_constraint({name: "not_valid"}, Sequel.lit("jsonb_typeof(column) = 'object'"))
RUBY

expect(offenses.size).to eq(2)
end

it 'does not register an offense when using `not_valid: true` option' do
offenses = inspect_source(<<~RUBY)
add_constraint({name: "name", not_valid: true }, Sequel.lit("jsonb_typeof(column) = 'object'"))
RUBY

expect(offenses.size).to eq(0)
end
end

it 'registers an offense when add_foregn_key used without valid option' do
offenses = inspect_source(<<~RUBY)
add_foreign_key(:not_valid, :table)
add_foreign_key(:not_valid, :table, name: "not_valid")
RUBY
context 'when add_foreign_key used' do
it 'registers an offense when used without `not_valid: true` option' do
offenses = inspect_source(<<~RUBY)
add_foreign_key(:not_valid, :table)
add_foreign_key(:not_valid, :table, name: "not_valid")
RUBY

expect(offenses.size).to eq(2)
end
expect(offenses.size).to eq(2)
end

it 'does not register an offense when using not valid option' do
offenses = inspect_source(<<~RUBY)
add_constraint({name: "name", not_valid: true }, Sequel.lit("jsonb_typeof(column) = 'object'"))
add_foreign_key(:not_valid, :table, name: "not_valid", not_valid: true)
RUBY
it 'does not register an offense when using `not_valid: true` option' do
offenses = inspect_source(<<~RUBY)
add_foreign_key(:not_valid, :table, name: "not_valid", not_valid: true)
RUBY

expect(offenses.size).to eq(0)
expect(offenses.size).to eq(0)
end
end
end

0 comments on commit 0f9cb6a

Please sign in to comment.