milestones_controller_spec.rb 3 KB
Newer Older
1 2 3
require 'spec_helper'

describe Dashboard::MilestonesController do
4
  let(:project) { create(:project) }
5 6
  let(:group) { create(:group) }
  let(:user) { create(:user) }
7
  let(:project_milestone) { create(:milestone, project: project) }
8
  let(:group_milestone) { create(:milestone, group: group) }
9 10 11 12 13 14 15
  let(:milestone) do
    DashboardMilestone.build(
      [project],
      project_milestone.title
    )
  end
  let(:issue) { create(:issue, project: project, milestone: project_milestone) }
16
  let(:group_issue) { create(:issue, milestone: group_milestone, project: create(:project, group: group)) }
17

18
  let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
19
  let!(:group_label) { create(:group_label, group: group, title: 'Group Issue Label', issues: [group_issue]) }
20 21 22 23 24
  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)
25
    project.add_maintainer(user)
26
    group.add_developer(user)
27 28 29 30 31 32 33 34
  end

  it_behaves_like 'milestone tabs'

  describe "#show" do
    render_views

    def view_milestone
blackst0ne's avatar
blackst0ne committed
35
      get :show, params: { id: milestone.safe_title, title: milestone.title }
36 37 38 39 40
    end

    it 'shows milestone page' do
      view_milestone

41
      expect(response).to have_gitlab_http_status(200)
42 43
    end
  end
44 45

  describe "#index" do
46 47 48
    let(:public_group) { create(:group, :public) }
    let!(:public_milestone) { create(:milestone, group: public_group) }

Eagllus's avatar
Eagllus committed
49 50
    render_views

51
    it 'returns group and project milestones to which the user belongs' do
52 53 54 55
      get :index, format: :json

      expect(response).to have_gitlab_http_status(200)
      expect(json_response.size).to eq(2)
56
      expect(json_response.map { |i| i["name"] }).to match_array([group_milestone.name, project_milestone.name])
57
      expect(json_response.map { |i| i["group_name"] }.compact).to match_array(group.name)
58
    end
Eagllus's avatar
Eagllus committed
59

Jacopo's avatar
Jacopo committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    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

78
    it 'should show counts of group and project milestones to which the user belongs to' do
Eagllus's avatar
Eagllus committed
79 80
      get :index

81
      expect(response.body).to include("Open\n<span class=\"badge badge-pill\">2</span>")
Eagllus's avatar
Eagllus committed
82 83
      expect(response.body).to include("Closed\n<span class=\"badge badge-pill\">0</span>")
    end
84
  end
85
end