summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-11-29 21:18:35 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-11-29 21:18:35 +0000
commit23974fb0cede44d69db1c31ef7cd7296bdb2bc90 (patch)
tree59f80323d0c593c246d9ffad6d52d52a4c064991
parent088ab2e68689bd63a28b1caee277739a8b923c91 (diff)
downloadredmine-23974fb0cede44d69db1c31ef7cd7296bdb2bc90.tar.gz
redmine-23974fb0cede44d69db1c31ef7cd7296bdb2bc90.zip
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
-rw-r--r--app/models/setting.rb4
-rw-r--r--test/unit/setting_test.rb14
2 files changed, 17 insertions, 1 deletions
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 444f45e20..b7a2a9b32 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -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 = {}
diff --git a/test/unit/setting_test.rb b/test/unit/setting_test.rb
index fa0a6192c..d3058f51c 100644
--- a/test/unit/setting_test.rb
+++ b/test/unit/setting_test.rb
@@ -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