Commit b288f128 authored by Stan Hu's avatar Stan Hu

Fix failing N+1 spec in spec/requests/api/discussions_spec.rb

This test was failing in EE because the API helper `get()` creates a
personal access token each time it's run. We can avoid that by
pre-creating a personal access token and passing it each time.
parent cf5d64e2
...@@ -17,6 +17,8 @@ describe API::Discussions do ...@@ -17,6 +17,8 @@ describe API::Discussions do
let!(:note) { create(:system_note, noteable: merge_request, project: project, note: cross_reference) } let!(:note) { create(:system_note, noteable: merge_request, project: project, note: cross_reference) }
let!(:note_metadata) { create(:system_note_metadata, note: note, action: 'cross_reference') } let!(:note_metadata) { create(:system_note_metadata, note: note, action: 'cross_reference') }
let(:cross_reference) { "test commit #{commit.to_reference(project)}" } let(:cross_reference) { "test commit #{commit.to_reference(project)}" }
let(:pat) { create(:personal_access_token, user: user) }
let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/discussions" } let(:url) { "/projects/#{project.id}/merge_requests/#{merge_request.iid}/discussions" }
before do before do
...@@ -30,7 +32,7 @@ describe API::Discussions do ...@@ -30,7 +32,7 @@ describe API::Discussions do
new_note = create(:system_note, noteable: merge_request, project: project, note: new_cross_reference) new_note = create(:system_note, noteable: merge_request, project: project, note: new_cross_reference)
create(:system_note_metadata, note: new_note, action: 'cross_reference') create(:system_note_metadata, note: new_note, action: 'cross_reference')
get api(url, user) get api(url, user, personal_access_token: pat)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(json_response.first['notes'].count).to eq(1) expect(json_response.first['notes'].count).to eq(1)
...@@ -45,7 +47,7 @@ describe API::Discussions do ...@@ -45,7 +47,7 @@ describe API::Discussions do
expect_any_instance_of(Repository).not_to receive(:find_commit).with(commit.id) expect_any_instance_of(Repository).not_to receive(:find_commit).with(commit.id)
control = ActiveRecord::QueryRecorder.new do control = ActiveRecord::QueryRecorder.new do
get api(url, user) get api(url, user, personal_access_token: pat)
end end
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
...@@ -57,7 +59,7 @@ describe API::Discussions do ...@@ -57,7 +59,7 @@ describe API::Discussions do
RequestStore.clear! RequestStore.clear!
expect { get api(url, user) }.not_to exceed_query_limit(control) expect { get api(url, user, personal_access_token: pat) }.not_to exceed_query_limit(control)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment