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