diff options
author | Toon Claes <toon@gitlab.com> | 2017-01-21 00:41:03 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-01-23 17:52:53 +0300 |
commit | 0d2c68d546cb58760a9d30a41b1454b02c462ad8 (patch) | |
tree | e29f5fc0f454ef555df9b5be5a4baa8cfced553d /spec/features/projects/merge_request_button_spec.rb | |
parent | 7ce39486b54a375eb13a11deb1835d6fcf218a4a (diff) |
Deduplicate tests for Merge Request buttons
Use shared examples to test the presence of the Merge Request button
on the various pages.
Diffstat (limited to 'spec/features/projects/merge_request_button_spec.rb')
-rw-r--r-- | spec/features/projects/merge_request_button_spec.rb | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/spec/features/projects/merge_request_button_spec.rb b/spec/features/projects/merge_request_button_spec.rb new file mode 100644 index 00000000000..177038f9a4c --- /dev/null +++ b/spec/features/projects/merge_request_button_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +feature 'Merge Request button', feature: true do + shared_examples 'Merge Request button only shown when allowed' do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:forked_project) { create(:project, forked_from_project: project) } + + context 'not logged in' do + it 'does not show Create Merge Request button' do + visit url + + expect(page).not_to have_link(label) + 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 + + expect(page).to have_link(label, href: href) + end + 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 + + expect(page).not_to have_link(label) + 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 + + expect(page).to have_link(label, href: href) + 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 |