Move theme-related helper methods out of controller (#37807)
This commit is contained in:
1 parent
040555be7f
commit
34514bcfe9
5 files changed
+72
-37
No files matched your search
@@ -85,20 +85,6 @@ RSpec.describe ApplicationController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'helper_method :current_theme' do
|
||||
it 'returns "default" when theme wasn\'t changed in admin settings' do
|
||||
allow(Setting).to receive(:default_settings).and_return({ 'theme' => 'default' })
|
||||
|
||||
expect(controller.view_context.current_theme).to eq 'default'
|
||||
end
|
||||
|
||||
it 'returns instances\'s theme when user is not signed in' do
|
||||
allow(Setting).to receive(:[]).with('theme').and_return 'contrast'
|
||||
|
||||
expect(controller.view_context.current_theme).to eq 'contrast'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with ActionController::RoutingError' do
|
||||
subject do
|
||||
routes.draw { get 'routing_error' => 'anonymous#routing_error' }
|
||||
|
||||
@@ -100,6 +100,60 @@ RSpec.describe ThemeHelper do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_theme' do
|
||||
subject { helper.current_theme }
|
||||
|
||||
context 'when user is not signed in' do
|
||||
context 'when theme was not changed in settings' do
|
||||
it { is_expected.to eq('default') }
|
||||
end
|
||||
|
||||
context 'when theme is changed in settings' do
|
||||
before { Setting.theme = 'contrast' }
|
||||
|
||||
it { is_expected.to eq('contrast') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is signed in' do
|
||||
before { allow(helper).to receive(:current_user).and_return(current_user) }
|
||||
|
||||
let(:current_user) { Fabricate :user }
|
||||
|
||||
context 'when user did not set theme' do
|
||||
it { is_expected.to eq('default') }
|
||||
end
|
||||
|
||||
context 'when user set theme' do
|
||||
before { current_user.settings.update(theme: 'alternate', noindex: false) }
|
||||
|
||||
context 'when theme is valid' do
|
||||
before { allow(Themes.instance).to receive(:names).and_return %w(default alternate good evil) }
|
||||
|
||||
it { is_expected.to eq('alternate') }
|
||||
end
|
||||
|
||||
context 'when theme is not valid' do
|
||||
it { is_expected.to eq('default') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#page_color_scheme' do
|
||||
subject { helper.page_color_scheme }
|
||||
|
||||
context 'when force_color_scheme is present' do
|
||||
before { helper.content_for(:force_color_scheme) { 'value' } }
|
||||
|
||||
it { is_expected.to eq('value') }
|
||||
end
|
||||
|
||||
context 'when force_color_scheme is absent' do
|
||||
it { is_expected.to eq('auto') }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def html_links
|
||||
|
||||
Reference in new issue
Block a user