annotate .svn/pristine/6a/6a90c258580c8739754206289754513f15068486.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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