diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-20 11:42:46 +0100 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-20 11:42:46 +0100 |
commit | 8c41d5f5e13c321aa38d7636e608dc84371cfd5d (patch) | |
tree | 6a68d0a5657015a8ce1a173d8ce9c294b2e40459 /spec/models/key_spec.rb | |
parent | 5a41d92b9d73cbc41b649239e40a15955094f77e (diff) | |
download | gitlab-ce-8c41d5f5e13c321aa38d7636e608dc84371cfd5d.tar.gz |
Record used SSH keys only once per dayrecord-used-ssh-keys-once-per-day
Use Gitlab::ExclusiveLease to make sure that we enqueue Sidekiq job
at most once per day for given key.
Diffstat (limited to 'spec/models/key_spec.rb')
-rw-r--r-- | spec/models/key_spec.rb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 5eaddd822be..7c40cfd8253 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -30,11 +30,30 @@ describe Key, models: true do end describe "#update_last_used_at" do - it "enqueues a UseKeyWorker job" do - key = create(:key) + let(:key) { create(:key) } + + context 'when key was not updated during the last day' do + before do + allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain). + and_return('000000') + end + + it 'enqueues a UseKeyWorker job' do + expect(UseKeyWorker).to receive(:perform_async).with(key.id) + key.update_last_used_at + end + end + + context 'when key was updated during the last day' do + before do + allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain). + and_return(false) + end - expect(UseKeyWorker).to receive(:perform_async).with(key.id) - key.update_last_used_at + it 'does not enqueue a UseKeyWorker job' do + expect(UseKeyWorker).not_to receive(:perform_async) + key.update_last_used_at + end end end end |