diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/personal_access_tokens | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/personal_access_tokens')
-rw-r--r-- | spec/services/personal_access_tokens/create_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/personal_access_tokens/last_used_service_spec.rb | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/spec/services/personal_access_tokens/create_service_spec.rb b/spec/services/personal_access_tokens/create_service_spec.rb index 9190434b96a..475ade95948 100644 --- a/spec/services/personal_access_tokens/create_service_spec.rb +++ b/spec/services/personal_access_tokens/create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PersonalAccessTokens::CreateService do +RSpec.describe PersonalAccessTokens::CreateService do describe '#execute' do context 'with valid params' do it 'creates personal access token record' do diff --git a/spec/services/personal_access_tokens/last_used_service_spec.rb b/spec/services/personal_access_tokens/last_used_service_spec.rb new file mode 100644 index 00000000000..6fc74e27dd9 --- /dev/null +++ b/spec/services/personal_access_tokens/last_used_service_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PersonalAccessTokens::LastUsedService do + describe '#execute' do + subject { described_class.new(personal_access_token).execute } + + context 'when the personal access token has not been used recently' do + let_it_be(:personal_access_token) { create(:personal_access_token, last_used_at: 1.year.ago) } + + it 'updates the last_used_at timestamp' do + expect { subject }.to change { personal_access_token.last_used_at } + end + + it 'does not run on read-only GitLab instances' do + allow(::Gitlab::Database).to receive(:read_only?).and_return(true) + + expect { subject }.not_to change { personal_access_token.last_used_at } + end + end + + context 'when the personal access token has been used recently' do + let_it_be(:personal_access_token) { create(:personal_access_token, last_used_at: 1.minute.ago) } + + it 'does not update the last_used_at timestamp' do + expect { subject }.not_to change { personal_access_token.last_used_at } + end + end + + context 'when the last_used_at timestamp is nil' do + let_it_be(:personal_access_token) { create(:personal_access_token, last_used_at: nil) } + + it 'updates the last_used_at timestamp' do + expect { subject }.to change { personal_access_token.last_used_at } + end + end + + context 'when not a personal access token' do + let_it_be(:personal_access_token) { create(:oauth_access_token) } + + it 'does not execute' do + expect(subject).to be_nil + end + end + end +end |