diff options
author | Brett Walker <bwalker@gitlab.com> | 2018-01-11 18:17:55 +0100 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2018-01-22 17:25:11 +0100 |
commit | ba4247c66fbbb97c4835fe54052e6cddc3c61ed0 (patch) | |
tree | c8771a3c5e513975f623aba482104cbc7693b9cd | |
parent | 0dc71abdd4f39916a1deba2657d81f54f465edb2 (diff) | |
download | gitlab-ce-ba4247c66fbbb97c4835fe54052e6cddc3c61ed0.tar.gz |
use new Product DSL for returning access_token from factory
-rw-r--r-- | qa/qa/factory/base.rb | 2 | ||||
-rw-r--r-- | qa/qa/factory/product.rb | 7 | ||||
-rw-r--r-- | qa/qa/factory/resource/personal_access_token.rb | 4 | ||||
-rw-r--r-- | qa/qa/specs/features/api/users_spec.rb | 3 |
4 files changed, 10 insertions, 6 deletions
diff --git a/qa/qa/factory/base.rb b/qa/qa/factory/base.rb index bd66b74a164..afaa96b4541 100644 --- a/qa/qa/factory/base.rb +++ b/qa/qa/factory/base.rb @@ -22,7 +22,7 @@ module QA factory.fabricate!(*args) - return Factory::Product.populate!(self) + return Factory::Product.populate!(factory) end end diff --git a/qa/qa/factory/product.rb b/qa/qa/factory/product.rb index 937bae7ac11..dbe02d37f22 100644 --- a/qa/qa/factory/product.rb +++ b/qa/qa/factory/product.rb @@ -8,7 +8,8 @@ module QA Attribute = Struct.new(:name, :block) - def initialize + def initialize(factory) + @factory = factory @location = current_url end @@ -17,8 +18,8 @@ module QA end def self.populate!(factory) - new.tap do |product| - factory.attributes.each_value do |attribute| + new(factory).tap do |product| + factory.class.attributes.each_value do |attribute| product.instance_exec(&attribute.block).tap do |value| product.define_singleton_method(attribute.name) { value } end diff --git a/qa/qa/factory/resource/personal_access_token.rb b/qa/qa/factory/resource/personal_access_token.rb index 949106cd80a..9c9fe185918 100644 --- a/qa/qa/factory/resource/personal_access_token.rb +++ b/qa/qa/factory/resource/personal_access_token.rb @@ -7,6 +7,10 @@ module QA class PersonalAccessToken < Factory::Base attr_accessor :name, :access_token + product :access_token do + self.factory.access_token + end + def fabricate!(sign_in_address = :gitlab) @access_token = Runtime::Env.personal_access_token return if @access_token diff --git a/qa/qa/specs/features/api/users_spec.rb b/qa/qa/specs/features/api/users_spec.rb index 86707d0f13c..4e7f5a92f84 100644 --- a/qa/qa/specs/features/api/users_spec.rb +++ b/qa/qa/specs/features/api/users_spec.rb @@ -3,8 +3,7 @@ module QA include Support::ApiHelpers before(:context) do - product = Factory::Resource::PersonalAccessToken.fabricate! - @access_token = product.factory.access_token + @access_token = Factory::Resource::PersonalAccessToken.fabricate!.access_token end context "when authenticated" do |