annotate .svn/pristine/ec/ece91c997e03c02829d36bfa3c15802fe47dbaf8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19 require 'welcome_controller'
Chris@1295 20
Chris@1295 21 # Re-raise errors caught by the controller.
Chris@1295 22 class WelcomeController; def rescue_action(e) raise e end; end
Chris@1295 23
Chris@1295 24 class WelcomeControllerTest < ActionController::TestCase
Chris@1295 25 fixtures :projects, :news, :users, :members
Chris@1295 26
Chris@1295 27 def setup
Chris@1295 28 @controller = WelcomeController.new
Chris@1295 29 @request = ActionController::TestRequest.new
Chris@1295 30 @response = ActionController::TestResponse.new
Chris@1295 31 User.current = nil
Chris@1295 32 end
Chris@1295 33
Chris@1295 34 def test_index
Chris@1295 35 get :index
Chris@1295 36 assert_response :success
Chris@1295 37 assert_template 'index'
Chris@1295 38 assert_not_nil assigns(:news)
Chris@1295 39 assert_not_nil assigns(:projects)
Chris@1295 40 assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
Chris@1295 41 end
Chris@1295 42
Chris@1295 43 def test_browser_language
Chris@1295 44 Setting.default_language = 'en'
Chris@1295 45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@1295 46 get :index
Chris@1295 47 assert_equal :fr, @controller.current_language
Chris@1295 48 end
Chris@1295 49
Chris@1295 50 def test_browser_language_alternate
Chris@1295 51 Setting.default_language = 'en'
Chris@1295 52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
Chris@1295 53 get :index
Chris@1295 54 assert_equal :"zh-TW", @controller.current_language
Chris@1295 55 end
Chris@1295 56
Chris@1295 57 def test_browser_language_alternate_not_valid
Chris@1295 58 Setting.default_language = 'en'
Chris@1295 59 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
Chris@1295 60 get :index
Chris@1295 61 assert_equal :fr, @controller.current_language
Chris@1295 62 end
Chris@1295 63
Chris@1295 64 def test_robots
Chris@1295 65 get :robots
Chris@1295 66 assert_response :success
Chris@1295 67 assert_equal 'text/plain', @response.content_type
Chris@1295 68 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
Chris@1295 69 end
Chris@1295 70
Chris@1295 71 def test_warn_on_leaving_unsaved_turn_on
Chris@1295 72 user = User.find(2)
Chris@1295 73 user.pref.warn_on_leaving_unsaved = '1'
Chris@1295 74 user.pref.save!
Chris@1295 75 @request.session[:user_id] = 2
Chris@1295 76
Chris@1295 77 get :index
Chris@1295 78 assert_tag 'script',
Chris@1295 79 :attributes => {:type => "text/javascript"},
Chris@1295 80 :content => %r{warnLeavingUnsaved}
Chris@1295 81 end
Chris@1295 82
Chris@1295 83 def test_warn_on_leaving_unsaved_turn_off
Chris@1295 84 user = User.find(2)
Chris@1295 85 user.pref.warn_on_leaving_unsaved = '0'
Chris@1295 86 user.pref.save!
Chris@1295 87 @request.session[:user_id] = 2
Chris@1295 88
Chris@1295 89 get :index
Chris@1295 90 assert_no_tag 'script',
Chris@1295 91 :attributes => {:type => "text/javascript"},
Chris@1295 92 :content => %r{warnLeavingUnsaved}
Chris@1295 93 end
Chris@1295 94
Chris@1295 95 def test_call_hook_mixed_in
Chris@1295 96 assert @controller.respond_to?(:call_hook)
Chris@1295 97 end
Chris@1295 98
Chris@1295 99 def test_project_jump_box_should_escape_names_once
Chris@1295 100 Project.find(1).update_attribute :name, 'Foo & Bar'
Chris@1295 101 @request.session[:user_id] = 2
Chris@1295 102
Chris@1295 103 get :index
Chris@1295 104 assert_select "#header select" do
Chris@1295 105 assert_select "option", :text => 'Foo &amp; Bar'
Chris@1295 106 end
Chris@1295 107 end
Chris@1295 108
Chris@1295 109 context "test_api_offset_and_limit" do
Chris@1295 110 context "without params" do
Chris@1295 111 should "return 0, 25" do
Chris@1295 112 assert_equal [0, 25], @controller.api_offset_and_limit({})
Chris@1295 113 end
Chris@1295 114 end
Chris@1295 115
Chris@1295 116 context "with limit" do
Chris@1295 117 should "return 0, limit" do
Chris@1295 118 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
Chris@1295 119 end
Chris@1295 120
Chris@1295 121 should "not exceed 100" do
Chris@1295 122 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
Chris@1295 123 end
Chris@1295 124
Chris@1295 125 should "not be negative" do
Chris@1295 126 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
Chris@1295 127 end
Chris@1295 128 end
Chris@1295 129
Chris@1295 130 context "with offset" do
Chris@1295 131 should "return offset, 25" do
Chris@1295 132 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
Chris@1295 133 end
Chris@1295 134
Chris@1295 135 should "not be negative" do
Chris@1295 136 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
Chris@1295 137 end
Chris@1295 138
Chris@1295 139 context "and limit" do
Chris@1295 140 should "return offset, limit" do
Chris@1295 141 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
Chris@1295 142 end
Chris@1295 143 end
Chris@1295 144 end
Chris@1295 145
Chris@1295 146 context "with page" do
Chris@1295 147 should "return offset, 25" do
Chris@1295 148 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
Chris@1295 149 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
Chris@1295 150 end
Chris@1295 151
Chris@1295 152 should "not be negative" do
Chris@1295 153 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
Chris@1295 154 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
Chris@1295 155 end
Chris@1295 156
Chris@1295 157 context "and limit" do
Chris@1295 158 should "return offset, limit" do
Chris@1295 159 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
Chris@1295 160 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
Chris@1295 161 end
Chris@1295 162 end
Chris@1295 163 end
Chris@1295 164 end
Chris@1295 165 end