BigW Consortium Gitlab

created_from_fork_spec.rb 2.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
require 'spec_helper'

feature 'Merge request created from fork' do
  given(:user) { create(:user) }
  given(:project) { create(:project, :public) }
  given(:fork_project) { create(:project, :public) }

  given!(:merge_request) do
    create(:forked_project_link, forked_to_project: fork_project,
                                 forked_from_project: project)

12 13 14
    create(:merge_request_with_diffs, source_project: fork_project,
                                      target_project: project,
                                      description: 'Test merge request')
15 16
  end

17 18
  background do
    fork_project.team << [user, :master]
19 20 21 22
    login_as user
  end

  scenario 'user can access merge request' do
23 24
    visit_merge_request(merge_request)

25 26
    expect(page).to have_content 'Test merge request'
  end
27 28 29 30 31 32 33 34 35 36 37 38 39 40

  context 'source project is deleted' do
    background do
      MergeRequests::MergeService.new(project, user).execute(merge_request)
      fork_project.destroy!
    end

    scenario 'user can access merge request' do
      visit_merge_request(merge_request)

      expect(page).to have_content 'Test merge request'
      expect(page).to have_content "(removed):#{merge_request.source_branch}"
    end
  end
41 42 43

  context 'pipeline present in source project' do
    given(:pipeline) do
44 45 46 47
      create(:ci_pipeline,
             project: fork_project,
             sha: merge_request.diff_head_sha,
             ref: merge_request.source_branch)
48 49
    end

50 51 52 53
    background do
      create(:ci_build, pipeline: pipeline, name: 'rspec')
      create(:ci_build, pipeline: pipeline, name: 'spinach')
    end
54 55 56 57 58

    scenario 'user visits a pipelines page', js: true do
      visit_merge_request(merge_request)
      page.within('.merge-request-tabs') { click_link 'Builds' }

59
      page.within('table.ci-table') do
60 61 62 63 64 65 66 67 68 69 70 71 72
        expect(page).to have_content 'rspec'
        expect(page).to have_content 'spinach'
      end

      expect(find_link('Cancel running')[:href])
        .to include fork_project.path_with_namespace
    end
  end

  def visit_merge_request(mr)
    visit namespace_project_merge_request_path(project.namespace,
                                               project, mr)
  end
73
end