BigW Consortium Gitlab

merge_when_build_succeeds_spec.rb 2.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
require 'spec_helper'

feature 'Merge When Build Succeeds', feature: true, js: true do
  let(:user) { create(:user) }

  let(:project)       { create(:project, :public) }
  let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user, title: "Bug NS-04") }

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

  context "Active build for Merge Request" do
15
    let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
16
    let!(:ci_build) { create(:ci_build, pipeline: ci_commit) }
17

18
    before do
19 20 21 22 23
      login_as user
      visit_merge_request(merge_request)
    end

    it 'displays the Merge When Build Succeeds button' do
24
      expect(page).to have_button "Merge When Build Succeeds"
25 26 27 28
    end

    context "Merge When Build succeeds enabled" do
      before do
29
        click_button "Merge When Build Succeeds"
30 31 32 33 34
      end

      it 'activates Merge When Build Succeeds feature' do
        expect(page).to have_link "Cancel Automatic Merge"

35
        expect(page).to have_content "Set by #{user.name} to be merged automatically when the build succeeds."
36
        expect(page).to have_content "The source branch will not be removed."
37 38 39

        visit_merge_request(merge_request) # Needed to refresh the page
        expect(page).to have_content /Enabled an automatic merge when the build for [0-9a-f]{8} succeeds/i
40 41 42 43 44
      end
    end
  end

  context 'When it is enabled' do
45
    let(:merge_request) do
Douwe Maan committed
46 47
      create(:merge_request_with_diffs, :simple,  source_project: project, author: user,
                                                  merge_user: user, title: "MepMep", merge_when_build_succeeds: true)
48
    end
49

50 51
    let!(:pipeline) { create(:ci_pipeline, project: project, sha: merge_request.last_commit.id, ref: merge_request.source_branch) }
    let!(:ci_build) { create(:ci_build, pipeline: pipeline) }
52

53 54 55 56 57 58 59 60
    before do
      login_as user
      visit_merge_request(merge_request)
    end

    it 'cancels the automatic merge' do
      click_link "Cancel Automatic Merge"

61
      expect(page).to have_button "Merge When Build Succeeds"
62 63

      visit_merge_request(merge_request) # Needed to refresh the page
Zeger-Jan van de Weg committed
64
      expect(page).to have_content "Canceled the automatic merge"
65 66 67 68
    end

    it "allows the user to remove the source branch" do
      expect(page).to have_link "Remove Source Branch When Merged"
69 70 71

      click_link "Remove Source Branch When Merged"
      expect(page).to have_content "The source branch will be removed"
72 73 74 75 76 77
    end
  end

  context 'Build is not active' do
    it "should not allow for enabling" do
      visit_merge_request(merge_request)
Zeger-Jan van de Weg committed
78
      expect(page).not_to have_link "Merge When Build Succeeds"
79 80 81 82 83 84 85
    end
  end

  def visit_merge_request(merge_request)
    visit namespace_project_merge_request_path(merge_request.project.namespace, merge_request.project, merge_request)
  end
end