Commit 40efc454 authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'qa-fix-resource-attribute' into 'master'

Fix Resource attribute bug

See merge request gitlab-org/gitlab-ce!24407
parents d559c9e6 bc4ba8d4
...@@ -116,23 +116,13 @@ module QA ...@@ -116,23 +116,13 @@ module QA
end end
private_class_method :evaluator private_class_method :evaluator
def self.dynamic_attributes
const_get(:DynamicAttributes)
rescue NameError
mod = const_set(:DynamicAttributes, Module.new)
include mod
mod
end
class DSL class DSL
def initialize(base) def initialize(base)
@base = base @base = base
end end
def attribute(name, &block) def attribute(name, &block)
@base.dynamic_attributes.module_eval do @base.module_eval do
attr_writer(name) attr_writer(name)
define_method(name) do define_method(name) do
......
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
module QA module QA
module Resource module Resource
class Fork < Base class Fork < Base
attribute :project do
Resource::Project.fabricate! do |resource|
resource.name = push.project.name
resource.path_with_namespace = "#{user.name}/#{push.project.name}"
end
end
attribute :push do attribute :push do
Repository::ProjectPush.fabricate! Repository::ProjectPush.fabricate!
end end
...@@ -37,6 +44,8 @@ module QA ...@@ -37,6 +44,8 @@ module QA
Page::Layout::Banner.perform do |page| Page::Layout::Banner.perform do |page|
page.has_notice?('The project was successfully forked.') page.has_notice?('The project was successfully forked.')
end end
populate(:project)
end end
end end
end end
......
...@@ -11,7 +11,7 @@ module QA ...@@ -11,7 +11,7 @@ module QA
attribute :push do attribute :push do
Repository::ProjectPush.fabricate! do |resource| Repository::ProjectPush.fabricate! do |resource|
resource.project = fork resource.project = fork.project
resource.branch_name = fork_branch resource.branch_name = fork_branch
resource.file_name = 'file2.txt' resource.file_name = 'file2.txt'
resource.user = fork.user resource.user = fork.user
......
...@@ -12,6 +12,10 @@ module QA ...@@ -12,6 +12,10 @@ module QA
Group.fabricate! Group.fabricate!
end end
attribute :path_with_namespace do
"#{group.sandbox.path}/#{group.path}/#{name}" if group
end
attribute :repository_ssh_location do attribute :repository_ssh_location do
Page::Project::Show.perform do |page| Page::Project::Show.perform do |page|
page.repository_clone_ssh_location page.repository_clone_ssh_location
...@@ -46,8 +50,14 @@ module QA ...@@ -46,8 +50,14 @@ module QA
end end
end end
def fabricate_via_api!
resource_web_url(api_get)
rescue ResourceNotFoundError
super
end
def api_get_path def api_get_path
"/projects/#{name}" "/projects/#{CGI.escape(path_with_namespace)}"
end end
def api_post_path def api_post_path
......
...@@ -5,18 +5,18 @@ module QA ...@@ -5,18 +5,18 @@ module QA
describe 'Merge request creation from fork' do describe 'Merge request creation from fork' do
it 'user forks a project, submits a merge request and maintainer merges it' do it 'user forks a project, submits a merge request and maintainer merges it' do
Runtime::Browser.visit(:gitlab, Page::Main::Login) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials } Page::Main::Login.perform(&:sign_in_using_credentials)
merge_request = Resource::MergeRequestFromFork.fabricate! do |merge_request| merge_request = Resource::MergeRequestFromFork.fabricate! do |merge_request|
merge_request.fork_branch = 'feature-branch' merge_request.fork_branch = 'feature-branch'
end end
Page::Main::Menu.perform { |main| main.sign_out } Page::Main::Menu.perform(&:sign_out)
Page::Main::Login.perform { |login| login.sign_in_using_credentials } Page::Main::Login.perform(&:sign_in_using_credentials)
merge_request.visit! merge_request.visit!
Page::MergeRequest::Show.perform { |show| show.merge! } Page::MergeRequest::Show.perform(&:merge!)
expect(page).to have_content('The changes were merged') expect(page).to have_content('The changes were merged')
end end
......
...@@ -213,6 +213,42 @@ describe QA::Resource::Base do ...@@ -213,6 +213,42 @@ describe QA::Resource::Base do
.to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.") .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.")
end end
end end
context 'when multiple resources have the same attribute name' do
let(:base) do
Class.new(QA::Resource::Base) do
def fabricate!
'any'
end
def self.current_url
'http://stub'
end
end
end
let(:first_resource) do
Class.new(base) do
attribute :test do
'first block'
end
end
end
let(:second_resource) do
Class.new(base) do
attribute :test do
'second block'
end
end
end
it 'has unique attribute values' do
first_result = first_resource.fabricate!(resource: first_resource.new)
second_result = second_resource.fabricate!(resource: second_resource.new)
expect(first_result.test).to eq 'first block'
expect(second_result.test).to eq 'second block'
end
end
end end
describe '#web_url' do describe '#web_url' do
......
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