Skip to content
Snippets Groups Projects
Unverified Commit df4e73c7 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

[QA] Fix more edge-cases with API fabrication


Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 5610e415
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -19,20 +19,17 @@ module QA
 
attr_reader :api_resource, :api_response
 
def api_get_path
raise NotImplementedError, "Factory #{self.class.name} does not support fabrication via the API!"
end
alias_method :api_post_path, :api_get_path
alias_method :api_post_body, :api_get_path
def api_support?
api_get_path && api_post_path && api_post_body && true
rescue NotImplementedError
false
respond_to?(:api_get_path) &&
respond_to?(:api_post_path) &&
respond_to?(:api_post_body)
end
 
def fabricate_via_api!
unless api_support?
raise NotImplementedError, "Factory #{self.class.name} does not support fabrication via the API!"
end
resource_web_url(api_post)
end
 
Loading
Loading
Loading
Loading
@@ -40,10 +40,11 @@ module QA
factory = options.fetch(:factory) { new }
parents = options.fetch(:parents) { [] }
 
do_fabricate!(factory: factory, prepare_block: prepare_block, parents: parents) do
raise NotImplementedError unless factory.api_support?
raise NotImplementedError unless factory.api_support?
factory.eager_load_api_client!
 
factory.eager_load_api_client!
do_fabricate!(factory: factory, prepare_block: prepare_block, parents: parents) do
log_fabrication(:api, factory, parents, args) { factory.fabricate_via_api! }
end
end
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ module QA
project.description = 'project for adding issues'
end
 
product :project
product :title do
Page::Project::Issue::Show.act { issue_title }
end
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ module QA
 
dependency Factory::Resource::Group, as: :group
 
product :group
product :name
 
product :repository_ssh_location do
Loading
Loading
Loading
Loading
@@ -35,6 +35,27 @@ describe QA::Factory::ApiFabricator do
 
subject { factory.tap { |f| f.include(described_class) }.new }
 
describe '#api_support?' do
let(:api_client) { spy('Runtime::API::Client') }
let(:api_client_instance) { double('API Client') }
context 'when factory does not support fabrication via the API' do
let(:factory) { factory_without_api_support }
it 'returns false' do
expect(subject).not_to be_api_support
end
end
context 'when factory supports fabrication via the API' do
let(:factory) { factory_with_api_support }
it 'returns false' do
expect(subject).to be_api_support
end
end
end
describe '#fabricate_via_api!' do
let(:api_client) { spy('Runtime::API::Client') }
let(:api_client_instance) { double('API Client') }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment