annotate test/functional/my_controller_test.rb @ 864:2465362d1b56 bug_145

Close obsolete branch bug_145
author Chris Cannam
date Wed, 11 May 2011 11:57:41 +0100
parents 94944d00e43c
children af80e5618e9b
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19 require 'my_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class MyController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class MyControllerTest < ActionController::TestCase
Chris@0 25 fixtures :users, :user_preferences, :roles, :projects, :issues, :issue_statuses, :trackers, :enumerations, :custom_fields
Chris@0 26
Chris@0 27 def setup
Chris@0 28 @controller = MyController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @request.session[:user_id] = 2
Chris@0 31 @response = ActionController::TestResponse.new
Chris@0 32 end
Chris@0 33
Chris@0 34 def test_index
Chris@0 35 get :index
Chris@0 36 assert_response :success
Chris@0 37 assert_template 'page'
Chris@0 38 end
Chris@0 39
Chris@0 40 def test_page
Chris@0 41 get :page
Chris@0 42 assert_response :success
Chris@0 43 assert_template 'page'
Chris@0 44 end
Chris@0 45
Chris@0 46 def test_my_account_should_show_editable_custom_fields
Chris@0 47 get :account
Chris@0 48 assert_response :success
Chris@0 49 assert_template 'account'
Chris@0 50 assert_equal User.find(2), assigns(:user)
Chris@0 51
Chris@0 52 assert_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
Chris@0 53 end
Chris@0 54
Chris@0 55 def test_my_account_should_not_show_non_editable_custom_fields
Chris@0 56 UserCustomField.find(4).update_attribute :editable, false
Chris@0 57
Chris@0 58 get :account
Chris@0 59 assert_response :success
Chris@0 60 assert_template 'account'
Chris@0 61 assert_equal User.find(2), assigns(:user)
Chris@0 62
Chris@0 63 assert_no_tag :input, :attributes => { :name => 'user[custom_field_values][4]'}
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_update_account
Chris@0 67 post :account, :user => {:firstname => "Joe",
Chris@0 68 :login => "root",
Chris@0 69 :admin => 1,
Chris@0 70 :custom_field_values => {"4" => "0100562500"}}
chris@37 71 assert_redirected_to '/my/account'
Chris@0 72 user = User.find(2)
Chris@0 73 assert_equal user, assigns(:user)
Chris@0 74 assert_equal "Joe", user.firstname
Chris@0 75 assert_equal "jsmith", user.login
Chris@0 76 assert_equal "0100562500", user.custom_value_for(4).value
Chris@0 77 assert !user.admin?
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_change_password
Chris@0 81 get :password
Chris@0 82 assert_response :success
Chris@0 83 assert_template 'password'
Chris@0 84
Chris@0 85 # non matching password confirmation
Chris@0 86 post :password, :password => 'jsmith',
Chris@0 87 :new_password => 'hello',
Chris@0 88 :new_password_confirmation => 'hello2'
Chris@0 89 assert_response :success
Chris@0 90 assert_template 'password'
Chris@0 91 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
Chris@0 92
Chris@0 93 # wrong password
Chris@0 94 post :password, :password => 'wrongpassword',
Chris@0 95 :new_password => 'hello',
Chris@0 96 :new_password_confirmation => 'hello'
Chris@0 97 assert_response :success
Chris@0 98 assert_template 'password'
Chris@0 99 assert_equal 'Wrong password', flash[:error]
Chris@0 100
Chris@0 101 # good password
Chris@0 102 post :password, :password => 'jsmith',
Chris@0 103 :new_password => 'hello',
Chris@0 104 :new_password_confirmation => 'hello'
chris@37 105 assert_redirected_to '/my/account'
Chris@0 106 assert User.try_to_login('jsmith', 'hello')
Chris@0 107 end
Chris@0 108
Chris@0 109 def test_page_layout
Chris@0 110 get :page_layout
Chris@0 111 assert_response :success
Chris@0 112 assert_template 'page_layout'
Chris@0 113 end
Chris@0 114
Chris@0 115 def test_add_block
Chris@0 116 xhr :post, :add_block, :block => 'issuesreportedbyme'
Chris@0 117 assert_response :success
Chris@0 118 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
Chris@0 119 end
Chris@0 120
Chris@0 121 def test_remove_block
Chris@0 122 xhr :post, :remove_block, :block => 'issuesassignedtome'
Chris@0 123 assert_response :success
Chris@0 124 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
Chris@0 125 end
Chris@0 126
Chris@0 127 def test_order_blocks
Chris@0 128 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
Chris@0 129 assert_response :success
Chris@0 130 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
Chris@0 131 end
Chris@0 132
Chris@0 133 context "POST to reset_rss_key" do
Chris@0 134 context "with an existing rss_token" do
Chris@0 135 setup do
Chris@0 136 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
Chris@0 137 post :reset_rss_key
Chris@0 138 end
Chris@0 139
Chris@0 140 should "destroy the existing token" do
Chris@0 141 assert_not_equal @previous_token_value, User.find(2).rss_key
Chris@0 142 end
Chris@0 143
Chris@0 144 should "create a new token" do
Chris@0 145 assert User.find(2).rss_token
Chris@0 146 end
Chris@0 147
Chris@0 148 should_set_the_flash_to /reset/
Chris@0 149 should_redirect_to('my account') {'/my/account' }
Chris@0 150 end
Chris@0 151
Chris@0 152 context "with no rss_token" do
Chris@0 153 setup do
Chris@0 154 assert_nil User.find(2).rss_token
Chris@0 155 post :reset_rss_key
Chris@0 156 end
Chris@0 157
Chris@0 158 should "create a new token" do
Chris@0 159 assert User.find(2).rss_token
Chris@0 160 end
Chris@0 161
Chris@0 162 should_set_the_flash_to /reset/
Chris@0 163 should_redirect_to('my account') {'/my/account' }
Chris@0 164 end
Chris@0 165 end
Chris@0 166
Chris@0 167 context "POST to reset_api_key" do
Chris@0 168 context "with an existing api_token" do
Chris@0 169 setup do
Chris@0 170 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
Chris@0 171 post :reset_api_key
Chris@0 172 end
Chris@0 173
Chris@0 174 should "destroy the existing token" do
Chris@0 175 assert_not_equal @previous_token_value, User.find(2).api_key
Chris@0 176 end
Chris@0 177
Chris@0 178 should "create a new token" do
Chris@0 179 assert User.find(2).api_token
Chris@0 180 end
Chris@0 181
Chris@0 182 should_set_the_flash_to /reset/
Chris@0 183 should_redirect_to('my account') {'/my/account' }
Chris@0 184 end
Chris@0 185
Chris@0 186 context "with no api_token" do
Chris@0 187 setup do
Chris@0 188 assert_nil User.find(2).api_token
Chris@0 189 post :reset_api_key
Chris@0 190 end
Chris@0 191
Chris@0 192 should "create a new token" do
Chris@0 193 assert User.find(2).api_token
Chris@0 194 end
Chris@0 195
Chris@0 196 should_set_the_flash_to /reset/
Chris@0 197 should_redirect_to('my account') {'/my/account' }
Chris@0 198 end
Chris@0 199 end
Chris@0 200 end