Skip to content
代码片段 群组 项目
提交 64500f44 编辑于 作者: Mark Lapierre's avatar Mark Lapierre 提交者: Sanad Liaquat
浏览文件

Fetch user via API in fabricate_or_use

Previously fabricate_or_use would only create a User instance with the
provided username and password. This was fine when only those creds
were needed (e.g., to sign on), but it's not enough in tests that
need other user details, e.g., the user's name.

This changes fabricate_or_use so that it fetches the user via the API,
which provides access to the user's details.
上级 bc498ba0
No related branches found
No related tags found
无相关合并请求
...@@ -76,7 +76,7 @@ def shallow_clone ...@@ -76,7 +76,7 @@ def shallow_clone
end end
def configure_identity(name, email) def configure_identity(name, email)
run(%Q{git config user.name #{name}}) run(%Q{git config user.name "#{name}"})
run(%Q{git config user.email #{email}}) run(%Q{git config user.email #{email}})
end end
......
...@@ -59,9 +59,9 @@ def api_post_body ...@@ -59,9 +59,9 @@ def api_post_body
def actions def actions
pending_actions = [] pending_actions = []
@add_files.map { |file| pending_actions << file.merge({ action: "create" }) } if @add_files pending_actions << @add_files.map { |file| file.merge({ action: "create" }) } if @add_files
@update_files.map { |file| pending_actions << file.merge({ action: "update" }) } if @update_files pending_actions << @update_files.map { |file| file.merge({ action: "update" }) } if @update_files
pending_actions pending_actions.flatten
end end
private private
......
...@@ -26,7 +26,7 @@ def password ...@@ -26,7 +26,7 @@ def password
end end
def name def name
@name ||= api_resource&.dig(:name) || username @name ||= api_resource&.dig(:name) || "QA User #{unique_id}"
end end
def email def email
...@@ -91,9 +91,8 @@ def api_post_body ...@@ -91,9 +91,8 @@ def api_post_body
def self.fabricate_or_use(username = nil, password = nil) def self.fabricate_or_use(username = nil, password = nil)
if Runtime::Env.signup_disabled? if Runtime::Env.signup_disabled?
self.new.tap do |user| self.fabricate_via_api! do |user|
user.username = username user.username = username
user.password = password
end end
else else
self.fabricate! self.fabricate!
......
...@@ -46,7 +46,7 @@ def create_project(user, api_client, project_name) ...@@ -46,7 +46,7 @@ def create_project(user, api_client, project_name)
project.standalone = true project.standalone = true
project.add_name_uuid = false project.add_name_uuid = false
project.name = project_name project.name = project_name
project.path_with_namespace = "#{user.name}/#{project_name}" project.path_with_namespace = "#{user.username}/#{project_name}"
project.user = user project.user = user
project.api_client = api_client project.api_client = api_client
end end
......
...@@ -6,8 +6,10 @@ module QA ...@@ -6,8 +6,10 @@ module QA
include Runtime::Fixtures include Runtime::Fixtures
def login def login
Runtime::Browser.visit(:gitlab, Page::Main::Login) unless Page::Main::Menu.perform(&:signed_in?)
Page::Main::Login.perform(&:sign_in_using_credentials) Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
end end
before(:all) do before(:all) do
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
end end
describe '#name' do describe '#name' do
it 'defaults to the username' do it 'defaults to a name based on the username' do
expect(subject.name).to eq(subject.username) expect(subject.name).to match(/#{subject.username.tr('-', ' ')}/i)
end end
it 'retrieves the name from the api_resource if present' do it 'retrieves the name from the api_resource if present' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册