1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
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.
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.
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.
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'my_controller'
21 # Re-raise errors caught by the controller.
22 class MyController; def rescue_action(e) raise e end; end
24 class MyControllerTest < ActionController::TestCase
25 fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields
28 @controller = MyController.new
29 @request = ActionController::TestRequest.new
30 @request.session[:user_id] = 2
31 @response = ActionController::TestResponse.new
36 assert_response :success
37 assert_template 'page'
42 assert_response :success
43 assert_template 'page'
46 def test_my_account_should_show_editable_custom_fields
48 assert_response :success
49 assert_template 'account'
50 assert_equal User.find(2), assigns(:user)
52 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
55 def test_my_account_should_not_show_non_editable_custom_fields
56 UserCustomField.find(4).update_attribute :editable, false
59 assert_response :success
60 assert_template 'account'
61 assert_equal User.find(2), assigns(:user)
63 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
66 def test_update_account
67 post :account, :user => {:firstname => "Joe",
70 :custom_field_values => {"4" => "0100562500"}}
71 assert_redirected_to 'my/account'
73 assert_equal user, assigns(:user)
74 assert_equal "Joe", user.firstname
75 assert_equal "jsmith", user.login
76 assert_equal "0100562500", user.custom_value_for(4).value
80 def test_change_password
82 assert_response :success
83 assert_template 'password'
85 # non matching password confirmation
86 post :password, :password => 'jsmith',
87 :new_password => 'hello',
88 :new_password_confirmation => 'hello2'
89 assert_response :success
90 assert_template 'password'
91 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
94 post :password, :password => 'wrongpassword',
95 :new_password => 'hello',
96 :new_password_confirmation => 'hello'
97 assert_response :success
98 assert_template 'password'
99 assert_equal 'Wrong password', flash[:error]
102 post :password, :password => 'jsmith',
103 :new_password => 'hello',
104 :new_password_confirmation => 'hello'
105 assert_redirected_to 'my/account'
106 assert User.try_to_login('jsmith', 'hello')
111 assert_response :success
112 assert_template 'page_layout'
116 xhr :post, :add_block, :block => 'issuesreportedbyme'
117 assert_response :success
118 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
121 def test_remove_block
122 xhr :post, :remove_block, :block => 'issuesassignedtome'
123 assert_response :success
124 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
127 def test_order_blocks
128 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
129 assert_response :success
130 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
133 context "POST to reset_rss_key" do
134 context "with an existing rss_token" do
136 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
140 should "destroy the existing token" do
141 assert_not_equal @previous_token_value, User.find(2).rss_key
144 should "create a new token" do
145 assert User.find(2).rss_token
148 should_set_the_flash_to /reset/
149 should_redirect_to('my account') {'/my/account' }
152 context "with no rss_token" do
154 assert_nil User.find(2).rss_token
158 should "create a new token" do
159 assert User.find(2).rss_token
162 should_set_the_flash_to /reset/
163 should_redirect_to('my account') {'/my/account' }
167 context "POST to reset_api_key" do
168 context "with an existing api_token" do
170 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
174 should "destroy the existing token" do
175 assert_not_equal @previous_token_value, User.find(2).api_key
178 should "create a new token" do
179 assert User.find(2).api_token
182 should_set_the_flash_to /reset/
183 should_redirect_to('my account') {'/my/account' }
186 context "with no api_token" do
188 assert_nil User.find(2).api_token
192 should "create a new token" do
193 assert User.find(2).api_token
196 should_set_the_flash_to /reset/
197 should_redirect_to('my account') {'/my/account' }