diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-05-17 12:46:33 +0300 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-05-17 13:56:25 +0300 |
commit | 9ff6edf690423a284f4d0ad924ff2a9a4285eb50 (patch) | |
tree | 9b770e812bd923a664a0c2166935794dcd3dffb3 /spec | |
parent | f117c032ac6c414e6c1dfeab98184363c1f61608 (diff) |
Review updates and cleanup
* Cleaned issues and issues_statistics docs
* Renamed param with_labels_data to with_labels_details
* Added spec for N+1 check when retrieving labels from issue
* Refactoed CheckAssigneesCount validation class
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/issues/issues_spec.rb | 51 | ||||
-rw-r--r-- | spec/support/shared_examples/requests/api/issues_shared_example_spec.rb | 6 |
2 files changed, 41 insertions, 16 deletions
diff --git a/spec/requests/api/issues/issues_spec.rb b/spec/requests/api/issues/issues_spec.rb index 24c53d9c68f..9b9cc778fb3 100644 --- a/spec/requests/api/issues/issues_spec.rb +++ b/spec/requests/api/issues/issues_spec.rb @@ -122,25 +122,25 @@ describe API::Issues do expect_paginated_array_response([issue.id, closed_issue.id]) end - it 'returns authentication error without any scope' do - get api('/issues_statistics') + context 'issues_statistics' do + it 'returns authentication error without any scope' do + get api('/issues_statistics') - expect(response).to have_http_status(401) - end + expect(response).to have_http_status(401) + end - it 'returns authentication error when scope is assigned-to-me' do - get api('/issues_statistics'), params: { scope: 'assigned-to-me' } + it 'returns authentication error when scope is assigned_to_me' do + get api('/issues_statistics'), params: { scope: 'assigned_to_me' } - expect(response).to have_http_status(401) - end + expect(response).to have_http_status(401) + end - it 'returns authentication error when scope is created-by-me' do - get api('/issues_statistics'), params: { scope: 'created-by-me' } + it 'returns authentication error when scope is created_by_me' do + get api('/issues_statistics'), params: { scope: 'created_by_me' } - expect(response).to have_http_status(401) - end + expect(response).to have_http_status(401) + end - context 'issues_statistics' do context 'no state is treated as all state' do let(:params) { {} } let(:counts) { { all: 2, closed: 1, opened: 1 } } @@ -386,6 +386,31 @@ describe API::Issues do end context 'filter by labels or label_name param' do + context 'N+1' do + let(:label_b) { create(:label, title: 'foo', project: project) } + let(:label_c) { create(:label, title: 'bar', project: project) } + + before do + create(:label_link, label: label_b, target: issue) + create(:label_link, label: label_c, target: issue) + end + it 'tests N+1' do + control = ActiveRecord::QueryRecorder.new do + get api('/issues', user), params: { labels: [label.title, label_b.title, label_c.title] } + end + + label_d = create(:label, title: 'dar', project: project) + label_e = create(:label, title: 'ear', project: project) + create(:label_link, label: label_d, target: issue) + create(:label_link, label: label_e, target: issue) + + expect do + get api('/issues', user), params: { labels: [label.title, label_b.title, label_c.title] } + end.not_to exceed_query_limit(control) + expect(issue.labels.count).to eq(5) + end + end + it 'returns an array of labeled issues' do get api('/issues', user), params: { labels: label.title } diff --git a/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb b/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb index d1c8e2208a3..1133e95e44e 100644 --- a/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb +++ b/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb @@ -28,15 +28,15 @@ shared_examples 'labeled issues with labels and label_name params' do it_behaves_like 'returns label names' end - context 'when with_labels_data provided' do + context 'when with_labels_details provided' do context 'array of labeled issues when all labels match' do - let(:params) { { labels: "#{label.title},#{label_b.title},#{label_c.title}", with_labels_data: true } } + let(:params) { { labels: "#{label.title},#{label_b.title},#{label_c.title}", with_labels_details: true } } it_behaves_like 'returns basic label entity' end context 'array of labeled issues when all labels match with labels param as array' do - let(:params) { { labels: [label.title, label_b.title, label_c.title], with_labels_data: true } } + let(:params) { { labels: [label.title, label_b.title, label_c.title], with_labels_details: true } } it_behaves_like 'returns basic label entity' end |