Commit 64500f44 authored by Mark Lapierre's avatar Mark Lapierre Committed by 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.
parent bc498ba0
......@@ -76,7 +76,7 @@ module QA
end
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}})
end
......
......@@ -59,9 +59,9 @@ module QA
def actions
pending_actions = []
@add_files.map { |file| pending_actions << file.merge({ action: "create" }) } if @add_files
@update_files.map { |file| pending_actions << file.merge({ action: "update" }) } if @update_files
pending_actions
pending_actions << @add_files.map { |file| file.merge({ action: "create" }) } if @add_files
pending_actions << @update_files.map { |file| file.merge({ action: "update" }) } if @update_files
pending_actions.flatten
end
private
......
......@@ -26,7 +26,7 @@ module QA
end
def name
@name ||= api_resource&.dig(:name) || username
@name ||= api_resource&.dig(:name) || "QA User #{unique_id}"
end
def email
......@@ -91,9 +91,8 @@ module QA
def self.fabricate_or_use(username = nil, password = nil)
if Runtime::Env.signup_disabled?
self.new.tap do |user|
self.fabricate_via_api! do |user|
user.username = username
user.password = password
end
else
self.fabricate!
......
......@@ -46,7 +46,7 @@ module QA
project.standalone = true
project.add_name_uuid = false
project.name = project_name
project.path_with_namespace = "#{user.name}/#{project_name}"
project.path_with_namespace = "#{user.username}/#{project_name}"
project.user = user
project.api_client = api_client
end
......
......@@ -6,8 +6,10 @@ module QA
include Runtime::Fixtures
def login
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
unless Page::Main::Menu.perform(&:signed_in?)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
end
before(:all) do
......
......@@ -35,8 +35,8 @@ describe QA::Resource::User do
end
describe '#name' do
it 'defaults to the username' do
expect(subject.name).to eq(subject.username)
it 'defaults to a name based on the username' do
expect(subject.name).to match(/#{subject.username.tr('-', ' ')}/i)
end
it 'retrieves the name from the api_resource if present' 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