Commit f48f9460 authored by Rémy Coutable's avatar Rémy Coutable

[QA] Retrieve the current user name and email

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent be855cc6
...@@ -126,10 +126,6 @@ module QA ...@@ -126,10 +126,6 @@ module QA
mod mod
end end
def self.attributes_names
dynamic_attributes.instance_methods(false).sort.grep_v(/=$/)
end
class DSL class DSL
def initialize(base) def initialize(base)
@base = base @base = base
......
...@@ -6,9 +6,12 @@ module QA ...@@ -6,9 +6,12 @@ module QA
module Resource module Resource
class User < Base class User < Base
attr_reader :unique_id attr_reader :unique_id
attr_writer :username, :password, :name, :email attr_writer :username, :password
attr_accessor :provider, :extern_uid attr_accessor :provider, :extern_uid
attribute :name
attribute :email
def initialize def initialize
@unique_id = SecureRandom.hex(8) @unique_id = SecureRandom.hex(8)
end end
...@@ -22,11 +25,11 @@ module QA ...@@ -22,11 +25,11 @@ module QA
end end
def name def name
@name ||= username @name ||= api_resource&.dig(:name) || username
end end
def email def email
@email ||= "#{username}@example.com" @email ||= api_resource&.dig(:email) || "#{username}@example.com"
end end
def credentials_given? def credentials_given?
......
...@@ -39,11 +39,15 @@ module QA ...@@ -39,11 +39,15 @@ module QA
end end
it 'user views raw email patch' do it 'user views raw email patch' do
user = Resource::User.fabricate_via_api! do |user|
user.username = Runtime::User.username
end
view_commit view_commit
Page::Project::Commit::Show.perform(&:select_email_patches) Page::Project::Commit::Show.perform(&:select_email_patches)
expect(page).to have_content('From: Administrator <admin@example.com>') expect(page).to have_content("From: #{user.name} <#{user.email}>")
expect(page).to have_content('Subject: [PATCH] Add second file') expect(page).to have_content('Subject: [PATCH] Add second file')
expect(page).to have_content('diff --git a/second b/second') expect(page).to have_content('diff --git a/second b/second')
end end
......
...@@ -138,10 +138,6 @@ describe QA::Resource::Base do ...@@ -138,10 +138,6 @@ describe QA::Resource::Base do
describe '.attribute' do describe '.attribute' do
include_context 'simple resource' include_context 'simple resource'
it 'appends new attribute' do
expect(subject.attributes_names).to eq([:no_block, :test, :web_url])
end
context 'when the attribute is populated via a block' do context 'when the attribute is populated via a block' do
it 'returns value from the block' do it 'returns value from the block' do
result = subject.fabricate!(resource: resource) result = subject.fabricate!(resource: resource)
......
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