##// END OF EJS Templates
2.6-stable: fix unit test on Ruby 1.8.7 (#19305)...
Toshi MARUYAMA -
r13737:e580d565eb55
parent child
Show More
@@ -1,127 +1,128
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 22 class SettingTest < ActiveSupport::TestCase
23 23
24 24 def teardown
25 25 Setting.clear_cache
26 26 end
27 27
28 28 def test_read_default
29 29 assert_equal "Redmine", Setting.app_title
30 30 assert Setting.self_registration?
31 31 assert !Setting.login_required?
32 32 end
33 33
34 34 def test_update
35 35 Setting.app_title = "My title"
36 36 assert_equal "My title", Setting.app_title
37 37 # make sure db has been updated (INSERT)
38 38 assert_equal "My title", Setting.find_by_name('app_title').value
39 39
40 40 Setting.app_title = "My other title"
41 41 assert_equal "My other title", Setting.app_title
42 42 # make sure db has been updated (UPDATE)
43 43 assert_equal "My other title", Setting.find_by_name('app_title').value
44 44 end
45 45
46 46 def test_setting_with_int_format_should_accept_numeric_only
47 47 with_settings :session_timeout => 30 do
48 48 Setting.session_timeout = 'foo'
49 49 assert_equal "30", Setting.session_timeout
50 50 Setting.session_timeout = 40
51 51 assert_equal "40", Setting.session_timeout
52 52 end
53 53 end
54 54
55 55 def test_setting_with_invalid_name_should_be_valid
56 56 setting = Setting.new(:name => "does_not_exist", :value => "should_not_be_allowed")
57 57 assert !setting.save
58 58 end
59 59
60 60 def test_serialized_setting
61 61 Setting.notified_events = ['issue_added', 'issue_updated', 'news_added']
62 62 assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events
63 63 assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.find_by_name('notified_events').value
64 64 end
65 65
66 66 def test_setting_should_be_reloaded_after_clear_cache
67 67 Setting.app_title = "My title"
68 68 assert_equal "My title", Setting.app_title
69 69
70 70 s = Setting.find_by_name("app_title")
71 71 s.value = 'New title'
72 72 s.save!
73 73 assert_equal "My title", Setting.app_title
74 74
75 75 Setting.clear_cache
76 76 assert_equal "New title", Setting.app_title
77 77 end
78 78
79 79 def test_per_page_options_array_should_be_an_empty_array_when_setting_is_blank
80 80 with_settings :per_page_options => nil do
81 81 assert_equal [], Setting.per_page_options_array
82 82 end
83 83
84 84 with_settings :per_page_options => '' do
85 85 assert_equal [], Setting.per_page_options_array
86 86 end
87 87 end
88 88
89 89 def test_per_page_options_array_should_be_an_array_of_integers
90 90 with_settings :per_page_options => '10, 25, 50' do
91 91 assert_equal [10, 25, 50], Setting.per_page_options_array
92 92 end
93 93 end
94 94
95 95 def test_per_page_options_array_should_omit_non_numerial_values
96 96 with_settings :per_page_options => 'a, 25, 50' do
97 97 assert_equal [25, 50], Setting.per_page_options_array
98 98 end
99 99 end
100 100
101 101 def test_per_page_options_array_should_be_sorted
102 102 with_settings :per_page_options => '25, 10, 50' do
103 103 assert_equal [10, 25, 50], Setting.per_page_options_array
104 104 end
105 105 end
106 106
107 107 def test_setting_serialied_as_binary_should_be_loaded_as_utf8_encoded_strings
108 108 yaml = <<-YAML
109 109 ---
110 110 - keywords: !binary |
111 111 Zml4ZXMsY2xvc2VzLNC40YHQv9GA0LDQstC70LXQvdC+LNCz0L7RgtC+0LLQ
112 112 vizRgdC00LXQu9Cw0L3QvixmaXhlZA==
113 113
114 114 done_ratio: "100"
115 115 status_id: "5"
116 116 YAML
117 117
118 118 Setting.commit_update_keywords = {}
119 119 assert_equal 1, Setting.where(:name => 'commit_update_keywords').update_all(:value => yaml)
120 120 Setting.clear_cache
121
121 if "".respond_to?(:force_encoding)
122 122 assert_equal 'UTF-8', Setting.commit_update_keywords.first['keywords'].encoding.name
123 end
123 124 ensure
124 125 Setting.where(:name => 'commit_update_keywords').delete_all
125 126 Setting.clear_cache
126 127 end
127 128 end
General Comments 0
You need to be logged in to leave comments. Login now