summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-03-07 00:39:56 +0000
committerRémy Coutable <remy@rymai.me>2017-03-07 00:39:56 +0000
commitef24c9ef775218adfdb8178fdc9a3bf4016a53b0 (patch)
tree192a213ba0a62890867eadc47df53816c03cfd15 /spec
parentd12c992191c0b3941b4cabb36f059b798dd20a35 (diff)
parent8ab17a5305e666cdeba59a01a57ff47df77f2c0a (diff)
downloadgitlab-ce-ef24c9ef775218adfdb8178fdc9a3bf4016a53b0.tar.gz
Merge branch 'use-publish-to-post-notifications' into 'master'
Use publish channel to post notifications changes See merge request !9574
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index a32c6131030..8e5e8288c49 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -199,4 +199,58 @@ describe Gitlab::Workhorse, lib: true do
end
end
end
+
+ describe '.set_key_and_notify' do
+ let(:key) { 'test-key' }
+ let(:value) { 'test-value' }
+
+ subject { described_class.set_key_and_notify(key, value, overwrite: overwrite) }
+
+ shared_examples 'set and notify' do
+ it 'set and return the same value' do
+ is_expected.to eq(value)
+ end
+
+ it 'set and notify' do
+ expect_any_instance_of(Redis).to receive(:publish)
+ .with(described_class::NOTIFICATION_CHANNEL, "test-key=test-value")
+
+ subject
+ end
+ end
+
+ context 'when we set a new key' do
+ let(:overwrite) { true }
+
+ it_behaves_like 'set and notify'
+ end
+
+ context 'when we set an existing key' do
+ let(:old_value) { 'existing-key' }
+
+ before do
+ described_class.set_key_and_notify(key, old_value, overwrite: true)
+ end
+
+ context 'and overwrite' do
+ let(:overwrite) { true }
+
+ it_behaves_like 'set and notify'
+ end
+
+ context 'and do not overwrite' do
+ let(:overwrite) { false }
+
+ it 'try to set but return the previous value' do
+ is_expected.to eq(old_value)
+ end
+
+ it 'does not notify' do
+ expect_any_instance_of(Redis).not_to receive(:publish)
+
+ subject
+ end
+ end
+ end
+ end
end