Commit 95bf6a28 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-ml-refactor-protected-branch-test' into 'master'

Refactor protected branch resource and spec

See merge request gitlab-org/gitlab-ee!16310
parents 940a9500 90e7d6c1
...@@ -54,7 +54,7 @@ module QA ...@@ -54,7 +54,7 @@ module QA
autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork' autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork'
autoload :DeployKey, 'qa/resource/deploy_key' autoload :DeployKey, 'qa/resource/deploy_key'
autoload :DeployToken, 'qa/resource/deploy_token' autoload :DeployToken, 'qa/resource/deploy_token'
autoload :Branch, 'qa/resource/branch' autoload :ProtectedBranch, 'qa/resource/protected_branch'
autoload :CiVariable, 'qa/resource/ci_variable' autoload :CiVariable, 'qa/resource/ci_variable'
autoload :Runner, 'qa/resource/runner' autoload :Runner, 'qa/resource/runner'
autoload :PersonalAccessToken, 'qa/resource/personal_access_token' autoload :PersonalAccessToken, 'qa/resource/personal_access_token'
......
...@@ -2,13 +2,24 @@ ...@@ -2,13 +2,24 @@
module QA module QA
module Resource module Resource
class Branch < Base class ProtectedBranch < Base
attr_accessor :project, :branch_name, attr_accessor :branch_name, :allow_to_push, :allow_to_merge, :protected
:allow_to_push, :allow_to_merge, :protected
attribute :project do attribute :project do
Project.fabricate! do |resource| Project.fabricate_via_api! do |resource|
resource.name = 'protected-branch-project' 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
end end
...@@ -20,32 +31,16 @@ module QA ...@@ -20,32 +31,16 @@ module QA
end end
def fabricate! def fabricate!
project.visit! populate(:branch)
Repository::ProjectPush.fabricate! do |resource|
resource.project = project
resource.file_name = 'kick-off.txt'
resource.commit_message = 'First commit'
end
branch = Repository::ProjectPush.fabricate! do |resource| project.wait_for_push_new_branch @branch_name
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
# The upcoming process will make it access the Protected Branches page, # The upcoming process will make it access the Protected Branches page,
# select the already created branch and protect it according # select the already created branch and protect it according
# to `allow_to_push` variable. # to `allow_to_push` variable.
return branch unless @protected return branch unless @protected
project.visit!
Page::Project::Menu.perform(&:go_to_repository_settings) Page::Project::Menu.perform(&:go_to_repository_settings)
Page::Project::Settings::Repository.perform do |setting| Page::Project::Settings::Repository.perform do |setting|
......
...@@ -33,7 +33,6 @@ module QA ...@@ -33,7 +33,6 @@ module QA
def fabricate! def fabricate!
super super
project.wait_for_push @commit_message if @wait_for_push project.wait_for_push @commit_message if @wait_for_push
project.visit!
end end
end end
end end
......
...@@ -8,6 +8,7 @@ module QA ...@@ -8,6 +8,7 @@ module QA
let(:project) do let(:project) do
Resource::Project.fabricate! do |resource| Resource::Project.fabricate! do |resource|
resource.name = 'protected-branch-project' resource.name = 'protected-branch-project'
resource.initialize_with_readme = true
end end
end end
...@@ -42,7 +43,7 @@ module QA ...@@ -42,7 +43,7 @@ module QA
end end
def create_protected_branch(allow_to_push:) def create_protected_branch(allow_to_push:)
Resource::Branch.fabricate! do |resource| Resource::ProtectedBranch.fabricate! do |resource|
resource.branch_name = branch_name resource.branch_name = branch_name
resource.project = project resource.project = project
resource.allow_to_push = allow_to_push resource.allow_to_push = allow_to_push
......
...@@ -58,7 +58,7 @@ module QA ...@@ -58,7 +58,7 @@ module QA
paths: paths:
- my-artifacts/ - my-artifacts/
EOF EOF
end end.project.visit!
expect(page).to have_content('Add .gitlab-ci.yml') expect(page).to have_content('Add .gitlab-ci.yml')
......
...@@ -23,7 +23,7 @@ module QA ...@@ -23,7 +23,7 @@ module QA
push.project = @project push.project = @project
push.file_name = @project_file_name push.file_name = @project_file_name
push.file_content = @project_file_content push.file_content = @project_file_content
end end.project.visit!
end end
it 'tests reindexing after push' do it 'tests reindexing after push' do
......
...@@ -23,7 +23,7 @@ module QA ...@@ -23,7 +23,7 @@ module QA
add_to_project user: @user_one add_to_project user: @user_one
add_to_project user: @user_two add_to_project user: @user_two
Resource::Branch.unprotect_via_api! do |branch| Resource::ProtectedBranch.unprotect_via_api! do |branch|
branch.project = @project branch.project = @project
branch.branch_name = 'master' branch.branch_name = 'master'
end end
......
...@@ -34,7 +34,7 @@ module QA ...@@ -34,7 +34,7 @@ module QA
push.file_name = file_name push.file_name = file_name
push.file_content = "# #{file_content}" push.file_content = "# #{file_content}"
push.commit_message = 'Add README.md' push.commit_message = 'Add README.md'
end end.project.visit!
# Validate git push worked and file exists with content # Validate git push worked and file exists with content
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
...@@ -99,6 +99,7 @@ module QA ...@@ -99,6 +99,7 @@ module QA
expect(push.output).to match(/Locking support detected on remote/) expect(push.output).to match(/Locking support detected on remote/)
# Validate git push worked and file exists with content # Validate git push worked and file exists with content
push.project.visit!
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
show.wait_for_repository_replication show.wait_for_repository_replication
......
...@@ -42,7 +42,7 @@ module QA ...@@ -42,7 +42,7 @@ module QA
push.file_name = file_name push.file_name = file_name
push.file_content = "# #{file_content}" push.file_content = "# #{file_content}"
push.commit_message = 'Add README.md' push.commit_message = 'Add README.md'
end end.project.visit!
# Validate git push worked and file exists with content # Validate git push worked and file exists with content
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
...@@ -121,6 +121,7 @@ module QA ...@@ -121,6 +121,7 @@ module QA
expect(push.output).to match(/Locking support detected on remote/) expect(push.output).to match(/Locking support detected on remote/)
# Validate git push worked and file exists with content # Validate git push worked and file exists with content
push.project.visit!
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
show.wait_for_repository_replication show.wait_for_repository_replication
......
...@@ -40,7 +40,7 @@ module QA ...@@ -40,7 +40,7 @@ module QA
.new(__dir__) .new(__dir__)
.join('../../../../../ee/fixtures/secure_premade_reports') .join('../../../../../ee/fixtures/secure_premade_reports')
push.commit_message = 'Create Secure compatible application to serve premade reports' push.commit_message = 'Create Secure compatible application to serve premade reports'
end end.project.visit!
Page::Project::Menu.perform(&:click_ci_cd_pipelines) Page::Project::Menu.perform(&:click_ci_cd_pipelines)
Page::Project::Pipeline::Index.perform(&:click_on_latest_pipeline) Page::Project::Pipeline::Index.perform(&:click_on_latest_pipeline)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment