gitlab-org--gitlab-foss/spec/models/appearance_spec.rb
Yorick Peterse 26bb50412c
Cache Appearance instances in Redis
This caches the result of Appearance.first in a similar fashion to how
ApplicationSetting instances are cached. We also add some NOT NULL
constraints to the table and correct the timestamp types.

Fixes gitlab-org/gitlab-ce#36066, fixes gitlab-org/gitlab-ce#31698
2017-08-10 12:45:49 +02:00

47 lines
1.1 KiB
Ruby

require 'rails_helper'
RSpec.describe Appearance do
subject { build(:appearance) }
it { is_expected.to be_valid }
it { is_expected.to validate_presence_of(:title) }
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