Skip to content

Commit 40efc45

Browse files
Merge branch 'qa-fix-resource-attribute' into 'master'
Fix Resource attribute bug See merge request gitlab-org/gitlab-ce!24407
2 parents d559c9e + bc4ba8d commit 40efc45

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed

qa/qa/resource/base.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,13 @@ def self.evaluator
116116
end
117117
private_class_method :evaluator
118118

119-
def self.dynamic_attributes
120-
const_get(:DynamicAttributes)
121-
rescue NameError
122-
mod = const_set(:DynamicAttributes, Module.new)
123-
124-
include mod
125-
126-
mod
127-
end
128-
129119
class DSL
130120
def initialize(base)
131121
@base = base
132122
end
133123

134124
def attribute(name, &block)
135-
@base.dynamic_attributes.module_eval do
125+
@base.module_eval do
136126
attr_writer(name)
137127

138128
define_method(name) do

qa/qa/resource/fork.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
module QA
44
module Resource
55
class Fork < Base
6+
attribute :project do
7+
Resource::Project.fabricate! do |resource|
8+
resource.name = push.project.name
9+
resource.path_with_namespace = "#{user.name}/#{push.project.name}"
10+
end
11+
end
12+
613
attribute :push do
714
Repository::ProjectPush.fabricate!
815
end
@@ -37,6 +44,8 @@ def fabricate!
3744
Page::Layout::Banner.perform do |page|
3845
page.has_notice?('The project was successfully forked.')
3946
end
47+
48+
populate(:project)
4049
end
4150
end
4251
end

qa/qa/resource/merge_request_from_fork.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MergeRequestFromFork < MergeRequest
1111

1212
attribute :push do
1313
Repository::ProjectPush.fabricate! do |resource|
14-
resource.project = fork
14+
resource.project = fork.project
1515
resource.branch_name = fork_branch
1616
resource.file_name = 'file2.txt'
1717
resource.user = fork.user

qa/qa/resource/project.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class Project < Base
1212
Group.fabricate!
1313
end
1414

15+
attribute :path_with_namespace do
16+
"#{group.sandbox.path}/#{group.path}/#{name}" if group
17+
end
18+
1519
attribute :repository_ssh_location do
1620
Page::Project::Show.perform do |page|
1721
page.repository_clone_ssh_location
@@ -46,8 +50,14 @@ def fabricate!
4650
end
4751
end
4852

53+
def fabricate_via_api!
54+
resource_web_url(api_get)
55+
rescue ResourceNotFoundError
56+
super
57+
end
58+
4959
def api_get_path
50-
"/projects/#{name}"
60+
"/projects/#{CGI.escape(path_with_namespace)}"
5161
end
5262

5363
def api_post_path

qa/qa/specs/features/browser_ui/3_create/merge_request/merge_merge_request_from_fork_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ module QA
55
describe 'Merge request creation from fork' do
66
it 'user forks a project, submits a merge request and maintainer merges it' do
77
Runtime::Browser.visit(:gitlab, Page::Main::Login)
8-
Page::Main::Login.act { sign_in_using_credentials }
8+
Page::Main::Login.perform(&:sign_in_using_credentials)
99

1010
merge_request = Resource::MergeRequestFromFork.fabricate! do |merge_request|
1111
merge_request.fork_branch = 'feature-branch'
1212
end
1313

14-
Page::Main::Menu.perform { |main| main.sign_out }
15-
Page::Main::Login.perform { |login| login.sign_in_using_credentials }
14+
Page::Main::Menu.perform(&:sign_out)
15+
Page::Main::Login.perform(&:sign_in_using_credentials)
1616

1717
merge_request.visit!
1818

19-
Page::MergeRequest::Show.perform { |show| show.merge! }
19+
Page::MergeRequest::Show.perform(&:merge!)
2020

2121
expect(page).to have_content('The changes were merged')
2222
end

qa/spec/resource/base_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,42 @@ def self.current_url
213213
.to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.")
214214
end
215215
end
216+
217+
context 'when multiple resources have the same attribute name' do
218+
let(:base) do
219+
Class.new(QA::Resource::Base) do
220+
def fabricate!
221+
'any'
222+
end
223+
224+
def self.current_url
225+
'http://stub'
226+
end
227+
end
228+
end
229+
let(:first_resource) do
230+
Class.new(base) do
231+
attribute :test do
232+
'first block'
233+
end
234+
end
235+
end
236+
let(:second_resource) do
237+
Class.new(base) do
238+
attribute :test do
239+
'second block'
240+
end
241+
end
242+
end
243+
244+
it 'has unique attribute values' do
245+
first_result = first_resource.fabricate!(resource: first_resource.new)
246+
second_result = second_resource.fabricate!(resource: second_resource.new)
247+
248+
expect(first_result.test).to eq 'first block'
249+
expect(second_result.test).to eq 'second block'
250+
end
251+
end
216252
end
217253

218254
describe '#web_url' do

0 commit comments

Comments
 (0)