2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-02-22 14:49:16 -05:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Appearance do
|
2016-10-12 01:50:01 -04:00
|
|
|
subject { build(:appearance) }
|
2016-02-22 14:49:16 -05:00
|
|
|
|
2018-05-04 13:23:50 -04:00
|
|
|
it { include(CacheableAttributes) }
|
|
|
|
it { expect(described_class.current_without_cache).to eq(described_class.first) }
|
2016-02-22 14:49:16 -05:00
|
|
|
|
2018-05-02 12:21:42 -04:00
|
|
|
it { is_expected.to have_many(:uploads) }
|
2017-08-09 10:41:51 -04:00
|
|
|
|
|
|
|
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-05-02 12:21:42 -04:00
|
|
|
|
2019-07-03 14:27:16 -04:00
|
|
|
context 'with uploads' do
|
2018-10-07 14:31:08 -04:00
|
|
|
it_behaves_like 'model with uploads', false do
|
2018-05-02 12:21:42 -04:00
|
|
|
let(:model_object) { create(:appearance, :with_logo) }
|
|
|
|
let(:upload_attribute) { :logo }
|
|
|
|
let(:uploader_class) { AttachmentUploader }
|
|
|
|
end
|
|
|
|
end
|
2018-12-25 03:24:00 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-01-23 13:28:26 -05:00
|
|
|
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
|
|
|
|
|
2018-12-25 03:24:00 -05:00
|
|
|
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
|
2018-04-02 10:26:59 -04:00
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
let(:triplet) { '#000' }
|
|
|
|
let(:hex) { '#AABBCC' }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value(nil).for(:message_background_color) }
|
|
|
|
it { is_expected.to allow_value(triplet).for(:message_background_color) }
|
|
|
|
it { is_expected.to allow_value(hex).for(:message_background_color) }
|
|
|
|
it { is_expected.not_to allow_value('000').for(:message_background_color) }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value(nil).for(:message_font_color) }
|
|
|
|
it { is_expected.to allow_value(triplet).for(:message_font_color) }
|
|
|
|
it { is_expected.to allow_value(hex).for(:message_font_color) }
|
|
|
|
it { is_expected.not_to allow_value('000').for(:message_font_color) }
|
|
|
|
end
|
2019-02-20 10:18:15 -05:00
|
|
|
|
|
|
|
describe 'email_header_and_footer_enabled' do
|
|
|
|
context 'default email_header_and_footer_enabled flag value' do
|
|
|
|
it 'returns email_header_and_footer_enabled as true' do
|
|
|
|
appearance = build(:appearance)
|
|
|
|
|
|
|
|
expect(appearance.email_header_and_footer_enabled?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting email_header_and_footer_enabled flag value' do
|
|
|
|
it 'returns email_header_and_footer_enabled as true' do
|
|
|
|
appearance = build(:appearance, email_header_and_footer_enabled: true)
|
|
|
|
|
|
|
|
expect(appearance.email_header_and_footer_enabled?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-22 14:49:16 -05:00
|
|
|
end
|