merge_request_button_spec.rb 3.55 KB
Newer Older
1 2 3
require 'spec_helper'

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

    context 'not logged in' do
10
      it 'does not show Create merge request button' do
11 12
        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
      end
    end

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

25
      it 'shows Create merge request button' do
26 27 28 29 30 31 32
        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

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

43
        it 'does not show Create merge request button' do
44 45 46 47 48 49 50
          visit url

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

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

58
      it 'does not show Create merge request button' do
59 60
        visit url

61 62 63
        within("#content-body") do
          expect(page).not_to have_link(label)
        end
64 65 66 67 68
      end

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

69
        it 'shows Create merge request button' do
70 71 72 73 74 75 76
          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
        end
      end
    end
  end

  context 'on branches page' do
86 87
    it_behaves_like 'Merge request button only shown when allowed' do
      let(:label) { 'Merge request' }
Sam Rose's avatar
Sam Rose committed
88 89
      let(:url) { namespace_project_branches_path(project.namespace, project, search: 'feature') }
      let(:fork_url) { namespace_project_branches_path(forked_project.namespace, forked_project, search: 'feature') }
90 91 92 93
    end
  end

  context 'on compare page' do
94 95
    it_behaves_like 'Merge request button only shown when allowed' do
      let(:label) { 'Create merge request' }
96 97 98 99 100 101
      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
102 103
    it_behaves_like 'Merge request button only shown when allowed' do
      let(:label) { 'Create merge request' }
104 105 106 107 108
      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