mirror of
https://github.com/mastodon/mastodon.git
synced 2026-06-10 09:37:24 -05:00
Some checks are pending
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / test (3.4) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.4) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
76 lines
2.0 KiB
Ruby
76 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Setting do
|
|
describe '#to_param' do
|
|
let(:setting) { Fabricate(:setting, var: var) }
|
|
let(:var) { 'var' }
|
|
|
|
it 'returns setting.var' do
|
|
expect(setting.to_param).to eq var
|
|
end
|
|
end
|
|
|
|
describe '.[]' do
|
|
let(:key) { 'key' }
|
|
let(:cache_key) { 'cache-key' }
|
|
let(:cache_value) { 'cache-value' }
|
|
|
|
before do
|
|
allow(described_class).to receive(:cache_key).with(key).and_return(cache_key)
|
|
end
|
|
|
|
context 'when Rails.cache does not exists' do
|
|
before do
|
|
allow(described_class).to receive(:default_settings).and_return(default_settings)
|
|
|
|
Fabricate(:setting, var: key, value: 42) if save_setting
|
|
|
|
Rails.cache.delete(cache_key)
|
|
end
|
|
|
|
let(:default_value) { 'default_value' }
|
|
let(:default_settings) { { key => default_value } }
|
|
let(:save_setting) { true }
|
|
|
|
context 'when the setting has been saved to database' do
|
|
it 'returns the value from database' do
|
|
notifications = capture_notifications('sql.active_record') do
|
|
expect(described_class[key]).to eq 42
|
|
end
|
|
|
|
expect(notifications.size).to eq(1)
|
|
expect(notifications.first.payload[:name]).to eq('Setting Load')
|
|
end
|
|
end
|
|
|
|
context 'when the setting has not been saved to database' do
|
|
let(:save_setting) { false }
|
|
|
|
it 'returns default_settings[key]' do
|
|
expect(described_class[key]).to be default_settings[key]
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'when Rails.cache exists' do
|
|
before do
|
|
Rails.cache.write(cache_key, cache_value)
|
|
end
|
|
|
|
it 'does not query the database' do
|
|
notifications = capture_notifications('sql.active_record') do
|
|
described_class[key]
|
|
end
|
|
|
|
expect(notifications).to be_empty
|
|
end
|
|
|
|
it 'returns the cached value' do
|
|
expect(described_class[key]).to eq cache_value
|
|
end
|
|
end
|
|
end
|
|
end
|