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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
887 B
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_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
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