| ... | @@ -7,7 +7,7 @@ describe Gitlab::JsonCache do |
... | @@ -7,7 +7,7 @@ describe Gitlab::JsonCache do |
|
|
let(:namespace) { 'geo' }
|
|
let(:namespace) { 'geo' }
|
|
|
let(:key) { 'foo' }
|
|
let(:key) { 'foo' }
|
|
|
let(:expanded_key) { "#{namespace}:#{key}:#{Rails.version}" }
|
|
let(:expanded_key) { "#{namespace}:#{key}:#{Rails.version}" }
|
|
|
let(:broadcast_message) { create(:broadcast_message) }
|
|
set(:broadcast_message) { create(:broadcast_message) }
|
|
|
|
|
|
|
|
subject(:cache) { described_class.new(namespace: namespace, backend: backend) }
|
|
subject(:cache) { described_class.new(namespace: namespace, backend: backend) }
|
|
|
|
|
|
| ... | @@ -321,6 +321,42 @@ describe Gitlab::JsonCache do |
... | @@ -321,6 +321,42 @@ describe Gitlab::JsonCache do |
|
|
|
|
|
|
|
expect(result).to be_new_record
|
|
expect(result).to be_new_record
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
it 'gracefully handles bad cached entry' do
|
|
|
|
allow(backend).to receive(:read)
|
|
|
|
.with(expanded_key)
|
|
|
|
.and_return('{')
|
|
|
|
|
|
|
|
expect(cache.read(key, BroadcastMessage)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gracefully handles an empty hash' do
|
|
|
|
allow(backend).to receive(:read)
|
|
|
|
.with(expanded_key)
|
|
|
|
.and_return('{}')
|
|
|
|
|
|
|
|
expect(cache.read(key, BroadcastMessage)).to be_a(BroadcastMessage)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gracefully handles unknown attributes' do
|
|
|
|
allow(backend).to receive(:read)
|
|
|
|
.with(expanded_key)
|
|
|
|
.and_return(broadcast_message.attributes.merge(unknown_attribute: 1).to_json)
|
|
|
|
|
|
|
|
expect(cache.read(key, BroadcastMessage)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gracefully handles excluded fields from attributes during serialization' do
|
|
|
|
backend.write(expanded_key, broadcast_message.to_json)
|
|
|
|
|
|
|
|
result = cache.fetch(key, as: BroadcastMessage) { 'block result' }
|
|
|
|
|
|
|
|
excluded_fields = BroadcastMessage.cached_markdown_fields.html_fields
|
|
|
|
|
|
|
|
(excluded_fields + ['cached_markdown_version']).each do |field|
|
|
|
|
expect(result.public_send(field)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
it "returns the result of the block when 'as' option is nil" do
|
|
it "returns the result of the block when 'as' option is nil" do
|
| ... | |
... | |
| ... | | ... | |