debian-mirror-gitlab/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb

42 lines
1 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2020-04-08 14:13:33 +05:30
require_relative '../../../../rubocop/cop/migration/with_lock_retries_with_change'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Migration::WithLockRetriesWithChange do
2020-04-08 14:13:33 +05:30
subject(:cop) { described_class.new }
2021-04-17 20:07:23 +05:30
context 'when in migration' do
2020-04-08 14:13:33 +05:30
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when `with_lock_retries` is used inside a `change` method' do
2021-04-17 20:07:23 +05:30
expect_offense(<<~RUBY)
def change
^^^^^^ `with_lock_retries` cannot be used within `change` [...]
with_lock_retries {}
end
RUBY
2020-04-08 14:13:33 +05:30
end
it 'registers no offense when `with_lock_retries` is used inside an `up` method' do
2021-04-17 20:07:23 +05:30
expect_no_offenses(<<~RUBY)
def up
with_lock_retries {}
end
RUBY
2020-04-08 14:13:33 +05:30
end
end
2021-04-17 20:07:23 +05:30
context 'when outside of migration' do
2020-04-08 14:13:33 +05:30
it 'registers no offense' do
2021-04-17 20:07:23 +05:30
expect_no_offenses(<<~RUBY)
def change
with_lock_retries {}
end
RUBY
2020-04-08 14:13:33 +05:30
end
end
end