2016-04-02 18:10:28 +05:30
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe Appearance do
|
2016-11-03 12:29:30 +05:30
|
|
|
subject { build(:appearance) }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it { include(CacheableAttributes) }
|
|
|
|
it { expect(described_class.current_without_cache).to eq(described_class.first) }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it { is_expected.to have_many(:uploads) }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
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
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
context 'with uploads' do
|
2019-02-13 22:33:31 +05:30
|
|
|
it_behaves_like 'model with uploads', false do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:model_object) { create(:appearance, :with_logo) }
|
|
|
|
let(:upload_attribute) { :logo }
|
|
|
|
let(:uploader_class) { AttachmentUploader }
|
|
|
|
end
|
|
|
|
end
|
2019-02-13 22:33:31 +05:30
|
|
|
|
|
|
|
shared_examples 'logo paths' do |logo_type|
|
|
|
|
let(:appearance) { create(:appearance, "with_#{logo_type}".to_sym) }
|
|
|
|
let(:filename) { 'dk.png' }
|
|
|
|
let(:expected_path) { "/uploads/-/system/appearance/#{logo_type}/#{appearance.id}/#{filename}" }
|
|
|
|
|
|
|
|
it 'returns nil when there is no upload' do
|
|
|
|
expect(subject.send("#{logo_type}_path")).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the path when the upload has been orphaned' do
|
|
|
|
appearance.send(logo_type).upload.destroy
|
|
|
|
appearance.reload
|
|
|
|
|
|
|
|
expect(appearance.send("#{logo_type}_path")).to eq(expected_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a local path using the system route' do
|
|
|
|
expect(appearance.send("#{logo_type}_path")).to eq(expected_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with asset host configured' do
|
|
|
|
let(:asset_host) { 'https://gitlab-assets.example.com' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(ActionController::Base).to receive(:asset_host) { asset_host }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a full URL with the system path' do
|
|
|
|
expect(appearance.send("#{logo_type}_path")).to eq("#{asset_host}#{expected_path}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%i(logo header_logo favicon).each do |logo_type|
|
|
|
|
it_behaves_like 'logo paths', logo_type
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|