debian-mirror-gitlab/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb

38 lines
925 B
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2018-11-08 19:23:39 +05:30
require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do
2018-11-08 19:23:39 +05:30
subject(:cop) { described_class.new }
context 'when calling execute.find' do
2021-03-11 19:13:27 +05:30
it 'registers an offense and corrects' do
expect_offense(<<~CODE)
DummyFinder.new(some_args)
.execute
.find_by!(1)
^^^^^^^^ Don't chain finders `#execute` method with [...]
CODE
expect_correction(<<~CODE)
DummyFinder.new(some_args)
.find_by!(1)
CODE
2018-11-08 19:23:39 +05:30
end
context 'when called within the `FinderMethods` module' do
2021-03-11 19:13:27 +05:30
it 'does not register an offense' do
expect_no_offenses(<<~SRC)
2018-11-08 19:23:39 +05:30
module FinderMethods
def find_by!(*args)
execute.find_by!(args)
end
end
SRC
end
end
end
end