annotate .svn/pristine/99/996a1b6e4446763a10437d55b49224da9e67f637.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class WelcomeControllerTest < ActionController::TestCase
Chris@1517 21 fixtures :projects, :news, :users, :members
Chris@1517 22
Chris@1517 23 def setup
Chris@1517 24 User.current = nil
Chris@1517 25 end
Chris@1517 26
Chris@1517 27 def test_index
Chris@1517 28 get :index
Chris@1517 29 assert_response :success
Chris@1517 30 assert_template 'index'
Chris@1517 31 assert_not_nil assigns(:news)
Chris@1517 32 assert_not_nil assigns(:projects)
Chris@1517 33 assert !assigns(:projects).include?(Project.where(:is_public => false).first)
Chris@1517 34 end
Chris@1517 35
Chris@1517 36 def test_browser_language
Chris@1517 37 Setting.default_language = 'en'
Chris@1517 38 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@1517 39 get :index
Chris@1517 40 assert_equal :fr, @controller.current_language
Chris@1517 41 end
Chris@1517 42
Chris@1517 43 def test_browser_language_alternate
Chris@1517 44 Setting.default_language = 'en'
Chris@1517 45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
Chris@1517 46 get :index
Chris@1517 47 assert_equal :"zh-TW", @controller.current_language
Chris@1517 48 end
Chris@1517 49
Chris@1517 50 def test_browser_language_alternate_not_valid
Chris@1517 51 Setting.default_language = 'en'
Chris@1517 52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
Chris@1517 53 get :index
Chris@1517 54 assert_equal :fr, @controller.current_language
Chris@1517 55 end
Chris@1517 56
Chris@1517 57 def test_browser_language_should_be_ignored_with_force_default_language_for_anonymous
Chris@1517 58 Setting.default_language = 'en'
Chris@1517 59 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@1517 60 with_settings :force_default_language_for_anonymous => '1' do
Chris@1517 61 get :index
Chris@1517 62 assert_equal :en, @controller.current_language
Chris@1517 63 end
Chris@1517 64 end
Chris@1517 65
Chris@1517 66 def test_user_language_should_be_used
Chris@1517 67 Setting.default_language = 'fi'
Chris@1517 68 user = User.find(2).update_attribute :language, 'it'
Chris@1517 69 @request.session[:user_id] = 2
Chris@1517 70 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@1517 71 get :index
Chris@1517 72 assert_equal :it, @controller.current_language
Chris@1517 73 end
Chris@1517 74
Chris@1517 75 def test_user_language_should_be_ignored_if_force_default_language_for_loggedin
Chris@1517 76 Setting.default_language = 'fi'
Chris@1517 77 user = User.find(2).update_attribute :language, 'it'
Chris@1517 78 @request.session[:user_id] = 2
Chris@1517 79 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@1517 80 with_settings :force_default_language_for_loggedin => '1' do
Chris@1517 81 get :index
Chris@1517 82 assert_equal :fi, @controller.current_language
Chris@1517 83 end
Chris@1517 84 end
Chris@1517 85
Chris@1517 86 def test_robots
Chris@1517 87 get :robots
Chris@1517 88 assert_response :success
Chris@1517 89 assert_equal 'text/plain', @response.content_type
Chris@1517 90 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
Chris@1517 91 end
Chris@1517 92
Chris@1517 93 def test_warn_on_leaving_unsaved_turn_on
Chris@1517 94 user = User.find(2)
Chris@1517 95 user.pref.warn_on_leaving_unsaved = '1'
Chris@1517 96 user.pref.save!
Chris@1517 97 @request.session[:user_id] = 2
Chris@1517 98
Chris@1517 99 get :index
Chris@1517 100 assert_tag 'script',
Chris@1517 101 :attributes => {:type => "text/javascript"},
Chris@1517 102 :content => %r{warnLeavingUnsaved}
Chris@1517 103 end
Chris@1517 104
Chris@1517 105 def test_warn_on_leaving_unsaved_turn_off
Chris@1517 106 user = User.find(2)
Chris@1517 107 user.pref.warn_on_leaving_unsaved = '0'
Chris@1517 108 user.pref.save!
Chris@1517 109 @request.session[:user_id] = 2
Chris@1517 110
Chris@1517 111 get :index
Chris@1517 112 assert_no_tag 'script',
Chris@1517 113 :attributes => {:type => "text/javascript"},
Chris@1517 114 :content => %r{warnLeavingUnsaved}
Chris@1517 115 end
Chris@1517 116
Chris@1517 117 def test_logout_link_should_post
Chris@1517 118 @request.session[:user_id] = 2
Chris@1517 119
Chris@1517 120 get :index
Chris@1517 121 assert_select 'a[href=/logout][data-method=post]', :text => 'Sign out'
Chris@1517 122 end
Chris@1517 123
Chris@1517 124 def test_call_hook_mixed_in
Chris@1517 125 assert @controller.respond_to?(:call_hook)
Chris@1517 126 end
Chris@1517 127
Chris@1517 128 def test_project_jump_box_should_escape_names_once
Chris@1517 129 Project.find(1).update_attribute :name, 'Foo & Bar'
Chris@1517 130 @request.session[:user_id] = 2
Chris@1517 131
Chris@1517 132 get :index
Chris@1517 133 assert_select "#header select" do
Chris@1517 134 assert_select "option", :text => 'Foo &amp; Bar'
Chris@1517 135 end
Chris@1517 136 end
Chris@1517 137
Chris@1517 138 def test_api_offset_and_limit_without_params
Chris@1517 139 assert_equal [0, 25], @controller.api_offset_and_limit({})
Chris@1517 140 end
Chris@1517 141
Chris@1517 142 def test_api_offset_and_limit_with_limit
Chris@1517 143 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
Chris@1517 144 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
Chris@1517 145 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
Chris@1517 146 end
Chris@1517 147
Chris@1517 148 def test_api_offset_and_limit_with_offset
Chris@1517 149 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
Chris@1517 150 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
Chris@1517 151 end
Chris@1517 152
Chris@1517 153 def test_api_offset_and_limit_with_offset_and_limit
Chris@1517 154 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
Chris@1517 155 end
Chris@1517 156
Chris@1517 157 def test_api_offset_and_limit_with_page
Chris@1517 158 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
Chris@1517 159 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
Chris@1517 160 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
Chris@1517 161 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
Chris@1517 162 end
Chris@1517 163
Chris@1517 164 def test_api_offset_and_limit_with_page_and_limit
Chris@1517 165 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
Chris@1517 166 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
Chris@1517 167 end
Chris@1517 168
Chris@1517 169 def test_unhautorized_exception_with_anonymous_should_redirect_to_login
Chris@1517 170 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
Chris@1517 171
Chris@1517 172 get :index
Chris@1517 173 assert_response 302
Chris@1517 174 assert_redirected_to('/login?back_url='+CGI.escape('http://test.host/'))
Chris@1517 175 end
Chris@1517 176
Chris@1517 177 def test_unhautorized_exception_with_anonymous_and_xmlhttprequest_should_respond_with_401_to_anonymous
Chris@1517 178 WelcomeController.any_instance.stubs(:index).raises(::Unauthorized)
Chris@1517 179
Chris@1517 180 @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
Chris@1517 181 get :index
Chris@1517 182 assert_response 401
Chris@1517 183 end
Chris@1517 184 end