2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
require 'fast_spec_helper'
|
2019-07-31 22:56:46 +05:30
|
|
|
require 'rubocop'
|
|
|
|
require_relative '../../../rubocop/cop/active_record_association_reload'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::ActiveRecordAssociationReload do
|
2019-07-31 22:56:46 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context 'when using ActiveRecord::Base' do
|
|
|
|
it 'registers an offense on reload usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_offense(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
users = User.all
|
|
|
|
users.reload
|
2019-12-04 20:38:33 +05:30
|
|
|
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
2020-11-24 15:15:51 +05:30
|
|
|
PATTERN
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense on reset usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
users = User.all
|
|
|
|
users.reset
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using ActiveRecord::Relation' do
|
|
|
|
it 'registers an offense on reload usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_offense(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
user = User.new
|
|
|
|
user.reload
|
2019-12-04 20:38:33 +05:30
|
|
|
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
2019-07-31 22:56:46 +05:30
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense on reset usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
user = User.new
|
|
|
|
user.reset
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using on self' do
|
|
|
|
it 'registers an offense on reload usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_offense(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
reload
|
2019-12-04 20:38:33 +05:30
|
|
|
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
2019-07-31 22:56:46 +05:30
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not register an offense on reset usage' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect_no_offenses(<<~PATTERN)
|
2019-07-31 22:56:46 +05:30
|
|
|
reset
|
|
|
|
PATTERN
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|