@@ -1,178 +1,164 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class AdminControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :roles |
|
22 | 22 | |
|
23 | class TestDelivery | |
|
24 | def initialize(*) | |
|
25 | end | |
|
26 | ||
|
27 | def deliver!(mail) | |
|
28 | raise 'Some error message' | |
|
29 | end | |
|
30 | end | |
|
31 | ||
|
32 | 23 | def setup |
|
33 | 24 | User.current = nil |
|
34 | 25 | @request.session[:user_id] = 1 # admin |
|
35 | @old_delivery_method = ActionMailer::Base.delivery_method | |
|
36 | end | |
|
37 | ||
|
38 | def teardown | |
|
39 | ActionMailer::Base.delivery_method = @old_delivery_method | |
|
40 | 26 | end |
|
41 | 27 | |
|
42 | 28 | def test_index |
|
43 | 29 | get :index |
|
44 | 30 | assert_no_tag :tag => 'div', |
|
45 | 31 | :attributes => { :class => /nodata/ } |
|
46 | 32 | end |
|
47 | 33 | |
|
48 | 34 | def test_index_with_no_configuration_data |
|
49 | 35 | delete_configuration_data |
|
50 | 36 | get :index |
|
51 | 37 | assert_tag :tag => 'div', |
|
52 | 38 | :attributes => { :class => /nodata/ } |
|
53 | 39 | end |
|
54 | 40 | |
|
55 | 41 | def test_projects |
|
56 | 42 | get :projects |
|
57 | 43 | assert_response :success |
|
58 | 44 | assert_template 'projects' |
|
59 | 45 | assert_not_nil assigns(:projects) |
|
60 | 46 | # active projects only |
|
61 | 47 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
62 | 48 | end |
|
63 | 49 | |
|
64 | 50 | def test_projects_with_status_filter |
|
65 | 51 | get :projects, :status => 1 |
|
66 | 52 | assert_response :success |
|
67 | 53 | assert_template 'projects' |
|
68 | 54 | assert_not_nil assigns(:projects) |
|
69 | 55 | # active projects only |
|
70 | 56 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
71 | 57 | end |
|
72 | 58 | |
|
73 | 59 | def test_projects_with_name_filter |
|
74 | 60 | get :projects, :name => 'store', :status => '' |
|
75 | 61 | assert_response :success |
|
76 | 62 | assert_template 'projects' |
|
77 | 63 | projects = assigns(:projects) |
|
78 | 64 | assert_not_nil projects |
|
79 | 65 | assert_equal 1, projects.size |
|
80 | 66 | assert_equal 'OnlineStore', projects.first.name |
|
81 | 67 | end |
|
82 | 68 | |
|
83 | 69 | def test_load_default_configuration_data |
|
84 | 70 | delete_configuration_data |
|
85 | 71 | post :default_configuration, :lang => 'fr' |
|
86 | 72 | assert_response :redirect |
|
87 | 73 | assert_nil flash[:error] |
|
88 | 74 | assert IssueStatus.find_by_name('Nouveau') |
|
89 | 75 | end |
|
90 | 76 | |
|
91 | 77 | def test_load_default_configuration_data_should_rescue_error |
|
92 | 78 | delete_configuration_data |
|
93 | 79 | Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong")) |
|
94 | 80 | post :default_configuration, :lang => 'fr' |
|
95 | 81 | assert_response :redirect |
|
96 | 82 | assert_not_nil flash[:error] |
|
97 | 83 | assert_match /Something went wrong/, flash[:error] |
|
98 | 84 | end |
|
99 | 85 | |
|
100 | 86 | def test_test_email |
|
101 | 87 | user = User.find(1) |
|
102 | 88 | user.pref[:no_self_notified] = '1' |
|
103 | 89 | user.pref.save! |
|
104 | 90 | ActionMailer::Base.deliveries.clear |
|
105 | 91 | |
|
106 | 92 | get :test_email |
|
107 | 93 | assert_redirected_to '/settings/edit?tab=notifications' |
|
108 | 94 | mail = ActionMailer::Base.deliveries.last |
|
109 | 95 | assert_not_nil mail |
|
110 | 96 | user = User.find(1) |
|
111 | 97 | assert_equal [user.mail], mail.bcc |
|
112 | 98 | end |
|
113 | 99 | |
|
114 | 100 | def test_test_email_failure_should_display_the_error |
|
115 | ActionMailer::Base.delivery_method = TestDelivery | |
|
101 | Mailer.stubs(:test_email).raises(Exception, 'Some error message') | |
|
116 | 102 | get :test_email |
|
117 | 103 | assert_redirected_to '/settings/edit?tab=notifications' |
|
118 | 104 | assert_match /Some error message/, flash[:error] |
|
119 | 105 | end |
|
120 | 106 | |
|
121 | 107 | def test_no_plugins |
|
122 | 108 | Redmine::Plugin.clear |
|
123 | 109 | |
|
124 | 110 | get :plugins |
|
125 | 111 | assert_response :success |
|
126 | 112 | assert_template 'plugins' |
|
127 | 113 | end |
|
128 | 114 | |
|
129 | 115 | def test_plugins |
|
130 | 116 | # Register a few plugins |
|
131 | 117 | Redmine::Plugin.register :foo do |
|
132 | 118 | name 'Foo plugin' |
|
133 | 119 | author 'John Smith' |
|
134 | 120 | description 'This is a test plugin' |
|
135 | 121 | version '0.0.1' |
|
136 | 122 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
137 | 123 | end |
|
138 | 124 | Redmine::Plugin.register :bar do |
|
139 | 125 | end |
|
140 | 126 | |
|
141 | 127 | get :plugins |
|
142 | 128 | assert_response :success |
|
143 | 129 | assert_template 'plugins' |
|
144 | 130 | |
|
145 | 131 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
146 | 132 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
147 | 133 | end |
|
148 | 134 | |
|
149 | 135 | def test_info |
|
150 | 136 | get :info |
|
151 | 137 | assert_response :success |
|
152 | 138 | assert_template 'info' |
|
153 | 139 | end |
|
154 | 140 | |
|
155 | 141 | def test_admin_menu_plugin_extension |
|
156 | 142 | Redmine::MenuManager.map :admin_menu do |menu| |
|
157 | 143 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' |
|
158 | 144 | end |
|
159 | 145 | |
|
160 | 146 | get :index |
|
161 | 147 | assert_response :success |
|
162 | 148 | assert_tag :a, :attributes => { :href => '/foo/bar' }, |
|
163 | 149 | :content => 'Test' |
|
164 | 150 | |
|
165 | 151 | Redmine::MenuManager.map :admin_menu do |menu| |
|
166 | 152 | menu.delete :test_admin_menu_plugin_extension |
|
167 | 153 | end |
|
168 | 154 | end |
|
169 | 155 | |
|
170 | 156 | private |
|
171 | 157 | |
|
172 | 158 | def delete_configuration_data |
|
173 | 159 | Role.delete_all('builtin = 0') |
|
174 | 160 | Tracker.delete_all |
|
175 | 161 | IssueStatus.delete_all |
|
176 | 162 | Enumeration.delete_all |
|
177 | 163 | end |
|
178 | 164 | end |
General Comments 0
You need to be logged in to leave comments.
Login now