annotate test/functional/welcome_controller_test.rb @ 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 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 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@909 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@909 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@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'welcome_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class WelcomeController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class WelcomeControllerTest < ActionController::TestCase
Chris@1115 25 fixtures :projects, :news, :users, :members
Chris@909 26
Chris@0 27 def setup
Chris@0 28 @controller = WelcomeController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @response = ActionController::TestResponse.new
Chris@0 31 User.current = nil
Chris@0 32 end
Chris@909 33
Chris@0 34 def test_index
Chris@0 35 get :index
Chris@0 36 assert_response :success
Chris@0 37 assert_template 'index'
Chris@0 38 assert_not_nil assigns(:news)
Chris@0 39 assert_not_nil assigns(:projects)
Chris@0 40 assert !assigns(:projects).include?(Project.find(:first, :conditions => {:is_public => false}))
Chris@0 41 end
Chris@909 42
Chris@0 43 def test_browser_language
Chris@0 44 Setting.default_language = 'en'
Chris@0 45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@0 46 get :index
Chris@0 47 assert_equal :fr, @controller.current_language
Chris@0 48 end
Chris@909 49
Chris@0 50 def test_browser_language_alternate
Chris@0 51 Setting.default_language = 'en'
Chris@0 52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
Chris@0 53 get :index
Chris@0 54 assert_equal :"zh-TW", @controller.current_language
Chris@0 55 end
Chris@909 56
Chris@0 57 def test_browser_language_alternate_not_valid
Chris@0 58 Setting.default_language = 'en'
Chris@0 59 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
Chris@0 60 get :index
Chris@0 61 assert_equal :fr, @controller.current_language
Chris@0 62 end
Chris@909 63
Chris@0 64 def test_robots
Chris@0 65 get :robots
Chris@0 66 assert_response :success
Chris@0 67 assert_equal 'text/plain', @response.content_type
Chris@0 68 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
Chris@0 69 end
Chris@909 70
Chris@245 71 def test_warn_on_leaving_unsaved_turn_on
Chris@245 72 user = User.find(2)
Chris@245 73 user.pref.warn_on_leaving_unsaved = '1'
Chris@245 74 user.pref.save!
Chris@245 75 @request.session[:user_id] = 2
Chris@909 76
Chris@245 77 get :index
Chris@245 78 assert_tag 'script',
Chris@245 79 :attributes => {:type => "text/javascript"},
Chris@1115 80 :content => %r{warnLeavingUnsaved}
Chris@245 81 end
Chris@909 82
Chris@245 83 def test_warn_on_leaving_unsaved_turn_off
Chris@245 84 user = User.find(2)
Chris@245 85 user.pref.warn_on_leaving_unsaved = '0'
Chris@245 86 user.pref.save!
Chris@245 87 @request.session[:user_id] = 2
Chris@909 88
Chris@245 89 get :index
Chris@245 90 assert_no_tag 'script',
Chris@245 91 :attributes => {:type => "text/javascript"},
Chris@1115 92 :content => %r{warnLeavingUnsaved}
Chris@1115 93 end
Chris@1115 94
Chris@1115 95 def test_call_hook_mixed_in
Chris@1115 96 assert @controller.respond_to?(:call_hook)
Chris@1115 97 end
Chris@1115 98
Chris@1115 99 def test_project_jump_box_should_escape_names_once
Chris@1115 100 Project.find(1).update_attribute :name, 'Foo & Bar'
Chris@1115 101 @request.session[:user_id] = 2
Chris@1115 102
Chris@1115 103 get :index
Chris@1115 104 assert_select "#header select" do
Chris@1115 105 assert_select "option", :text => 'Foo &amp; Bar'
Chris@1115 106 end
Chris@1115 107 end
Chris@1115 108
Chris@1115 109 context "test_api_offset_and_limit" do
Chris@1115 110 context "without params" do
Chris@1115 111 should "return 0, 25" do
Chris@1115 112 assert_equal [0, 25], @controller.api_offset_and_limit({})
Chris@1115 113 end
Chris@1115 114 end
Chris@1115 115
Chris@1115 116 context "with limit" do
Chris@1115 117 should "return 0, limit" do
Chris@1115 118 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
Chris@1115 119 end
Chris@1115 120
Chris@1115 121 should "not exceed 100" do
Chris@1115 122 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
Chris@1115 123 end
Chris@1115 124
Chris@1115 125 should "not be negative" do
Chris@1115 126 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
Chris@1115 127 end
Chris@1115 128 end
Chris@1115 129
Chris@1115 130 context "with offset" do
Chris@1115 131 should "return offset, 25" do
Chris@1115 132 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
Chris@1115 133 end
Chris@1115 134
Chris@1115 135 should "not be negative" do
Chris@1115 136 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
Chris@1115 137 end
Chris@1115 138
Chris@1115 139 context "and limit" do
Chris@1115 140 should "return offset, limit" do
Chris@1115 141 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
Chris@1115 142 end
Chris@1115 143 end
Chris@1115 144 end
Chris@1115 145
Chris@1115 146 context "with page" do
Chris@1115 147 should "return offset, 25" do
Chris@1115 148 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
Chris@1115 149 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
Chris@1115 150 end
Chris@1115 151
Chris@1115 152 should "not be negative" do
Chris@1115 153 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
Chris@1115 154 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
Chris@1115 155 end
Chris@1115 156
Chris@1115 157 context "and limit" do
Chris@1115 158 should "return offset, limit" do
Chris@1115 159 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
Chris@1115 160 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
Chris@1115 161 end
Chris@1115 162 end
Chris@1115 163 end
Chris@245 164 end
Chris@0 165 end