diff options
author | Ruben Davila <rdavila84@gmail.com> | 2017-09-07 09:10:39 -0500 |
---|---|---|
committer | Ruben Davila <rdavila84@gmail.com> | 2017-09-07 09:11:52 -0500 |
commit | 26264625cbc2692bc113c1e701cb15eecbd010d2 (patch) | |
tree | 7833db383c1d1170f7c8a9a4f1131bec0e53943a | |
parent | 99dcf870dd46299ffec2e5067c9b3223de3315ce (diff) | |
download | gitlab-ce-35012-navigation-add-option-to-change-navigation-color-palette.tar.gz |
Small refactor after last code review.35012-navigation-add-option-to-change-navigation-color-palette
-rw-r--r-- | app/helpers/preferences_helper.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/themes.rb | 10 | ||||
-rw-r--r-- | spec/helpers/preferences_helper_spec.rb | 6 |
3 files changed, 8 insertions, 10 deletions
diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 64605908c05..0d7347ed30d 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -41,7 +41,7 @@ module PreferencesHelper end def user_application_theme - Gitlab::Themes.for_user(current_user).css_class + @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class end def user_color_scheme diff --git a/lib/gitlab/themes.rb b/lib/gitlab/themes.rb index 37054d98102..d43eff5ba4a 100644 --- a/lib/gitlab/themes.rb +++ b/lib/gitlab/themes.rb @@ -73,13 +73,11 @@ module Gitlab private def default_id - id = Gitlab.config.gitlab.default_theme.to_i + @default_id ||= begin + id = Gitlab.config.gitlab.default_theme.to_i + theme_ids = THEMES.map(&:id) - # Prevent an invalid configuration setting from causing an infinite loop - if id < THEMES.first.id || id > THEMES.last.id - APPLICATION_DEFAULT - else - id + theme_ids.include?(id) ? id : APPLICATION_DEFAULT end end end diff --git a/spec/helpers/preferences_helper_spec.rb b/spec/helpers/preferences_helper_spec.rb index 69f0e8e2f9e..8b8080563d3 100644 --- a/spec/helpers/preferences_helper_spec.rb +++ b/spec/helpers/preferences_helper_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe PreferencesHelper do - describe 'dashboard_choices' do + describe '#dashboard_choices' do it 'raises an exception when defined choices may be missing' do expect(User).to receive(:dashboards).and_return(foo: 'foo') expect { helper.dashboard_choices }.to raise_error(RuntimeError) @@ -26,7 +26,7 @@ describe PreferencesHelper do end end - describe 'user_application_theme' do + describe '#user_application_theme' do context 'with a user' do it "returns user's theme's css_class" do stub_user(theme_id: 3) @@ -52,7 +52,7 @@ describe PreferencesHelper do end end - describe 'user_color_scheme' do + describe '#user_color_scheme' do context 'with a user' do it "returns user's scheme's css_class" do allow(helper).to receive(:current_user) |