Mercurial > hg > soundsoftware-site
comparison test/functional/settings_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | e248c7af89ec |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 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. |
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 require 'settings_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class SettingsController; def rescue_action(e) raise e end; end | |
23 | 19 |
24 class SettingsControllerTest < ActionController::TestCase | 20 class SettingsControllerTest < ActionController::TestCase |
25 fixtures :users | 21 fixtures :users |
26 | 22 |
27 def setup | 23 def setup |
28 @controller = SettingsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | 24 User.current = nil |
32 @request.session[:user_id] = 1 # admin | 25 @request.session[:user_id] = 1 # admin |
33 end | 26 end |
34 | 27 |
35 def test_index | 28 def test_index |
77 post :edit, :settings => {:mail_from => 'functional@test.foo', | 70 post :edit, :settings => {:mail_from => 'functional@test.foo', |
78 :bcc_recipients => '0', | 71 :bcc_recipients => '0', |
79 :notified_events => %w(issue_added issue_updated news_added), | 72 :notified_events => %w(issue_added issue_updated news_added), |
80 :emails_footer => 'Test footer' | 73 :emails_footer => 'Test footer' |
81 } | 74 } |
82 assert_redirected_to '/settings/edit' | 75 assert_redirected_to '/settings' |
83 assert_equal 'functional@test.foo', Setting.mail_from | 76 assert_equal 'functional@test.foo', Setting.mail_from |
84 assert !Setting.bcc_recipients? | 77 assert !Setting.bcc_recipients? |
85 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events | 78 assert_equal %w(issue_added issue_updated news_added), Setting.notified_events |
86 assert_equal 'Test footer', Setting.emails_footer | 79 assert_equal 'Test footer', Setting.emails_footer |
87 Setting.clear_cache | 80 Setting.clear_cache |
81 end | |
82 | |
83 def test_edit_commit_update_keywords | |
84 with_settings :commit_update_keywords => [ | |
85 {"keywords" => "fixes, resolves", "status_id" => "3"}, | |
86 {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"} | |
87 ] do | |
88 get :edit | |
89 end | |
90 assert_response :success | |
91 assert_select 'tr.commit-keywords', 2 | |
92 assert_select 'tr.commit-keywords:nth-child(1)' do | |
93 assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'fixes, resolves' | |
94 assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do | |
95 assert_select 'option[value=3][selected=selected]' | |
96 end | |
97 end | |
98 assert_select 'tr.commit-keywords:nth-child(2)' do | |
99 assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'closes' | |
100 assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do | |
101 assert_select 'option[value=5][selected=selected]', :text => 'Closed' | |
102 end | |
103 assert_select 'select[name=?]', 'settings[commit_update_keywords][done_ratio][]' do | |
104 assert_select 'option[value=100][selected=selected]', :text => '100 %' | |
105 end | |
106 assert_select 'select[name=?]', 'settings[commit_update_keywords][if_tracker_id][]' do | |
107 assert_select 'option[value=2][selected=selected]', :text => 'Feature request' | |
108 end | |
109 end | |
110 end | |
111 | |
112 def test_edit_without_commit_update_keywords_should_show_blank_line | |
113 with_settings :commit_update_keywords => [] do | |
114 get :edit | |
115 end | |
116 assert_response :success | |
117 assert_select 'tr.commit-keywords', 1 do | |
118 assert_select 'input[name=?]:not([value])', 'settings[commit_update_keywords][keywords][]' | |
119 end | |
120 end | |
121 | |
122 def test_post_edit_commit_update_keywords | |
123 post :edit, :settings => { | |
124 :commit_update_keywords => { | |
125 :keywords => ["resolves", "closes"], | |
126 :status_id => ["3", "5"], | |
127 :done_ratio => ["", "100"], | |
128 :if_tracker_id => ["", "2"] | |
129 } | |
130 } | |
131 assert_redirected_to '/settings' | |
132 assert_equal([ | |
133 {"keywords" => "resolves", "status_id" => "3"}, | |
134 {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"} | |
135 ], Setting.commit_update_keywords) | |
88 end | 136 end |
89 | 137 |
90 def test_get_plugin_settings | 138 def test_get_plugin_settings |
91 Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'}) | 139 Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'}) |
92 ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins")) | 140 ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins")) |
106 def test_get_invalid_plugin_settings | 154 def test_get_invalid_plugin_settings |
107 get :plugin, :id => 'none' | 155 get :plugin, :id => 'none' |
108 assert_response 404 | 156 assert_response 404 |
109 end | 157 end |
110 | 158 |
159 def test_get_non_configurable_plugin_settings | |
160 Redmine::Plugin.register(:foo) {} | |
161 | |
162 get :plugin, :id => 'foo' | |
163 assert_response 404 | |
164 | |
165 Redmine::Plugin.clear | |
166 end | |
167 | |
111 def test_post_plugin_settings | 168 def test_post_plugin_settings |
112 Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true) | 169 Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true) |
113 Redmine::Plugin.register(:foo) {} | 170 Redmine::Plugin.register(:foo) do |
171 settings :partial => 'not blank' # so that configurable? is true | |
172 end | |
114 | 173 |
115 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'} | 174 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'} |
116 assert_redirected_to '/settings/plugin/foo' | 175 assert_redirected_to '/settings/plugin/foo' |
117 end | 176 end |
177 | |
178 def test_post_non_configurable_plugin_settings | |
179 Redmine::Plugin.register(:foo) {} | |
180 | |
181 post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'} | |
182 assert_response 404 | |
183 | |
184 Redmine::Plugin.clear | |
185 end | |
118 end | 186 end |