Welcome to mirror list, hosted at ThFree Co, Russian Federation.

finder_with_find_by_spec.rb « gitlab « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d2cd06d77c53e197c07fa92ecda9188d932e2662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

require 'fast_spec_helper'

require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by'

RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do
  subject(:cop) { described_class.new }

  context 'when calling execute.find' do
    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
    end

    context 'when called within the `FinderMethods` module' do
      it 'does not register an offense' do
        expect_no_offenses(<<~SRC)
          module FinderMethods
            def find_by!(*args)
              execute.find_by!(args)
            end
          end
        SRC
      end
    end
  end
end