Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2017-01-20 13:42:46 +0300
committerAdam Niedzielski <adamsunday@gmail.com>2017-01-20 13:42:46 +0300
commit8c41d5f5e13c321aa38d7636e608dc84371cfd5d (patch)
tree6a68d0a5657015a8ce1a173d8ce9c294b2e40459 /spec/models/key_spec.rb
parent5a41d92b9d73cbc41b649239e40a15955094f77e (diff)
Record used SSH keys only 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.rb27
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