diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-11 14:39:26 +0000 |
---|---|---|
committer | Simon Knox <psimyn@gmail.com> | 2017-08-15 09:15:39 +1000 |
commit | fea1e1299e14fb92faf33b9e1c312691deb1954e (patch) | |
tree | af2109c4908c8fbd9c01fc9cbdf9cb95a25e25d6 /spec | |
parent | 70be65ca5f440d5f57a937e9ce2d1cabf03f4652 (diff) | |
download | gitlab-ce-fea1e1299e14fb92faf33b9e1c312691deb1954e.tar.gz |
Merge branch 'appearances-caching-and-schema' into 'master'
Cache Appearance instances in Redis
Closes #36066 and #31698
See merge request !13433
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/appearance_spec.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb index 7cd3a84d592..b5d5d58697b 100644 --- a/spec/models/appearance_spec.rb +++ b/spec/models/appearance_spec.rb @@ -9,4 +9,39 @@ RSpec.describe Appearance do it { is_expected.to validate_presence_of(:description) } it { is_expected.to have_many(:uploads).dependent(:destroy) } + + describe '.current', :use_clean_rails_memory_store_caching do + let!(:appearance) { create(:appearance) } + + it 'returns the current appearance row' do + expect(described_class.current).to eq(appearance) + end + + it 'caches the result' do + expect(described_class).to receive(:first).once + + 2.times { described_class.current } + end + end + + describe '#flush_redis_cache' do + it 'flushes the cache in Redis' do + appearance = create(:appearance) + + expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY) + + appearance.flush_redis_cache + end + end + + describe '#single_appearance_row' do + it 'adds an error when more than 1 row exists' do + create(:appearance) + + new_row = build(:appearance) + new_row.save + + expect(new_row.valid?).to eq(false) + end + end end |