Commit a2a8c590 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'refactor_api_deployments_spec' into 'master'

Refactor API deployments spec

See merge request gitlab-org/gitlab!22537
parents 4dba72cf f93dd640
...@@ -346,38 +346,26 @@ describe API::Deployments do ...@@ -346,38 +346,26 @@ describe API::Deployments do
context 'prevent N + 1 queries' do context 'prevent N + 1 queries' do
context 'when the endpoint returns multiple records' do context 'when the endpoint returns multiple records' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let!(:deployment) { create(:deployment, :success, project: project) }
def create_record subject { get api("/projects/#{project.id}/deployments?order_by=updated_at&sort=asc", user) }
create(:deployment, :success, project: project)
end
def request_with_query_count
ActiveRecord::QueryRecorder.new { trigger_request }.count
end
def trigger_request it 'succeeds', :aggregate_failures do
get api("/projects/#{project.id}/deployments?order_by=updated_at&sort=asc", user) subject
end
before do
create_record
end
it 'succeeds' do
trigger_request
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
end end
it 'does not increase the query count' do context 'with 10 more records' do
10.times { create_record } it 'does not increase the query count', :aggregate_failures do
create_list(:deployment, 10, :success, project: project)
expect { trigger_request }.not_to be_n_plus_1_query expect { subject }.not_to be_n_plus_1_query
expect(json_response.size).to eq(11) expect(json_response.size).to eq(11)
end end
end end
end 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