Fixed that validating a Setting with invalid name triggers an error (#15551).

git-svn-id: http://svn.redmine.org/redmine/trunk@12348 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-11-29 21:18:35 +00:00
parent 088ab2e686
commit 23974fb0ce
2 changed files with 17 additions and 1 deletions

View File

@ -83,7 +83,9 @@ class Setting < ActiveRecord::Base
validates_uniqueness_of :name
validates_inclusion_of :name, :in => @@available_settings.keys
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting|
(s = @@available_settings[setting.name]) && s['format'] == 'int'
}
# Hash used to cache setting values
@cached_settings = {}

View File

@ -41,6 +41,20 @@ class SettingTest < ActiveSupport::TestCase
assert_equal "My other title", Setting.find_by_name('app_title').value
end
def test_setting_with_int_format_should_accept_numeric_only
with_settings :session_timeout => 30 do
Setting.session_timeout = 'foo'
assert_equal "30", Setting.session_timeout
Setting.session_timeout = 40
assert_equal "40", Setting.session_timeout
end
end
def test_setting_with_invalid_name_should_be_valid
setting = Setting.new(:name => "does_not_exist", :value => "should_not_be_allowed")
assert !setting.save
end
def test_serialized_setting
Setting.notified_events = ['issue_added', 'issue_updated', 'news_added']
assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events