summaryrefslogtreecommitdiff
path: root/qa/qa/factory
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-12-13 15:21:28 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-12-15 10:46:58 +0100
commit5c393b39ab561d615bfc08908bb9721699337dc8 (patch)
tree50a664688838d2a12ab22acacd766747e6c1a0ba /qa/qa/factory
parent8b436fb8f87878264508c78471e3e71e2d024aa0 (diff)
downloadgitlab-ce-5c393b39ab561d615bfc08908bb9721699337dc8.tar.gz
Rename QA scenarios to make factory concept explicit
Diffstat (limited to 'qa/qa/factory')
-rw-r--r--qa/qa/factory/base.rb16
-rw-r--r--qa/qa/factory/repository/push.rb45
-rw-r--r--qa/qa/factory/resource/group.rb23
-rw-r--r--qa/qa/factory/resource/project.rb40
-rw-r--r--qa/qa/factory/resource/sandbox.rb28
-rw-r--r--qa/qa/factory/settings/hashed_storage.rb22
6 files changed, 174 insertions, 0 deletions
diff --git a/qa/qa/factory/base.rb b/qa/qa/factory/base.rb
new file mode 100644
index 00000000000..7b951a99b69
--- /dev/null
+++ b/qa/qa/factory/base.rb
@@ -0,0 +1,16 @@
+module QA
+ module Factory
+ class Base
+ def self.fabricate!(*args)
+ new.tap do |factory|
+ yield factory if block_given?
+ return factory.fabricate!(*args)
+ end
+ end
+
+ def fabricate!(*_args)
+ raise NotImplementedError
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/repository/push.rb b/qa/qa/factory/repository/push.rb
new file mode 100644
index 00000000000..1d5375d8c76
--- /dev/null
+++ b/qa/qa/factory/repository/push.rb
@@ -0,0 +1,45 @@
+require "pry-byebug"
+
+module QA
+ module Factory
+ module Repository
+ class Push < Factory::Base
+ PAGE_REGEX_CHECK =
+ %r{\/#{Runtime::Namespace.sandbox_name}\/qa-test[^\/]+\/{1}[^\/]+\z}.freeze
+
+ attr_writer :file_name,
+ :file_content,
+ :commit_message,
+ :branch_name
+
+ def initialize
+ @file_name = 'file.txt'
+ @file_content = '# This is test project'
+ @commit_message = "Add #{@file_name}"
+ @branch_name = 'master'
+ end
+
+ def fabricate!
+ Git::Repository.perform do |repository|
+ repository.location = Page::Project::Show.act do
+ unless PAGE_REGEX_CHECK.match(current_path)
+ raise "To perform this scenario the current page should be project show."
+ end
+
+ choose_repository_clone_http
+ repository_location
+ end
+
+ repository.use_default_credentials
+ repository.clone
+ repository.configure_identity('GitLab QA', 'root@gitlab.com')
+
+ repository.add_file(@file_name, @file_content)
+ repository.commit(@commit_message)
+ repository.push_changes(@branch_name)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/resource/group.rb b/qa/qa/factory/resource/group.rb
new file mode 100644
index 00000000000..a081cd94d39
--- /dev/null
+++ b/qa/qa/factory/resource/group.rb
@@ -0,0 +1,23 @@
+module QA
+ module Factory
+ module Resource
+ class Group < Factory::Base
+ attr_writer :path, :description
+
+ def initialize
+ @path = Runtime::Namespace.name
+ @description = "QA test run at #{Runtime::Namespace.time}"
+ end
+
+ def fabricate!
+ Page::Group::New.perform do |group|
+ group.set_path(@path)
+ group.set_description(@description)
+ group.set_visibility('Private')
+ group.create
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/resource/project.rb b/qa/qa/factory/resource/project.rb
new file mode 100644
index 00000000000..64fcfb084bb
--- /dev/null
+++ b/qa/qa/factory/resource/project.rb
@@ -0,0 +1,40 @@
+require 'securerandom'
+
+module QA
+ module Factory
+ module Resource
+ class Project < Factory::Base
+ attr_writer :description
+
+ def name=(name)
+ @name = "#{name}-#{SecureRandom.hex(8)}"
+ end
+
+ def fabricate!
+ Factory::Resource::Sandbox.fabricate!
+
+ Page::Group::Show.perform do |page|
+ if page.has_subgroup?(Runtime::Namespace.name)
+ page.go_to_subgroup(Runtime::Namespace.name)
+ else
+ page.go_to_new_subgroup
+
+ Factory::Resource::Group.fabricate! do |group|
+ group.path = Runtime::Namespace.name
+ end
+ end
+
+ page.go_to_new_project
+ end
+
+ Page::Project::New.perform do |page|
+ page.choose_test_namespace
+ page.choose_name(@name)
+ page.add_description(@description)
+ page.create_new_project
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/resource/sandbox.rb b/qa/qa/factory/resource/sandbox.rb
new file mode 100644
index 00000000000..fd2177915c5
--- /dev/null
+++ b/qa/qa/factory/resource/sandbox.rb
@@ -0,0 +1,28 @@
+module QA
+ module Factory
+ module Resource
+ ##
+ # Ensure we're in our sandbox namespace, either by navigating to it or by
+ # creating it if it doesn't yet exist.
+ #
+ class Sandbox < Factory::Base
+ def fabricate!
+ Page::Main::Menu.act { go_to_groups }
+
+ Page::Dashboard::Groups.perform do |page|
+ if page.has_group?(Runtime::Namespace.sandbox_name)
+ page.go_to_group(Runtime::Namespace.sandbox_name)
+ else
+ page.go_to_new_group
+
+ Resource::Group.fabricate! do |group|
+ group.path = Runtime::Namespace.sandbox_name
+ group.description = 'GitLab QA Sandbox'
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/settings/hashed_storage.rb b/qa/qa/factory/settings/hashed_storage.rb
new file mode 100644
index 00000000000..eb3b28f2613
--- /dev/null
+++ b/qa/qa/factory/settings/hashed_storage.rb
@@ -0,0 +1,22 @@
+module QA
+ module Factory
+ module Settings
+ class HashedStorage < Factory::Base
+ def fabricate!(*traits)
+ raise ArgumentError unless traits.include?(:enabled)
+
+ Page::Main::Login.act { sign_in_using_credentials }
+ Page::Main::Menu.act { go_to_admin_area }
+ Page::Admin::Menu.act { go_to_settings }
+
+ Page::Admin::Settings.act do
+ enable_hashed_storage
+ save_settings
+ end
+
+ QA::Page::Main::Menu.act { sign_out }
+ end
+ end
+ end
+ end
+end