@@ -1,127 +1,130 | |||
|
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 | Setting.delete_all | |
|
30 | Setting.clear_cache | |
|
31 | ||
|
29 | 32 | assert_equal "Redmine", Setting.app_title |
|
30 | 33 | assert Setting.self_registration? |
|
31 | 34 | assert !Setting.login_required? |
|
32 | 35 | end |
|
33 | 36 | |
|
34 | 37 | def test_update |
|
35 | 38 | Setting.app_title = "My title" |
|
36 | 39 | assert_equal "My title", Setting.app_title |
|
37 | 40 | # make sure db has been updated (INSERT) |
|
38 | 41 | assert_equal "My title", Setting.find_by_name('app_title').value |
|
39 | 42 | |
|
40 | 43 | Setting.app_title = "My other title" |
|
41 | 44 | assert_equal "My other title", Setting.app_title |
|
42 | 45 | # make sure db has been updated (UPDATE) |
|
43 | 46 | assert_equal "My other title", Setting.find_by_name('app_title').value |
|
44 | 47 | end |
|
45 | 48 | |
|
46 | 49 | def test_setting_with_int_format_should_accept_numeric_only |
|
47 | 50 | with_settings :session_timeout => 30 do |
|
48 | 51 | Setting.session_timeout = 'foo' |
|
49 | 52 | assert_equal "30", Setting.session_timeout |
|
50 | 53 | Setting.session_timeout = 40 |
|
51 | 54 | assert_equal "40", Setting.session_timeout |
|
52 | 55 | end |
|
53 | 56 | end |
|
54 | 57 | |
|
55 | 58 | def test_setting_with_invalid_name_should_be_valid |
|
56 | 59 | setting = Setting.new(:name => "does_not_exist", :value => "should_not_be_allowed") |
|
57 | 60 | assert !setting.save |
|
58 | 61 | end |
|
59 | 62 | |
|
60 | 63 | def test_serialized_setting |
|
61 | 64 | Setting.notified_events = ['issue_added', 'issue_updated', 'news_added'] |
|
62 | 65 | assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events |
|
63 | 66 | assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.find_by_name('notified_events').value |
|
64 | 67 | end |
|
65 | 68 | |
|
66 | 69 | def test_setting_should_be_reloaded_after_clear_cache |
|
67 | 70 | Setting.app_title = "My title" |
|
68 | 71 | assert_equal "My title", Setting.app_title |
|
69 | 72 | |
|
70 | 73 | s = Setting.find_by_name("app_title") |
|
71 | 74 | s.value = 'New title' |
|
72 | 75 | s.save! |
|
73 | 76 | assert_equal "My title", Setting.app_title |
|
74 | 77 | |
|
75 | 78 | Setting.clear_cache |
|
76 | 79 | assert_equal "New title", Setting.app_title |
|
77 | 80 | end |
|
78 | 81 | |
|
79 | 82 | def test_per_page_options_array_should_be_an_empty_array_when_setting_is_blank |
|
80 | 83 | with_settings :per_page_options => nil do |
|
81 | 84 | assert_equal [], Setting.per_page_options_array |
|
82 | 85 | end |
|
83 | 86 | |
|
84 | 87 | with_settings :per_page_options => '' do |
|
85 | 88 | assert_equal [], Setting.per_page_options_array |
|
86 | 89 | end |
|
87 | 90 | end |
|
88 | 91 | |
|
89 | 92 | def test_per_page_options_array_should_be_an_array_of_integers |
|
90 | 93 | with_settings :per_page_options => '10, 25, 50' do |
|
91 | 94 | assert_equal [10, 25, 50], Setting.per_page_options_array |
|
92 | 95 | end |
|
93 | 96 | end |
|
94 | 97 | |
|
95 | 98 | def test_per_page_options_array_should_omit_non_numerial_values |
|
96 | 99 | with_settings :per_page_options => 'a, 25, 50' do |
|
97 | 100 | assert_equal [25, 50], Setting.per_page_options_array |
|
98 | 101 | end |
|
99 | 102 | end |
|
100 | 103 | |
|
101 | 104 | def test_per_page_options_array_should_be_sorted |
|
102 | 105 | with_settings :per_page_options => '25, 10, 50' do |
|
103 | 106 | assert_equal [10, 25, 50], Setting.per_page_options_array |
|
104 | 107 | end |
|
105 | 108 | end |
|
106 | 109 | |
|
107 | 110 | def test_setting_serialied_as_binary_should_be_loaded_as_utf8_encoded_strings |
|
108 | 111 | yaml = <<-YAML |
|
109 | 112 | --- |
|
110 | 113 | - keywords: !binary | |
|
111 | 114 | Zml4ZXMsY2xvc2VzLNC40YHQv9GA0LDQstC70LXQvdC+LNCz0L7RgtC+0LLQ |
|
112 | 115 | vizRgdC00LXQu9Cw0L3QvixmaXhlZA== |
|
113 | 116 | |
|
114 | 117 | done_ratio: "100" |
|
115 | 118 | status_id: "5" |
|
116 | 119 | YAML |
|
117 | 120 | |
|
118 | 121 | Setting.commit_update_keywords = {} |
|
119 | 122 | assert_equal 1, Setting.where(:name => 'commit_update_keywords').update_all(:value => yaml) |
|
120 | 123 | Setting.clear_cache |
|
121 | 124 | |
|
122 | 125 | assert_equal 'UTF-8', Setting.commit_update_keywords.first['keywords'].encoding.name |
|
123 | 126 | ensure |
|
124 | 127 | Setting.where(:name => 'commit_update_keywords').delete_all |
|
125 | 128 | Setting.clear_cache |
|
126 | 129 | end |
|
127 | 130 | end |
General Comments 0
You need to be logged in to leave comments.
Login now