summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Lapierre <mlapierre@gitlab.com>2019-09-05 16:13:22 +1000
committerMark Lapierre <mlapierre@gitlab.com>2019-09-11 11:48:14 +1000
commit5c261439e2cbc77c7bc1ce368e52bd60188d5c55 (patch)
tree8549375b833016c0f5f0dbb58b71317ebea46bc6
parentc0b9e50af9ecdbaf6cd8bb0dbcf23388c3c388e4 (diff)
downloadgitlab-ce-qa-ml-refactor-protected-branch-test.tar.gz
Refactor protected branch resource and specqa-ml-refactor-protected-branch-test
Rename Resource::Branch to Resource::ProtectedBranch to be clear that it configures the settings to protect a branch, rather than just creating a new branch. Make branch an attribute to make it clear creating the branch is not the main responsibility of the class. Initialize the project with a readme so that the resource only has to push once when it creates a branch. Stop ProjectPush from visiting the project page so that it doesn't have to use the browser UI.
-rw-r--r--qa/qa.rb2
-rw-r--r--qa/qa/resource/protected_branch.rb (renamed from qa/qa/resource/branch.rb)41
-rw-r--r--qa/qa/resource/repository/project_push.rb1
-rw-r--r--qa/qa/specs/features/browser_ui/3_create/repository/push_protected_branch_spec.rb3
-rw-r--r--qa/qa/specs/features/browser_ui/4_verify/pipeline/create_and_process_pipeline_spec.rb2
5 files changed, 22 insertions, 27 deletions
diff --git a/qa/qa.rb b/qa/qa.rb
index 9bf28d396ba..b38c39a621f 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -54,7 +54,7 @@ module QA
autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork'
autoload :DeployKey, 'qa/resource/deploy_key'
autoload :DeployToken, 'qa/resource/deploy_token'
- autoload :Branch, 'qa/resource/branch'
+ autoload :ProtectedBranch, 'qa/resource/protected_branch'
autoload :CiVariable, 'qa/resource/ci_variable'
autoload :Runner, 'qa/resource/runner'
autoload :PersonalAccessToken, 'qa/resource/personal_access_token'
diff --git a/qa/qa/resource/branch.rb b/qa/qa/resource/protected_branch.rb
index 6dc47e36977..c27647cf3ce 100644
--- a/qa/qa/resource/branch.rb
+++ b/qa/qa/resource/protected_branch.rb
@@ -2,13 +2,24 @@
module QA
module Resource
- class Branch < Base
- attr_accessor :project, :branch_name,
- :allow_to_push, :allow_to_merge, :protected
+ class ProtectedBranch < Base
+ attr_accessor :branch_name, :allow_to_push, :allow_to_merge, :protected
attribute :project do
- Project.fabricate! do |resource|
+ Project.fabricate_via_api! do |resource|
resource.name = 'protected-branch-project'
+ resource.initialize_with_readme = true
+ end
+ end
+
+ attribute :branch do
+ Repository::ProjectPush.fabricate! do |project_push|
+ project_push.project = project
+ project_push.file_name = 'new_file.md'
+ project_push.commit_message = 'Add new file'
+ project_push.branch_name = branch_name
+ project_push.new_branch = true
+ project_push.remote_branch = @branch_name
end
end
@@ -20,32 +31,16 @@ module QA
end
def fabricate!
- project.visit!
-
- Repository::ProjectPush.fabricate! do |resource|
- resource.project = project
- resource.file_name = 'kick-off.txt'
- resource.commit_message = 'First commit'
- end
+ populate(:branch)
- branch = Repository::ProjectPush.fabricate! do |resource|
- resource.project = project
- resource.file_name = 'README.md'
- resource.commit_message = 'Add readme'
- resource.branch_name = 'master'
- resource.new_branch = false
- resource.remote_branch = @branch_name
- end
-
- Page::Project::Show.perform do |page|
- page.wait { page.has_content?(branch_name) }
- end
+ project.wait_for_push_new_branch @branch_name
# The upcoming process will make it access the Protected Branches page,
# select the already created branch and protect it according
# to `allow_to_push` variable.
return branch unless @protected
+ project.visit!
Page::Project::Menu.perform(&:go_to_repository_settings)
Page::Project::Settings::Repository.perform do |setting|
diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb
index e98880ce195..c84ade3a140 100644
--- a/qa/qa/resource/repository/project_push.rb
+++ b/qa/qa/resource/repository/project_push.rb
@@ -33,7 +33,6 @@ module QA
def fabricate!
super
project.wait_for_push @commit_message if @wait_for_push
- project.visit!
end
end
end
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
index e159e517cbb..dd80905d184 100644
--- 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
@@ -8,6 +8,7 @@ module QA
let(:project) do
Resource::Project.fabricate! do |resource|
resource.name = 'protected-branch-project'
+ resource.initialize_with_readme = true
end
end
@@ -42,7 +43,7 @@ module QA
end
def create_protected_branch(allow_to_push:)
- Resource::Branch.fabricate! do |resource|
+ Resource::ProtectedBranch.fabricate! do |resource|
resource.branch_name = branch_name
resource.project = project
resource.allow_to_push = allow_to_push
diff --git a/qa/qa/specs/features/browser_ui/4_verify/pipeline/create_and_process_pipeline_spec.rb b/qa/qa/specs/features/browser_ui/4_verify/pipeline/create_and_process_pipeline_spec.rb
index 7c1d4489c47..2952a54ff5d 100644
--- a/qa/qa/specs/features/browser_ui/4_verify/pipeline/create_and_process_pipeline_spec.rb
+++ b/qa/qa/specs/features/browser_ui/4_verify/pipeline/create_and_process_pipeline_spec.rb
@@ -58,7 +58,7 @@ module QA
paths:
- my-artifacts/
EOF
- end
+ end.project.visit!
expect(page).to have_content('Add .gitlab-ci.yml')