@@ -83,7 +83,9 class Setting < ActiveRecord::Base | |||
|
83 | 83 | |
|
84 | 84 | validates_uniqueness_of :name |
|
85 | 85 | validates_inclusion_of :name, :in => @@available_settings.keys |
|
86 |
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| |
|
|
86 | validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| | |
|
87 | (s = @@available_settings[setting.name]) && s['format'] == 'int' | |
|
88 | } | |
|
87 | 89 | |
|
88 | 90 | # Hash used to cache setting values |
|
89 | 91 | @cached_settings = {} |
@@ -41,6 +41,20 class SettingTest < ActiveSupport::TestCase | |||
|
41 | 41 | assert_equal "My other title", Setting.find_by_name('app_title').value |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | def test_setting_with_int_format_should_accept_numeric_only | |
|
45 | with_settings :session_timeout => 30 do | |
|
46 | Setting.session_timeout = 'foo' | |
|
47 | assert_equal "30", Setting.session_timeout | |
|
48 | Setting.session_timeout = 40 | |
|
49 | assert_equal "40", Setting.session_timeout | |
|
50 | end | |
|
51 | end | |
|
52 | ||
|
53 | def test_setting_with_invalid_name_should_be_valid | |
|
54 | setting = Setting.new(:name => "does_not_exist", :value => "should_not_be_allowed") | |
|
55 | assert !setting.save | |
|
56 | end | |
|
57 | ||
|
44 | 58 | def test_serialized_setting |
|
45 | 59 | Setting.notified_events = ['issue_added', 'issue_updated', 'news_added'] |
|
46 | 60 | assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events |
General Comments 0
You need to be logged in to leave comments.
Login now