BigW Consortium Gitlab

merge_request_button_spec.rb 3.52 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

feature 'Merge Request button', feature: true do
  shared_examples 'Merge Request button only shown when allowed' do
    let(:user) { create(:user) }
6 7
    let(:project) { create(:project, :public) }
    let(:forked_project) { create(:project, :public, forked_from_project: project) }
8 9 10 11 12

    context 'not logged in' do
      it 'does not show Create Merge Request button' do
        visit url

13 14 15
        within("#content-body") do
          expect(page).not_to have_link(label)
        end
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
      end
    end

    context 'logged in as developer' do
      before do
        login_as(user)
        project.team << [user, :developer]
      end

      it 'shows Create Merge Request button' do
        href = new_namespace_project_merge_request_path(project.namespace,
                                                        project,
                                                        merge_request: { source_branch: 'feature',
                                                                         target_branch: 'master' })

        visit url

33 34 35
        within("#content-body") do
          expect(page).to have_link(label, href: href)
        end
36
      end
37 38 39 40 41 42 43 44 45 46 47 48 49 50

      context 'merge requests are disabled' do
        before do
          project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
        end

        it 'does not show Create Merge Request button' do
          visit url

          within("#content-body") do
            expect(page).not_to have_link(label)
          end
        end
      end
51 52 53 54 55 56 57 58 59 60
    end

    context 'logged in as non-member' do
      before do
        login_as(user)
      end

      it 'does not show Create Merge Request button' do
        visit url

61 62 63
        within("#content-body") do
          expect(page).not_to have_link(label)
        end
64 65 66 67 68 69 70 71 72 73 74 75 76
      end

      context 'on own fork of project' do
        let(:user) { forked_project.owner }

        it 'shows Create Merge Request button' do
          href = new_namespace_project_merge_request_path(forked_project.namespace,
                                                          forked_project,
                                                          merge_request: { source_branch: 'feature',
                                                                           target_branch: 'master' })

          visit fork_url

77 78 79
          within("#content-body") do
            expect(page).to have_link(label, href: href)
          end
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        end
      end
    end
  end

  context 'on branches page' do
    it_behaves_like 'Merge Request button only shown when allowed' do
      let(:label) { 'Merge Request' }
      let(:url) { namespace_project_branches_path(project.namespace, project) }
      let(:fork_url) { namespace_project_branches_path(forked_project.namespace, forked_project) }
    end
  end

  context 'on compare page' do
    it_behaves_like 'Merge Request button only shown when allowed' do
      let(:label) { 'Create Merge Request' }
      let(:url) { namespace_project_compare_path(project.namespace, project, from: 'master', to: 'feature') }
      let(:fork_url) { namespace_project_compare_path(forked_project.namespace, forked_project, from: 'master', to: 'feature') }
    end
  end

  context 'on commits page' do
    it_behaves_like 'Merge Request button only shown when allowed' do
      let(:label) { 'Create Merge Request' }
      let(:url) { namespace_project_commits_path(project.namespace, project, 'feature') }
      let(:fork_url) { namespace_project_commits_path(forked_project.namespace, forked_project, 'feature') }
    end
  end
end