diff options
Diffstat (limited to 'spec/lib/api/support')
-rw-r--r-- | spec/lib/api/support/git_access_actor_spec.rb | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/spec/lib/api/support/git_access_actor_spec.rb b/spec/lib/api/support/git_access_actor_spec.rb index 70753856419..143cc6e56ee 100644 --- a/spec/lib/api/support/git_access_actor_spec.rb +++ b/spec/lib/api/support/git_access_actor_spec.rb @@ -36,7 +36,7 @@ RSpec.describe API::Support::GitAccessActor do describe 'attributes' do describe '#user' do context 'when initialized with a User' do - let(:user) { create(:user) } + let(:user) { build(:user) } it 'returns the User' do expect(subject.user).to eq(user) @@ -44,7 +44,7 @@ RSpec.describe API::Support::GitAccessActor do end context 'when initialized with a Key' do - let(:user_for_key) { create(:user) } + let(:user_for_key) { build(:user) } let(:key) { create(:key, user: user_for_key) } it 'returns the User associated to the Key' do @@ -85,7 +85,7 @@ RSpec.describe API::Support::GitAccessActor do describe '#username' do context 'when initialized with a User' do - let(:user) { create(:user) } + let(:user) { build(:user) } it 'returns the username' do expect(subject.username).to eq(user.username) @@ -104,7 +104,7 @@ RSpec.describe API::Support::GitAccessActor do end context 'that has a User associated' do - let(:user_for_key) { create(:user) } + let(:user_for_key) { build(:user) } it 'returns the username of the User associated to the Key' do expect(subject.username).to eq(user_for_key.username) @@ -113,9 +113,47 @@ RSpec.describe API::Support::GitAccessActor do end end + describe '#key_details' do + context 'when initialized with a User' do + let(:user) { build(:user) } + + it 'returns an empty Hash' do + expect(subject.key_details).to eq({}) + end + end + + context 'when initialized with a Key' do + let(:key) { create(:key, user: user_for_key) } + + context 'that has no User associated' do + let(:user_for_key) { nil } + + it 'returns a Hash' do + expect(subject.key_details).to eq({ gl_key_type: 'key', gl_key_id: key.id }) + end + end + + context 'that has a User associated' do + let(:user_for_key) { build(:user) } + + it 'returns a Hash' do + expect(subject.key_details).to eq({ gl_key_type: 'key', gl_key_id: key.id }) + end + end + end + + context 'when initialized with a DeployKey' do + let(:key) { create(:deploy_key) } + + it 'returns a Hash' do + expect(subject.key_details).to eq({ gl_key_type: 'deploy_key', gl_key_id: key.id }) + end + end + end + describe '#update_last_used_at!' do context 'when initialized with a User' do - let(:user) { create(:user) } + let(:user) { build(:user) } it 'does nothing' do expect(user).not_to receive(:update_last_used_at) |