debian-mirror-gitlab/spec/requests/groups/milestones_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
3.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2019-09-30 23:59:55 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Groups::MilestonesController do
2019-09-30 23:59:55 +05:30
context 'N+1 DB queries' do
2021-04-29 21:17:54 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:public_group) { create(:group, :public) }
2019-09-30 23:59:55 +05:30
let!(:public_project_with_private_issues_and_mrs) do
create(:project, :public, :issues_private, :merge_requests_private, group: public_group)
end
2020-10-24 23:57:45 +05:30
2019-09-30 23:59:55 +05:30
let!(:private_milestone) { create(:milestone, project: public_project_with_private_issues_and_mrs, title: 'project milestone') }
2020-04-08 14:13:33 +05:30
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)
2019-09-30 23:59:55 +05:30
2020-04-08 14:13:33 +05:30
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) { get group_milestones_path(public_group, format: :json) }.count
2019-09-30 23:59:55 +05:30
2020-04-08 14:13:33 +05:30
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)
2022-08-27 11:52:29 +05:30
expect(milestones.map { |x| x['title'] }).not_to include(private_milestone.title)
2019-09-30 23:59:55 +05:30
end
2020-04-08 14:13:33 +05:30
end
2019-09-30 23:59:55 +05:30
2020-04-08 14:13:33 +05:30
describe 'GET #show' do
let(:milestone) { create(:milestone, group: public_group) }
let(:show_path) { group_milestone_path(public_group, milestone) }
2019-09-30 23:59:55 +05:30
2020-04-08 14:13:33 +05:30
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
2019-09-30 23:59:55 +05:30
end
2021-04-29 21:17:54 +05:30
describe 'GET #merge_requests' do
let(:milestone) { create(:milestone, group: public_group) }
let(:project) { create(:project, :public, :merge_requests_enabled, :issues_enabled, group: public_group) }
let!(:merge_request) { create(:merge_request, milestone: milestone, source_project: project) }
def perform_request
get merge_requests_group_milestone_path(public_group, milestone, format: :json)
end
it 'avoids N+1 database queries' do
perform_request # warm up the cache
control_count = ActiveRecord::QueryRecorder.new { perform_request }.count
create(:merge_request, milestone: milestone, source_project: project, source_branch: 'fix')
expect { perform_request }.not_to exceed_query_limit(control_count)
end
end
2019-09-30 23:59:55 +05:30
end
end