summaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2018-05-02 12:56:42 -0700
committerMichael Kozono <mkozono@gmail.com>2018-06-08 09:05:06 -0700
commit289a6100ff4f5c9cbcfbb0f1d2719e15b9f49018 (patch)
tree19294340bcf76fee7b4f03a0b2e72e0ab2f44b55 /qa
parentb8a031e54a46735d93ac932a25835a8bdfd9824d (diff)
downloadgitlab-ce-289a6100ff4f5c9cbcfbb0f1d2719e15b9f49018.tar.gz
Dry up tests
Diffstat (limited to 'qa')
-rw-r--r--qa/qa/specs/features/repository/protected_branches_spec.rb78
1 files changed, 35 insertions, 43 deletions
diff --git a/qa/qa/specs/features/repository/protected_branches_spec.rb b/qa/qa/specs/features/repository/protected_branches_spec.rb
index 40c810605ba..fcec987ec69 100644
--- a/qa/qa/specs/features/repository/protected_branches_spec.rb
+++ b/qa/qa/specs/features/repository/protected_branches_spec.rb
@@ -27,69 +27,61 @@ module QA
end
scenario 'user is able to protect a branch' do
- protected_branch = Factory::Resource::Branch.fabricate! do |resource|
- resource.branch_name = branch_name
- resource.project = project
- resource.allow_to_push = true
- resource.protected = true
- end
+ protected_branch = fabricate_branch(allow_to_push: true)
expect(protected_branch.name).to have_content(branch_name)
expect(protected_branch.push_allowance).to have_content('Developers + Maintainers')
end
- scenario 'users without authorization cannot push to protected branch' do
- Factory::Resource::Branch.fabricate! do |resource|
- resource.branch_name = branch_name
- resource.project = project
- resource.allow_to_push = false
- resource.protected = true
- end
+ context 'push to protected branch' do
+ scenario 'unauthorized users are blocked' do
+ fabricate_branch(allow_to_push: false)
- project.visit!
+ project.visit!
- Git::Repository.perform do |repository|
- repository.uri = location.uri
- repository.use_default_credentials
+ Git::Repository.perform do |repository|
+ push_output = push_to_repository(repository)
- repository.act do
- clone
- configure_identity('GitLab QA', 'root@gitlab.com')
- checkout('protected-branch')
- commit_file('README.md', 'readme content', 'Add a readme')
- push_changes('protected-branch')
+ 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
+
+ scenario 'authorized users are allowed' do
+ fabricate_branch(allow_to_push: true)
+
+ project.visit!
- expect(repository.push_output)
- .to match(/remote\: GitLab\: You are not allowed to push code to protected branches on this project/)
- expect(repository.push_output)
- .to match(/\[remote rejected\] #{branch_name} -> #{branch_name} \(pre-receive hook declined\)/)
+ Git::Repository.perform do |repository|
+ push_output = push_to_repository(repository)
+
+ expect(push_output).to match(/remote: To create a merge request for protected-branch, visit/)
+ end
end
end
- scenario 'users with authorization can push to protected branch' do
+ def fabricate_branch(allow_to_push:)
Factory::Resource::Branch.fabricate! do |resource|
resource.branch_name = branch_name
resource.project = project
- resource.allow_to_push = true
+ resource.allow_to_push = allow_to_push
resource.protected = true
end
+ end
- project.visit!
-
- Git::Repository.perform do |repository|
- repository.uri = location.uri
- repository.use_default_credentials
-
- repository.act do
- clone
- configure_identity('GitLab QA', 'root@gitlab.com')
- checkout('protected-branch')
- commit_file('README.md', 'readme content', 'Add a readme')
- push_changes('protected-branch')
- end
+ def push_to_repository(repository)
+ repository.uri = location.uri
+ repository.use_default_credentials
- expect(repository.push_output).to match(/remote: To create a merge request for protected-branch, visit/)
+ repository.act do
+ clone
+ configure_identity('GitLab QA', 'root@gitlab.com')
+ checkout('protected-branch')
+ commit_file('README.md', 'readme content', 'Add a readme')
+ push_changes('protected-branch')
+ push_output
end
end
end