diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 00:07:49 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 00:07:49 +0000 |
commit | 77237c5a6b9044f58beabc54d3589e5fa09cbfba (patch) | |
tree | f43188047fe8955f6cf78e05ae9c2e8f6a019e0b /spec/requests/groups/milestones_controller_spec.rb | |
parent | 2fd92f2dc784ade9cb4e1c33dd60cbfad7b86818 (diff) | |
download | gitlab-ce-77237c5a6b9044f58beabc54d3589e5fa09cbfba.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/groups/milestones_controller_spec.rb')
-rw-r--r-- | spec/requests/groups/milestones_controller_spec.rb | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/spec/requests/groups/milestones_controller_spec.rb b/spec/requests/groups/milestones_controller_spec.rb index 4d15aa43cd2..1c6743dc678 100644 --- a/spec/requests/groups/milestones_controller_spec.rb +++ b/spec/requests/groups/milestones_controller_spec.rb @@ -12,23 +12,45 @@ describe Groups::MilestonesController do end let!(:private_milestone) { create(:milestone, project: public_project_with_private_issues_and_mrs, title: 'project milestone') } - it 'avoids N+1 database queries' do - public_project = create(:project, :public, :merge_requests_enabled, :issues_enabled, group: public_group) - create(:milestone, project: public_project) + describe 'GET #index' do + it 'avoids N+1 database queries' do + public_project = create(:project, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + create(:milestone, project: public_project) - control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get "/groups/#{public_group.to_param}/-/milestones.json" }.count + control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get group_milestones_path(public_group, format: :json) }.count - projects = create_list(:project, 2, :public, :merge_requests_enabled, :issues_enabled, group: public_group) - projects.each do |project| - create(:milestone, project: project) + projects = create_list(:project, 2, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create(:milestone, project: project) + end + + expect { get group_milestones_path(public_group, format: :json) }.not_to exceed_all_query_limit(control_count) + expect(response).to have_gitlab_http_status(:ok) + milestones = json_response + + expect(milestones.count).to eq(3) + expect(milestones.map {|x| x['title']}).not_to include(private_milestone.title) end + end - expect { get "/groups/#{public_group.to_param}/-/milestones.json" }.not_to exceed_all_query_limit(control_count) - expect(response).to have_gitlab_http_status(:ok) - milestones = json_response + describe 'GET #show' do + let(:milestone) { create(:milestone, group: public_group) } + let(:show_path) { group_milestone_path(public_group, milestone) } - expect(milestones.count).to eq(3) - expect(milestones.map {|x| x['title']}).not_to include(private_milestone.title) + it 'avoids N+1 database queries' do + projects = create_list(:project, 3, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create_list(:issue, 2, milestone: milestone, project: project) + end + control = ActiveRecord::QueryRecorder.new(skip_cached: false) { get show_path } + + projects = create_list(:project, 3, :public, :merge_requests_enabled, :issues_enabled, group: public_group) + projects.each do |project| + create_list(:issue, 2, milestone: milestone, project: project) + end + + expect { get show_path }.not_to exceed_all_query_limit(control) + end end end end |