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