To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / aa / aaf905ee3518e0c52f64e7a528de1f2b7f2001eb.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (4.07 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  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
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
24
class SettingsControllerTest < ActionController::TestCase
25
  fixtures :users
26
27
  def setup
28
    @controller = SettingsController.new
29
    @request    = ActionController::TestRequest.new
30
    @response   = ActionController::TestResponse.new
31
    User.current = nil
32
    @request.session[:user_id] = 1 # admin
33
  end
34
35
  def test_index
36
    get :index
37
    assert_response :success
38
    assert_template 'edit'
39
  end
40
41
  def test_get_edit
42
    get :edit
43
    assert_response :success
44
    assert_template 'edit'
45
46
    assert_tag 'input', :attributes => {:name => 'settings[enabled_scm][]', :value => ''}
47
  end
48
49
  def test_get_edit_should_preselect_default_issue_list_columns
50
    with_settings :issue_list_default_columns => %w(tracker subject status updated_on) do
51
      get :edit
52
      assert_response :success
53
    end
54
55
    assert_select 'select[id=selected_columns][name=?]', 'settings[issue_list_default_columns][]' do
56
      assert_select 'option', 4
57
      assert_select 'option[value=tracker]', :text => 'Tracker'
58
      assert_select 'option[value=subject]', :text => 'Subject'
59
      assert_select 'option[value=status]', :text => 'Status'
60
      assert_select 'option[value=updated_on]', :text => 'Updated'
61
    end
62
63
    assert_select 'select[id=available_columns]' do
64
      assert_select 'option[value=tracker]', 0
65
      assert_select 'option[value=priority]', :text => 'Priority'
66
    end
67
  end
68
69
  def test_get_edit_without_trackers_should_succeed
70
    Tracker.delete_all
71
72
    get :edit
73
    assert_response :success
74
  end
75
76
  def test_post_edit_notifications
77
    post :edit, :settings => {:mail_from => 'functional@test.foo',
78
                              :bcc_recipients  => '0',
79
                              :notified_events => %w(issue_added issue_updated news_added),
80
                              :emails_footer => 'Test footer'
81
                              }
82
    assert_redirected_to '/settings/edit'
83
    assert_equal 'functional@test.foo', Setting.mail_from
84
    assert !Setting.bcc_recipients?
85
    assert_equal %w(issue_added issue_updated news_added), Setting.notified_events
86
    assert_equal 'Test footer', Setting.emails_footer
87
    Setting.clear_cache
88
  end
89
90
  def test_get_plugin_settings
91
    Setting.stubs(:plugin_foo).returns({'sample_setting' => 'Plugin setting value'})
92
    ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
93
    Redmine::Plugin.register :foo do
94
      settings :partial => "foo_plugin/foo_plugin_settings"
95
    end
96
97
    get :plugin, :id => 'foo'
98
    assert_response :success
99
    assert_template 'plugin'
100
    assert_tag 'form', :attributes => {:action => '/settings/plugin/foo'},
101
      :descendant => {:tag => 'input', :attributes => {:name => 'settings[sample_setting]', :value => 'Plugin setting value'}}
102
103
    Redmine::Plugin.clear
104
  end
105
106
  def test_get_invalid_plugin_settings
107
    get :plugin, :id => 'none'
108
    assert_response 404
109
  end
110
111
  def test_post_plugin_settings
112
    Setting.expects(:plugin_foo=).with({'sample_setting' => 'Value'}).returns(true)
113
    Redmine::Plugin.register(:foo) {}
114
115
    post :plugin, :id => 'foo', :settings => {'sample_setting' => 'Value'}
116
    assert_redirected_to '/settings/plugin/foo'
117
  end
118
end