2023-03-10 07:33:30 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe Form::AdminSettings do
|
2024-10-24 08:44:13 -04:00
|
|
|
describe 'Validations' do
|
2023-03-10 07:33:30 -05:00
|
|
|
describe 'site_contact_username' do
|
|
|
|
context 'with no accounts' do
|
2024-10-24 08:44:13 -04:00
|
|
|
it { is_expected.to_not allow_value('Test').for(:site_contact_username) }
|
2023-03-10 07:33:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an account' do
|
|
|
|
before { Fabricate(:account, username: 'Glorp') }
|
|
|
|
|
2024-10-24 08:44:13 -04:00
|
|
|
it { is_expected.to_not allow_value('Test').for(:site_contact_username) }
|
|
|
|
it { is_expected.to allow_value('Glorp').for(:site_contact_username) }
|
2023-03-10 07:33:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2025-01-08 03:48:45 -05:00
|
|
|
|
|
|
|
describe '#save' do
|
|
|
|
describe 'updating digest values' do
|
|
|
|
context 'when updating custom css to real value' do
|
|
|
|
subject { described_class.new(custom_css: css) }
|
|
|
|
|
|
|
|
let(:css) { 'body { color: red; }' }
|
|
|
|
let(:digested) { Digest::SHA256.hexdigest(css) }
|
|
|
|
|
|
|
|
it 'changes relevant digest value' do
|
|
|
|
expect { subject.save }
|
|
|
|
.to(change { Rails.cache.read(:setting_digest_custom_css) }.to(digested))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when updating custom css to empty value' do
|
|
|
|
subject { described_class.new(custom_css: '') }
|
|
|
|
|
|
|
|
before { Rails.cache.write(:setting_digest_custom_css, 'previous-value') }
|
|
|
|
|
|
|
|
it 'changes relevant digest value' do
|
|
|
|
expect { subject.save }
|
|
|
|
.to(change { Rails.cache.read(:setting_digest_custom_css) }.to(be_blank))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when updating other fields' do
|
|
|
|
subject { described_class.new(site_contact_email: 'test@example.host') }
|
|
|
|
|
|
|
|
it 'does not update digests' do
|
|
|
|
expect { subject.save }
|
|
|
|
.to(not_change { Rails.cache.read(:setting_digest_custom_css) })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-03-10 07:33:30 -05:00
|
|
|
end
|