@@ -1,66 +1,71 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 | class SettingsController < ApplicationController |
|
19 | 19 | layout 'admin' |
|
20 | 20 | menu_item :plugins, :only => :plugin |
|
21 | 21 | |
|
22 | 22 | before_filter :require_admin |
|
23 | 23 | |
|
24 | 24 | def index |
|
25 | 25 | edit |
|
26 | 26 | render :action => 'edit' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def edit |
|
30 | 30 | @notifiables = Redmine::Notifiable.all |
|
31 | 31 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) |
|
32 | 32 | settings = (params[:settings] || {}).dup.symbolize_keys |
|
33 | 33 | settings.each do |name, value| |
|
34 | 34 | # remove blank values in array settings |
|
35 | 35 | value.delete_if {|v| v.blank? } if value.is_a?(Array) |
|
36 | 36 | Setting[name] = value |
|
37 | 37 | end |
|
38 | 38 | flash[:notice] = l(:notice_successful_update) |
|
39 | 39 | redirect_to settings_path(:tab => params[:tab]) |
|
40 | 40 | else |
|
41 | 41 | @options = {} |
|
42 | 42 | user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]} |
|
43 | 43 | @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]} |
|
44 | 44 | @deliveries = ActionMailer::Base.perform_deliveries |
|
45 | 45 | |
|
46 | 46 | @guessed_host_and_path = request.host_with_port.dup |
|
47 | 47 | @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank? |
|
48 | 48 | |
|
49 | 49 | Redmine::Themes.rescan |
|
50 | 50 | end |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def plugin |
|
54 | 54 | @plugin = Redmine::Plugin.find(params[:id]) |
|
55 | unless @plugin.configurable? | |
|
56 | render_404 | |
|
57 | return | |
|
58 | end | |
|
59 | ||
|
55 | 60 | if request.post? |
|
56 | 61 | Setting.send "plugin_#{@plugin.id}=", params[:settings] |
|
57 | 62 | flash[:notice] = l(:notice_successful_update) |
|
58 | 63 | redirect_to plugin_settings_path(@plugin) |
|
59 | 64 | else |
|
60 | 65 | @partial = @plugin.settings[:partial] |
|
61 | 66 | @settings = Setting.send "plugin_#{@plugin.id}" |
|
62 | 67 | end |
|
63 | 68 | rescue Redmine::PluginNotFound |
|
64 | 69 | render_404 |
|
65 | 70 | end |
|
66 | 71 | end |
@@ -1,111 +1,131 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 SettingsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :users |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | @request.session[:user_id] = 1 # admin |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_template 'edit' |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_get_edit |
|
35 | 35 | get :edit |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_template 'edit' |
|
38 | 38 | |
|
39 | 39 | assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''} |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_get_edit_should_preselect_default_issue_list_columns |
|
43 | 43 | with_settings :issue_list_default_columns => %w(tracker subject status updated_on) do |
|
44 | 44 | get :edit |
|
45 | 45 | assert_response :success |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | assert_select 'select[id=selected_columns][name=?]', 'settings[issue_list_default_columns][]' do |
|
49 | 49 | assert_select 'option', 4 |
|
50 | 50 | assert_select 'option[value=tracker]', :text => 'Tracker' |
|
51 | 51 | assert_select 'option[value=subject]', :text => 'Subject' |
|
52 | 52 | assert_select 'option[value=status]', :text => 'Status' |
|
53 | 53 | assert_select 'option[value=updated_on]', :text => 'Updated' |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | assert_select 'select[id=available_columns]' do |
|
57 | 57 | assert_select 'option[value=tracker]', 0 |
|
58 | 58 | assert_select 'option[value=priority]', :text => 'Priority' |
|
59 | 59 | end |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_get_edit_without_trackers_should_succeed |
|
63 | 63 | Tracker.delete_all |
|
64 | 64 | |
|
65 | 65 | get :edit |
|
66 | 66 | assert_response :success |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_post_edit_notifications |
|
70 | 70 | post :edit, :settings => {:mail_from => 'functional@test.foo', |
|
71 | 71 | :bcc_recipients => '0', |
|
72 | 72 | :notified_events => %w(issue_added issue_updated news_added), |
|
73 | 73 | :emails_footer => 'Test footer' |
|
74 | 74 | } |
|
75 | 75 | assert_redirected_to '/settings' |
|
76 | 76 | assert_equal 'functional@test.foo', Setting.mail_from |
|
77 | 77 | assert !Setting.bcc_recipients? |
|
78 | 78 | assert_equal %w(issue_added issue_updated news_added), Setting.notified_events |
|
79 | 79 | assert_equal 'Test footer', Setting.emails_footer |
|
80 | 80 | Setting.clear_cache |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def test_get_plugin_settings |
|
84 | 84 | Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'}) |
|
85 | 85 | ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins")) |
|
86 | 86 | Redmine::Plugin.register :foo do |
|
87 | 87 | settings :partial => "foo_plugin/foo_plugin_settings" |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | get :plugin, :id => 'foo' |
|
91 | 91 | assert_response :success |
|
92 | 92 | assert_template 'plugin' |
|
93 | 93 | assert_tag 'form', :attributes => {:action => '/settings/plugin/foo'}, |
|
94 | 94 | :descendant => {:tag => 'input', :attributes => {:name => 'settings[sample_setting]', :value => 'Plugin setting value'}} |
|
95 | 95 | |
|
96 | 96 | Redmine::Plugin.clear |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | def test_get_invalid_plugin_settings |
|
100 | 100 | get :plugin, :id => 'none' |
|
101 | 101 | assert_response 404 |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | def test_get_non_configurable_plugin_settings | |
|
105 | Redmine::Plugin.register(:foo) {} | |
|
106 | ||
|
107 | get :plugin, :id => 'foo' | |
|
108 | assert_response 404 | |
|
109 | ||
|
110 | Redmine::Plugin.clear | |
|
111 | end | |
|
112 | ||
|
104 | 113 | def test_post_plugin_settings |
|
105 | 114 | Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true) |
|
106 |
Redmine::Plugin.register(:foo) |
|
|
115 | Redmine::Plugin.register(:foo) do | |
|
116 | settings :partial => 'not blank' # so that configurable? is true | |
|
117 | end | |
|
107 | 118 | |
|
108 | 119 | post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'} |
|
109 | 120 | assert_redirected_to '/settings/plugin/foo' |
|
110 | 121 | end |
|
122 | ||
|
123 | def test_post_non_configurable_plugin_settings | |
|
124 | Redmine::Plugin.register(:foo) {} | |
|
125 | ||
|
126 | post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'} | |
|
127 | assert_response 404 | |
|
128 | ||
|
129 | Redmine::Plugin.clear | |
|
130 | end | |
|
111 | 131 | end |
General Comments 0
You need to be logged in to leave comments.
Login now