summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-08-08 16:27:38 +0200
committerRémy Coutable <remy@rymai.me>2017-08-08 16:27:38 +0200
commit164e6604117ef32980fc221fdab2b7188bc1c167 (patch)
tree7f90fdd33b5928f328838ef6b38054b5c1277d44 /spec
parent2aa460de76840d469071f17df9433c614e700e6e (diff)
downloadgitlab-ce-164e6604117ef32980fc221fdab2b7188bc1c167.tar.gz
Fix a broken Events API spec36169-fix-master
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/events_spec.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb
index 48db964d782..f1a26b6ce6c 100644
--- a/spec/requests/api/events_spec.rb
+++ b/spec/requests/api/events_spec.rb
@@ -140,33 +140,28 @@ describe API::Events do
end
context 'when exists some events' do
+ let(:merge_request1) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: 'Test') }
+ let(:merge_request2) { create(:merge_request, :closed, author: user, assignee: user, source_project: private_project, title: 'Test') }
+
before do
- create_event(note1)
- create_event(note2)
create_event(merge_request1)
end
- let(:note1) { create(:note_on_merge_request, project: private_project, author: user) }
- let(:note2) { create(:note_on_issue, project: private_project, author: user) }
- let(:merge_request1) { create(:merge_request, state: 'closed', author: user, assignee: user, source_project: private_project, title: 'Test') }
- let(:merge_request2) { create(:merge_request, state: 'closed', author: user, assignee: user, source_project: private_project, title: 'Test') }
-
it 'avoids N+1 queries' do
control_count = ActiveRecord::QueryRecorder.new do
- get api("/projects/#{private_project.id}/events", user)
+ get api("/projects/#{private_project.id}/events", user), target_type: :merge_request
end.count
create_event(merge_request2)
expect do
- get api("/projects/#{private_project.id}/events", user)
+ get api("/projects/#{private_project.id}/events", user), target_type: :merge_request
end.not_to exceed_query_limit(control_count)
- expect(response).to have_http_status(200)
+ expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
- expect(json_response).to be_an Array
- expect(json_response[0]).to include('target_type' => 'MergeRequest', 'target_id' => merge_request2.id)
- expect(json_response[1]).to include('target_type' => 'MergeRequest', 'target_id' => merge_request1.id)
+ expect(json_response.size).to eq(2)
+ expect(json_response.map { |r| r['target_id'] }).to match_array([merge_request1.id, merge_request2.id])
end
def create_event(target)