Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'theme_changer_my_account_hooks'
require 'theme_changer_user_patch'
require 'theme_changer_themes_patch'
require 'theme_changer_setting_patch'

Rails.configuration.to_prepare do
# Guards against including the module multiple time (like in tests)
Expand Down
19 changes: 19 additions & 0 deletions lib/theme_changer_setting_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module ThemeChangerSetting #:nodoc: all
def self.prepended(base)
base.singleton_class.prepend ClassMethods
end

module ClassMethods
def ui_theme
setting = ThemeChangerUserSetting.find_theme_by_user_id(User.current.id)
return self[:ui_theme] unless setting
if setting.theme == ThemeChangerUserSetting::SYSTEM_SETTING
return self[:ui_theme]
end

setting.theme_name
end
end
end

Setting.prepend(ThemeChangerSetting) unless Setting.include? ThemeChangerSetting
29 changes: 29 additions & 0 deletions test/unit/theme_changer_setting_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Theme Changer plugin for Redmine
# Copyright (C) 2010-2017 Haruyuki Iida
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

class ThemeChangerSettingTest < ActiveSupport::TestCase
fixtures :theme_changer_user_settings, :users

def setup
User.current = User.second
end

def test_setting_ui_theme_returns_custom_user_theme_if_set
assert_equal('alternate', Setting.ui_theme)
end
end