summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-01 17:02:56 +0000
committerStan Hu <stanhu@gmail.com>2019-03-01 17:02:56 +0000
commitadf71cfa75fb07c54cb2f55126d1f8596e3ab5c3 (patch)
treefb0661b3a8a6e2eb8b3ad182bf35f00083edd200 /spec
parent3977421ed1b0cf75ab2a4bdf7c06d7b8c80489f0 (diff)
parente96f2f248a63cc7115fb52a02b1743f15205e642 (diff)
downloadgitlab-ce-adf71cfa75fb07c54cb2f55126d1f8596e3ab5c3.tar.gz
Merge branch '9903-geo-selective-sync-by-namespace-is-broken' into 'master'
Fix GitLab::JsonCache when reading a persisted entry back from the cache See merge request gitlab-org/gitlab-ce!25587
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/json_cache_spec.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb
index b52078e8556..2cae8ec031a 100644
--- a/spec/lib/gitlab/json_cache_spec.rb
+++ b/spec/lib/gitlab/json_cache_spec.rb
@@ -297,13 +297,39 @@ describe Gitlab::JsonCache do
expect(result).to eq(broadcast_message)
end
+ context 'when the cached value is an instance of ActiveRecord::Base' do
+ it 'returns a persisted record when id is set' do
+ backend.write(expanded_key, broadcast_message.to_json)
+
+ result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+
+ expect(result).to be_persisted
+ end
+
+ it 'returns a new record when id is nil' do
+ backend.write(expanded_key, build(:broadcast_message).to_json)
+
+ result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+
+ expect(result).to be_new_record
+ end
+
+ it 'returns a new record when id is missing' do
+ backend.write(expanded_key, build(:broadcast_message).attributes.except('id').to_json)
+
+ result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
+
+ expect(result).to be_new_record
+ end
+ end
+
it "returns the result of the block when 'as' option is nil" do
result = cache.fetch(key, as: nil) { 'block result' }
expect(result).to eq('block result')
end
- it "returns the result of the block when 'as' option is not informed" do
+ it "returns the result of the block when 'as' option is missing" do
result = cache.fetch(key) { 'block result' }
expect(result).to eq('block result')