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