7da3b2cdd0
ObjectStore uploader requires presence of associated `uploads` record when deleting the upload file (through the carrierwave's after_commit hook) because we keep info whether file is LOCAL or REMOTE in `upload` object. For this reason we can not destroy uploads as "dependent: :destroy" hook because these would be deleted too soon. Instead we rely on carrierwave's hook to destroy `uploads` in after_commit hook. But in before_destroy hook we still have to delete not-mounted uploads (which don't use carrierwave's destroy hook). This has to be done in before_Destroy instead of after_commit because `FileUpload` requires existence of model's object on destroy action. This is not ideal state of things, in a next step we should investigate how to unify model dependencies so we can use same workflow for all uploads. Related to #45425
52 lines
1.2 KiB
Ruby
52 lines
1.2 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Appearance do
|
|
subject { build(:appearance) }
|
|
|
|
it { is_expected.to be_valid }
|
|
|
|
it { is_expected.to have_many(:uploads) }
|
|
|
|
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
|
|
|
|
context 'with uploads' do
|
|
it_behaves_like 'model with mounted uploader', false do
|
|
let(:model_object) { create(:appearance, :with_logo) }
|
|
let(:upload_attribute) { :logo }
|
|
let(:uploader_class) { AttachmentUploader }
|
|
end
|
|
end
|
|
end
|