diff options
author | Stan Hu <stanhu@gmail.com> | 2017-07-08 21:44:03 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-07-08 22:19:34 -0700 |
commit | 0a9a33e7eb6e0d0e8fc7c69fec7863e6f52b4f42 (patch) | |
tree | a1cd164fa914f971c2f3ed459aa7c0bd867dcd1c /spec | |
parent | 88c4248ac72ab1e520edddfa184000d59c509e8f (diff) | |
download | gitlab-ce-0a9a33e7eb6e0d0e8fc7c69fec7863e6f52b4f42.tar.gz |
Add spec for N+1 queries
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 6b67523981c..360a82196a8 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -36,6 +36,18 @@ describe API::MergeRequests do end context "when authenticated" do + it 'avoids N+1 queries' do + control_count = ActiveRecord::QueryRecorder.new do + get api("/projects/#{project.id}/merge_requests", user) + end.count + + create(:merge_request, state: 'closed', milestone: milestone1, author: user, assignee: user, source_project: project, target_project: project, title: "Test", created_at: base_time) + + expect do + get api("/projects/#{project.id}/merge_requests", user) + end.not_to exceed_query_limit(control_count) + end + it "returns an array of all merge_requests" do get api("/projects/#{project.id}/merge_requests", user) |