annotate test/functional/my_controller_test.rb @ 1452:d6b9fd02bb89 feature_36_js_refactoring

Deprecated develoment branch.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 11 Oct 2013 17:01:24 +0100
parents af80e5618e9b
children cbb26bc654de
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@117 18 require File.expand_path('../../test_helper', __FILE__)
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@117 67 post :account,
Chris@117 68 :user => {
Chris@117 69 :firstname => "Joe",
Chris@117 70 :login => "root",
Chris@117 71 :admin => 1,
Chris@117 72 :group_ids => ['10'],
Chris@117 73 :custom_field_values => {"4" => "0100562500"}
Chris@117 74 }
Chris@117 75
chris@37 76 assert_redirected_to '/my/account'
Chris@0 77 user = User.find(2)
Chris@0 78 assert_equal user, assigns(:user)
Chris@0 79 assert_equal "Joe", user.firstname
Chris@0 80 assert_equal "jsmith", user.login
Chris@0 81 assert_equal "0100562500", user.custom_value_for(4).value
Chris@117 82 # ignored
Chris@0 83 assert !user.admin?
Chris@117 84 assert user.groups.empty?
Chris@0 85 end
Chris@0 86
Chris@0 87 def test_change_password
Chris@0 88 get :password
Chris@0 89 assert_response :success
Chris@0 90 assert_template 'password'
Chris@0 91
Chris@0 92 # non matching password confirmation
Chris@0 93 post :password, :password => 'jsmith',
Chris@0 94 :new_password => 'hello',
Chris@0 95 :new_password_confirmation => 'hello2'
Chris@0 96 assert_response :success
Chris@0 97 assert_template 'password'
Chris@0 98 assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
Chris@0 99
Chris@0 100 # wrong password
Chris@0 101 post :password, :password => 'wrongpassword',
Chris@0 102 :new_password => 'hello',
Chris@0 103 :new_password_confirmation => 'hello'
Chris@0 104 assert_response :success
Chris@0 105 assert_template 'password'
Chris@0 106 assert_equal 'Wrong password', flash[:error]
Chris@0 107
Chris@0 108 # good password
Chris@0 109 post :password, :password => 'jsmith',
Chris@0 110 :new_password => 'hello',
Chris@0 111 :new_password_confirmation => 'hello'
chris@37 112 assert_redirected_to '/my/account'
Chris@0 113 assert User.try_to_login('jsmith', 'hello')
Chris@0 114 end
Chris@0 115
Chris@0 116 def test_page_layout
Chris@0 117 get :page_layout
Chris@0 118 assert_response :success
Chris@0 119 assert_template 'page_layout'
Chris@0 120 end
Chris@0 121
Chris@0 122 def test_add_block
Chris@0 123 xhr :post, :add_block, :block => 'issuesreportedbyme'
Chris@0 124 assert_response :success
Chris@0 125 assert User.find(2).pref[:my_page_layout]['top'].include?('issuesreportedbyme')
Chris@0 126 end
Chris@0 127
Chris@0 128 def test_remove_block
Chris@0 129 xhr :post, :remove_block, :block => 'issuesassignedtome'
Chris@0 130 assert_response :success
Chris@0 131 assert !User.find(2).pref[:my_page_layout].values.flatten.include?('issuesassignedtome')
Chris@0 132 end
Chris@0 133
Chris@0 134 def test_order_blocks
Chris@0 135 xhr :post, :order_blocks, :group => 'left', 'list-left' => ['documents', 'calendar', 'latestnews']
Chris@0 136 assert_response :success
Chris@0 137 assert_equal ['documents', 'calendar', 'latestnews'], User.find(2).pref[:my_page_layout]['left']
Chris@0 138 end
Chris@0 139
Chris@0 140 context "POST to reset_rss_key" do
Chris@0 141 context "with an existing rss_token" do
Chris@0 142 setup do
Chris@0 143 @previous_token_value = User.find(2).rss_key # Will generate one if it's missing
Chris@0 144 post :reset_rss_key
Chris@0 145 end
Chris@0 146
Chris@0 147 should "destroy the existing token" do
Chris@0 148 assert_not_equal @previous_token_value, User.find(2).rss_key
Chris@0 149 end
Chris@0 150
Chris@0 151 should "create a new token" do
Chris@0 152 assert User.find(2).rss_token
Chris@0 153 end
Chris@0 154
Chris@0 155 should_set_the_flash_to /reset/
Chris@0 156 should_redirect_to('my account') {'/my/account' }
Chris@0 157 end
Chris@0 158
Chris@0 159 context "with no rss_token" do
Chris@0 160 setup do
Chris@0 161 assert_nil User.find(2).rss_token
Chris@0 162 post :reset_rss_key
Chris@0 163 end
Chris@0 164
Chris@0 165 should "create a new token" do
Chris@0 166 assert User.find(2).rss_token
Chris@0 167 end
Chris@0 168
Chris@0 169 should_set_the_flash_to /reset/
Chris@0 170 should_redirect_to('my account') {'/my/account' }
Chris@0 171 end
Chris@0 172 end
Chris@0 173
Chris@0 174 context "POST to reset_api_key" do
Chris@0 175 context "with an existing api_token" do
Chris@0 176 setup do
Chris@0 177 @previous_token_value = User.find(2).api_key # Will generate one if it's missing
Chris@0 178 post :reset_api_key
Chris@0 179 end
Chris@0 180
Chris@0 181 should "destroy the existing token" do
Chris@0 182 assert_not_equal @previous_token_value, User.find(2).api_key
Chris@0 183 end
Chris@0 184
Chris@0 185 should "create a new token" do
Chris@0 186 assert User.find(2).api_token
Chris@0 187 end
Chris@0 188
Chris@0 189 should_set_the_flash_to /reset/
Chris@0 190 should_redirect_to('my account') {'/my/account' }
Chris@0 191 end
Chris@0 192
Chris@0 193 context "with no api_token" do
Chris@0 194 setup do
Chris@0 195 assert_nil User.find(2).api_token
Chris@0 196 post :reset_api_key
Chris@0 197 end
Chris@0 198
Chris@0 199 should "create a new token" do
Chris@0 200 assert User.find(2).api_token
Chris@0 201 end
Chris@0 202
Chris@0 203 should_set_the_flash_to /reset/
Chris@0 204 should_redirect_to('my account') {'/my/account' }
Chris@0 205 end
Chris@0 206 end
Chris@0 207 end