closes_issues_spec.rb 3.7 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Merge Request closing issues message', feature: true, js: true do
4 5 6 7 8 9 10 11 12
  let(:user) { create(:user) }
  let(:project) { create(:project, :public) }
  let(:issue_1) { create(:issue, project: project)}
  let(:issue_2) { create(:issue, project: project)}
  let(:merge_request) do
    create(
      :merge_request,
      :simple,
      source_project: project,
13 14
      description: merge_request_description,
      title: merge_request_title
15 16 17
    )
  end
  let(:merge_request_description) { 'Merge Request Description' }
18
  let(:merge_request_title) { 'Merge Request Title' }
19 20 21 22

  before do
    project.team << [user, :master]

23
    gitlab_sign_in user
24 25

    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
26
    wait_for_requests
27 28 29 30 31 32 33 34 35 36 37 38
  end

  context 'not closing or mentioning any issue' do
    it 'does not display closing issue message' do
      expect(page).not_to have_css('.mr-widget-footer')
    end
  end

  context 'closing issues but not mentioning any other issue' do
    let(:merge_request_description) { "Description\n\nclosing #{issue_1.to_reference}, #{issue_2.to_reference}" }

    it 'does not display closing issue message' do
39
      expect(page).to have_content("Closed issues #{issue_1.to_reference} and #{issue_2.to_reference}")
40 41 42 43 44 45 46
    end
  end

  context 'mentioning issues but not closing them' do
    let(:merge_request_description) { "Description\n\nRefers to #{issue_1.to_reference} and #{issue_2.to_reference}" }

    it 'does not display closing issue message' do
47
      expect(page).to have_content("Issues #{issue_1.to_reference} and #{issue_2.to_reference} are mentioned but were not closed")
48 49 50
    end
  end

51 52 53 54
  context 'closing some issues in title and mentioning, but not closing, others' do
    let(:merge_request_title) { "closes #{issue_1.to_reference}\n\n refers to #{issue_2.to_reference}" }

    it 'does not display closing issue message' do
55 56
      expect(page).to have_content("Closed issue #{issue_1.to_reference}")
      expect(page).to have_content("Issue #{issue_2.to_reference} is mentioned but was not closed")
57 58 59 60 61 62 63
    end
  end

  context 'closing issues using title but not mentioning any other issue' do
    let(:merge_request_title) { "closing #{issue_1.to_reference}, #{issue_2.to_reference}" }

    it 'does not display closing issue message' do
64
      expect(page).to have_content("Closed issues #{issue_1.to_reference} and #{issue_2.to_reference}")
65 66 67 68 69 70 71
    end
  end

  context 'mentioning issues using title but not closing them' do
    let(:merge_request_title) { "Refers to #{issue_1.to_reference} and #{issue_2.to_reference}" }

    it 'does not display closing issue message' do
72
      expect(page).to have_content("Issues #{issue_1.to_reference} and #{issue_2.to_reference} are mentioned but were not closed")
73 74 75 76 77
    end
  end

  context 'closing some issues using title and mentioning, but not closing, others' do
    let(:merge_request_title) { "closes #{issue_1.to_reference}\n\n refers to #{issue_2.to_reference}" }
78 79

    it 'does not display closing issue message' do
80 81
      expect(page).to have_content("Closed issue #{issue_1.to_reference}")
      expect(page).to have_content("Issue #{issue_2.to_reference} is mentioned but was not closed")
82 83
    end
  end
84 85 86 87 88 89 90 91 92 93

  context 'approvals are enabled while closing issues', js: true do
    before do
      project.team << [user, :developer]
    end

    let(:project) { create(:project, :public, approvals_before_merge: 1) }
    let(:merge_request_description) { "Description\n\nclosing #{issue_1.to_reference}, #{issue_2.to_reference}" }

    it 'displays closing issue message exactly one time' do
94
      wait_for_requests
95
      expect(page).to have_content("Closes issues #{issue_1.to_reference} and #{issue_2.to_reference}", count: 1)
96 97
    end
  end
98
end