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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJames Lopez <james@gitlab.com>2019-02-21 14:38:11 +0300
committerJames Lopez <james@gitlab.com>2019-02-21 14:38:11 +0300
commit3de4c8d0462aba1e254a255c438c80092109edf7 (patch)
treed8c9103dc3bdfa34b3f13f1ae354305ecefa8819 /spec
parent161851de3632c772248b7f2f0d5614b49bd06a21 (diff)
parent843f4b94b59255ec27b3bdf22e93180fce74ddca (diff)
Merge branch '57867-accessing-issue-1-of-gitlab-ce-via-the-api-results-in-500-internal-server-error' into 'master'
Speed up find_by when used on finders Closes #57867 See merge request gitlab-org/gitlab-ce!25421
Diffstat (limited to 'spec')
-rw-r--r--spec/finders/concerns/finder_methods_spec.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/spec/finders/concerns/finder_methods_spec.rb b/spec/finders/concerns/finder_methods_spec.rb
index a4ad331f613..e074e53c2c5 100644
--- a/spec/finders/concerns/finder_methods_spec.rb
+++ b/spec/finders/concerns/finder_methods_spec.rb
@@ -12,7 +12,7 @@ describe FinderMethods do
end
def execute
- Project.all
+ Project.all.order(id: :desc)
end
end
end
@@ -38,6 +38,16 @@ describe FinderMethods do
it 'raises not found the user does not have access' do
expect { finder.find_by!(id: unauthorized_project.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
+
+ it 'ignores ordering' do
+ # Memoise the finder result so we can add message expectations to it
+ relation = finder.execute
+ allow(finder).to receive(:execute).and_return(relation)
+
+ expect(relation).to receive(:reorder).with(nil).and_call_original
+
+ finder.find_by!(id: authorized_project.id)
+ end
end
describe '#find' do
@@ -66,5 +76,15 @@ describe FinderMethods do
it 'returns nil when the user does not have access' do
expect(finder.find_by(id: unauthorized_project.id)).to be_nil
end
+
+ it 'ignores ordering' do
+ # Memoise the finder result so we can add message expectations to it
+ relation = finder.execute
+ allow(finder).to receive(:execute).and_return(relation)
+
+ expect(relation).to receive(:reorder).with(nil).and_call_original
+
+ finder.find_by(id: authorized_project.id)
+ end
end
end