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