summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-06-21 08:31:12 +0000
committerDouwe Maan <douwe@gitlab.com>2018-06-21 08:31:12 +0000
commit4226873afbf3950b1e7ff0ed106822c16c10bc67 (patch)
tree3531aded0d07282d3e2fb8a227f7f7411ff39572 /spec
parent7c11ed8c916a10f6d9c32635986008b48410531f (diff)
parentf3f1df1476ba7fe223e5d8d6707a7675dc9fa597 (diff)
downloadgitlab-ce-4226873afbf3950b1e7ff0ed106822c16c10bc67.tar.gz
Merge branch 'bvl-finder-methods-cop' into 'master'
Add a cop for `FinderMethods` Closes #42705 See merge request gitlab-org/gitlab-ce!19951
Diffstat (limited to 'spec')
-rw-r--r--spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb56
-rw-r--r--spec/services/issues/resolve_discussions_spec.rb4
2 files changed, 57 insertions, 3 deletions
diff --git a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb
new file mode 100644
index 00000000000..7f689b196c5
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by'
+
+describe RuboCop::Cop::Gitlab::FinderWithFindBy do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'when calling execute.find' do
+ let(:source) do
+ <<~SRC
+ DummyFinder.new(some_args)
+ .execute
+ .find_by!(1)
+ SRC
+ end
+ let(:corrected_source) do
+ <<~SRC
+ DummyFinder.new(some_args)
+ .find_by!(1)
+ SRC
+ end
+
+ it 'registers an offence' do
+ inspect_source(source)
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'can autocorrect the source' do
+ expect(autocorrect_source(source)).to eq(corrected_source)
+ end
+
+ context 'when called within the `FinderMethods` module' do
+ let(:source) do
+ <<~SRC
+ module FinderMethods
+ def find_by!(*args)
+ execute.find_by!(args)
+ end
+ end
+ SRC
+ end
+
+ it 'does not register an offence' do
+ inspect_source(source)
+
+ expect(cop.offenses).to be_empty
+ end
+ end
+ end
+end
diff --git a/spec/services/issues/resolve_discussions_spec.rb b/spec/services/issues/resolve_discussions_spec.rb
index 13accc6ae1b..b6cfc09da65 100644
--- a/spec/services/issues/resolve_discussions_spec.rb
+++ b/spec/services/issues/resolve_discussions_spec.rb
@@ -31,10 +31,8 @@ describe Issues::ResolveDiscussions do
it "only queries for the merge request once" do
fake_finder = double
- fake_results = double
- expect(fake_finder).to receive(:execute).and_return(fake_results).exactly(1)
- expect(fake_results).to receive(:find_by).exactly(1)
+ expect(fake_finder).to receive(:find_by).exactly(1)
expect(MergeRequestsFinder).to receive(:new).and_return(fake_finder).exactly(1)
2.times { service.merge_request_to_resolve_discussions_of }