diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/optimistic_locking_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubocop/cop/active_record_association_reload_spec.rb | 60 |
2 files changed, 62 insertions, 2 deletions
diff --git a/spec/lib/gitlab/optimistic_locking_spec.rb b/spec/lib/gitlab/optimistic_locking_spec.rb index 81f81d4f963..6fdf61ee0a7 100644 --- a/spec/lib/gitlab/optimistic_locking_spec.rb +++ b/spec/lib/gitlab/optimistic_locking_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::OptimisticLocking do describe '#retry_lock' do it 'does not reload object if state changes' do - expect(pipeline).not_to receive(:reload) + expect(pipeline).not_to receive(:reset) expect(pipeline).to receive(:succeed).and_call_original described_class.retry_lock(pipeline) do |subject| @@ -17,7 +17,7 @@ describe Gitlab::OptimisticLocking do it 'retries action if exception is raised' do pipeline.succeed - expect(pipeline2).to receive(:reload).and_call_original + expect(pipeline2).to receive(:reset).and_call_original expect(pipeline2).to receive(:drop).twice.and_call_original described_class.retry_lock(pipeline2) do |subject| diff --git a/spec/rubocop/cop/active_record_association_reload_spec.rb b/spec/rubocop/cop/active_record_association_reload_spec.rb new file mode 100644 index 00000000000..69eb16a54d2 --- /dev/null +++ b/spec/rubocop/cop/active_record_association_reload_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require_relative '../../../rubocop/cop/active_record_association_reload' + +describe RuboCop::Cop::ActiveRecordAssociationReload do + include CopHelper + + subject(:cop) { described_class.new } + + context 'when using ActiveRecord::Base' do + it 'registers an offense on reload usage' do + expect_offense(<<~PATTERN.strip_indent) + users = User.all + users.reload + ^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-ce/issues/60218. + PATTERN + end + + it 'does not register an offense on reset usage' do + expect_no_offenses(<<~PATTERN.strip_indent) + users = User.all + users.reset + PATTERN + end + end + + context 'when using ActiveRecord::Relation' do + it 'registers an offense on reload usage' do + expect_offense(<<~PATTERN.strip_indent) + user = User.new + user.reload + ^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-ce/issues/60218. + PATTERN + end + + it 'does not register an offense on reset usage' do + expect_no_offenses(<<~PATTERN.strip_indent) + user = User.new + user.reset + PATTERN + end + end + + context 'when using on self' do + it 'registers an offense on reload usage' do + expect_offense(<<~PATTERN.strip_indent) + reload + ^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-ce/issues/60218. + PATTERN + end + + it 'does not register an offense on reset usage' do + expect_no_offenses(<<~PATTERN.strip_indent) + reset + PATTERN + end + end +end |