diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-29 22:54:12 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-29 22:54:12 -0700 |
commit | 69eddc14b11b63429b8f2511a1127616c692b94c (patch) | |
tree | a94482be144cef60a8ee1b590857ca24f49f418a /qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb | |
parent | bc7a4eedf9fa6681465b622af52c34d49ffb5d0e (diff) | |
parent | f981d4febbbb5103262f4daa858236d9c4ed9d67 (diff) | |
download | gitlab-ce-69eddc14b11b63429b8f2511a1127616c692b94c.tar.gz |
Merge branch 'master' into sh-test-ldap-clones-via-gitlab-qa
Diffstat (limited to 'qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb')
-rw-r--r-- | qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb new file mode 100644 index 00000000000..b2da685c477 --- /dev/null +++ b/qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +module QA + context :create do + describe 'Protected branch support', :ldap do + let(:branch_name) { 'protected-branch' } + let(:commit_message) { 'Protected push commit message' } + let(:project) do + Factory::Resource::Project.fabricate! do |resource| + resource.name = 'protected-branch-project' + end + end + + before do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + end + + after do + # We need to clear localStorage because we're using it for the dropdown, + # and capybara doesn't do this for us. + # https://github.com/teamcapybara/capybara/issues/1702 + Capybara.execute_script 'localStorage.clear()' + end + + context 'when developers and maintainers are allowed to push to a protected branch' do + it 'user with push rights successfully pushes to the protected branch' do + create_protected_branch(allow_to_push: true) + + push = push_new_file(branch_name) + + expect(push.output).to match(/remote: To create a merge request for protected-branch, visit/) + end + end + + context 'when developers and maintainers are not allowed to push to a protected branch' do + it 'user without push rights fails to push to the protected branch' do + create_protected_branch(allow_to_push: false) + + push = push_new_file(branch_name) + + expect(push.output) + .to match(/remote\: GitLab\: You are not allowed to push code to protected branches on this project/) + expect(push.output) + .to match(/\[remote rejected\] #{branch_name} -> #{branch_name} \(pre-receive hook declined\)/) + end + end + + def create_protected_branch(allow_to_push:) + Factory::Resource::Branch.fabricate! do |resource| + resource.branch_name = branch_name + resource.project = project + resource.allow_to_push = allow_to_push + resource.protected = true + end + end + + def push_new_file(branch) + Factory::Repository::ProjectPush.fabricate! do |resource| + resource.project = project + resource.file_name = 'new_file.md' + resource.file_content = '# This is a new file' + resource.commit_message = 'Add new_file.md' + resource.branch_name = branch_name + resource.new_branch = false + end + end + end + end +end |