You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings_controller_test.rb 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class SettingsControllerTest < ActionController::TestCase
  19. fixtures :users
  20. def setup
  21. User.current = nil
  22. @request.session[:user_id] = 1 # admin
  23. end
  24. def test_index
  25. get :index
  26. assert_response :success
  27. assert_template 'edit'
  28. end
  29. def test_get_edit
  30. get :edit
  31. assert_response :success
  32. assert_template 'edit'
  33. assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''}
  34. end
  35. def test_get_edit_should_preselect_default_issue_list_columns
  36. with_settings :issue_list_default_columns => %w(tracker subject status updated_on) do
  37. get :edit
  38. assert_response :success
  39. end
  40. assert_select 'select[id=selected_columns][name=?]', 'settings[issue_list_default_columns][]' do
  41. assert_select 'option', 4
  42. assert_select 'option[value=tracker]', :text => 'Tracker'
  43. assert_select 'option[value=subject]', :text => 'Subject'
  44. assert_select 'option[value=status]', :text => 'Status'
  45. assert_select 'option[value=updated_on]', :text => 'Updated'
  46. end
  47. assert_select 'select[id=available_columns]' do
  48. assert_select 'option[value=tracker]', 0
  49. assert_select 'option[value=priority]', :text => 'Priority'
  50. end
  51. end
  52. def test_get_edit_without_trackers_should_succeed
  53. Tracker.delete_all
  54. get :edit
  55. assert_response :success
  56. end
  57. def test_post_edit_notifications
  58. post :edit, :settings => {:mail_from => 'functional@test.foo',
  59. :bcc_recipients => '0',
  60. :notified_events => %w(issue_added issue_updated news_added),
  61. :emails_footer => 'Test footer'
  62. }
  63. assert_redirected_to '/settings'
  64. assert_equal 'functional@test.foo', Setting.mail_from
  65. assert !Setting.bcc_recipients?
  66. assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
  67. assert_equal 'Test footer', Setting.emails_footer
  68. Setting.clear_cache
  69. end
  70. def test_edit_commit_update_keywords
  71. with_settings :commit_update_keywords => [
  72. {"keywords" => "fixes, resolves", "status_id" => "3"},
  73. {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"}
  74. ] do
  75. get :edit
  76. end
  77. assert_response :success
  78. assert_select 'tr.commit-keywords', 2
  79. assert_select 'tr.commit-keywords:nth-child(1)' do
  80. assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'fixes, resolves'
  81. assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do
  82. assert_select 'option[value=3][selected=selected]'
  83. end
  84. end
  85. assert_select 'tr.commit-keywords:nth-child(2)' do
  86. assert_select 'input[name=?][value=?]', 'settings[commit_update_keywords][keywords][]', 'closes'
  87. assert_select 'select[name=?]', 'settings[commit_update_keywords][status_id][]' do
  88. assert_select 'option[value=5][selected=selected]', :text => 'Closed'
  89. end
  90. assert_select 'select[name=?]', 'settings[commit_update_keywords][done_ratio][]' do
  91. assert_select 'option[value=100][selected=selected]', :text => '100 %'
  92. end
  93. assert_select 'select[name=?]', 'settings[commit_update_keywords][if_tracker_id][]' do
  94. assert_select 'option[value=2][selected=selected]', :text => 'Feature request'
  95. end
  96. end
  97. end
  98. def test_edit_without_commit_update_keywords_should_show_blank_line
  99. with_settings :commit_update_keywords => [] do
  100. get :edit
  101. end
  102. assert_response :success
  103. assert_select 'tr.commit-keywords', 1 do
  104. assert_select 'input[name=?]:not([value])', 'settings[commit_update_keywords][keywords][]'
  105. end
  106. end
  107. def test_post_edit_commit_update_keywords
  108. post :edit, :settings => {
  109. :commit_update_keywords => {
  110. :keywords => ["resolves", "closes"],
  111. :status_id => ["3", "5"],
  112. :done_ratio => ["", "100"],
  113. :if_tracker_id => ["", "2"]
  114. }
  115. }
  116. assert_redirected_to '/settings'
  117. assert_equal([
  118. {"keywords" => "resolves", "status_id" => "3"},
  119. {"keywords" => "closes", "status_id" => "5", "done_ratio" => "100", "if_tracker_id" => "2"}
  120. ], Setting.commit_update_keywords)
  121. end
  122. def test_get_plugin_settings
  123. Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'})
  124. ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
  125. Redmine::Plugin.register :foo do
  126. settings :partial => "foo_plugin/foo_plugin_settings"
  127. end
  128. get :plugin, :id => 'foo'
  129. assert_response :success
  130. assert_template 'plugin'
  131. assert_tag 'form', :attributes => {:action => '/settings/plugin/foo'},
  132. :descendant => {:tag => 'input', :attributes => {:name => 'settings[sample_setting]', :value => 'Plugin setting value'}}
  133. Redmine::Plugin.clear
  134. end
  135. def test_get_invalid_plugin_settings
  136. get :plugin, :id => 'none'
  137. assert_response 404
  138. end
  139. def test_get_non_configurable_plugin_settings
  140. Redmine::Plugin.register(:foo) {}
  141. get :plugin, :id => 'foo'
  142. assert_response 404
  143. Redmine::Plugin.clear
  144. end
  145. def test_post_plugin_settings
  146. Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true)
  147. Redmine::Plugin.register(:foo) do
  148. settings :partial => 'not blank' # so that configurable? is true
  149. end
  150. post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
  151. assert_redirected_to '/settings/plugin/foo'
  152. end
  153. def test_post_non_configurable_plugin_settings
  154. Redmine::Plugin.register(:foo) {}
  155. post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
  156. assert_response 404
  157. Redmine::Plugin.clear
  158. end
  159. end