debian-mirror-gitlab/spec/controllers/dashboard/milestones_controller_spec.rb

86 lines
3 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
require 'spec_helper'
describe Dashboard::MilestonesController do
let(:project) { create(:project) }
2018-11-18 11:00:15 +05:30
let(:group) { create(:group) }
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project_milestone) { create(:milestone, project: project) }
2018-11-18 11:00:15 +05:30
let(:group_milestone) { create(:milestone, group: group) }
2017-09-10 17:25:29 +05:30
let(:milestone) do
DashboardMilestone.build(
[project],
project_milestone.title
)
end
let(:issue) { create(:issue, project: project, milestone: project_milestone) }
2019-03-13 22:55:13 +05:30
let(:group_issue) { create(:issue, milestone: group_milestone, project: create(:project, group: group)) }
2018-11-18 11:00:15 +05:30
2017-09-10 17:25:29 +05:30
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
2018-11-18 11:00:15 +05:30
let!(:group_label) { create(:group_label, group: group, title: 'Group Issue Label', issues: [group_issue]) }
2017-09-10 17:25:29 +05:30
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: project_milestone) }
let(:milestone_path) { dashboard_milestone_path(milestone.safe_title, title: milestone.title) }
before do
sign_in(user)
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
group.add_developer(user)
2017-09-10 17:25:29 +05:30
end
it_behaves_like 'milestone tabs'
describe "#show" do
render_views
def view_milestone
2019-02-15 15:39:39 +05:30
get :show, params: { id: milestone.safe_title, title: milestone.title }
2017-09-10 17:25:29 +05:30
end
it 'shows milestone page' do
view_milestone
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-09-10 17:25:29 +05:30
end
end
2018-11-18 11:00:15 +05:30
describe "#index" do
2019-03-02 22:35:43 +05:30
let(:public_group) { create(:group, :public) }
let!(:public_milestone) { create(:milestone, group: public_group) }
2018-12-13 13:39:08 +05:30
render_views
2018-12-05 23:21:45 +05:30
it 'returns group and project milestones to which the user belongs' do
2018-11-18 11:00:15 +05:30
get :index, format: :json
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(2)
2019-02-15 15:39:39 +05:30
expect(json_response.map { |i| i["name"] }).to match_array([group_milestone.name, project_milestone.name])
2018-12-05 23:21:45 +05:30
expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name)
2018-11-18 11:00:15 +05:30
end
2018-12-13 13:39:08 +05:30
2019-03-02 22:35:43 +05:30
it 'searches legacy project milestones by title when search_title is given' do
project_milestone = create(:milestone, title: 'Project milestone title', project: project)
get :index, params: { search_title: 'Project mil' }
expect(response.body).to include(project_milestone.title)
expect(response.body).not_to include(group_milestone.title)
end
it 'searches group milestones by title when search_title is given' do
group_milestone = create(:milestone, title: 'Group milestone title', group: group)
get :index, params: { search_title: 'Group mil' }
expect(response.body).to include(group_milestone.title)
expect(response.body).not_to include(project_milestone.title)
end
it 'should show counts of group and project milestones to which the user belongs to' do
2018-12-13 13:39:08 +05:30
get :index
2019-03-02 22:35:43 +05:30
expect(response.body).to include("Open\n<span class=\"badge badge-pill\">2</span>")
2018-12-13 13:39:08 +05:30
expect(response.body).to include("Closed\n<span class=\"badge badge-pill\">0</span>")
end
2018-11-18 11:00:15 +05:30
end
2017-09-10 17:25:29 +05:30
end