annotate test/functional/welcome_controller_test.rb @ 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@909 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 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
Chris@0 20 class WelcomeControllerTest < ActionController::TestCase
Chris@1115 21 fixtures :projects, :news, :users, :members
Chris@909 22
Chris@0 23 def setup
Chris@0 24 User.current = nil
Chris@0 25 end
Chris@909 26
Chris@0 27 def test_index
Chris@0 28 get :index
Chris@0 29 assert_response :success
Chris@0 30 assert_template 'index'
Chris@0 31 assert_not_nil assigns(:news)
Chris@0 32 assert_not_nil assigns(:projects)
Chris@1295 33 assert !assigns(:projects).include?(Project.where(:is_public => false).first)
Chris@0 34 end
Chris@909 35
Chris@0 36 def test_browser_language
Chris@0 37 Setting.default_language = 'en'
Chris@0 38 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
Chris@0 39 get :index
Chris@0 40 assert_equal :fr, @controller.current_language
Chris@0 41 end
Chris@909 42
Chris@0 43 def test_browser_language_alternate
Chris@0 44 Setting.default_language = 'en'
Chris@0 45 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
Chris@0 46 get :index
Chris@0 47 assert_equal :"zh-TW", @controller.current_language
Chris@0 48 end
Chris@909 49
Chris@0 50 def test_browser_language_alternate_not_valid
Chris@0 51 Setting.default_language = 'en'
Chris@0 52 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr-CA'
Chris@0 53 get :index
Chris@0 54 assert_equal :fr, @controller.current_language
Chris@0 55 end
Chris@909 56
Chris@0 57 def test_robots
Chris@0 58 get :robots
Chris@0 59 assert_response :success
Chris@0 60 assert_equal 'text/plain', @response.content_type
Chris@0 61 assert @response.body.match(%r{^Disallow: /projects/ecookbook/issues\r?$})
Chris@0 62 end
Chris@909 63
Chris@245 64 def test_warn_on_leaving_unsaved_turn_on
Chris@245 65 user = User.find(2)
Chris@245 66 user.pref.warn_on_leaving_unsaved = '1'
Chris@245 67 user.pref.save!
Chris@245 68 @request.session[:user_id] = 2
Chris@909 69
Chris@245 70 get :index
Chris@245 71 assert_tag 'script',
Chris@245 72 :attributes => {:type => "text/javascript"},
Chris@1115 73 :content => %r{warnLeavingUnsaved}
Chris@245 74 end
Chris@909 75
Chris@245 76 def test_warn_on_leaving_unsaved_turn_off
Chris@245 77 user = User.find(2)
Chris@245 78 user.pref.warn_on_leaving_unsaved = '0'
Chris@245 79 user.pref.save!
Chris@245 80 @request.session[:user_id] = 2
Chris@909 81
Chris@245 82 get :index
Chris@245 83 assert_no_tag 'script',
Chris@245 84 :attributes => {:type => "text/javascript"},
Chris@1115 85 :content => %r{warnLeavingUnsaved}
Chris@1115 86 end
Chris@1115 87
Chris@1295 88 def test_logout_link_should_post
Chris@1295 89 @request.session[:user_id] = 2
Chris@1295 90
Chris@1295 91 get :index
Chris@1295 92 assert_select 'a[href=/logout][data-method=post]', :text => 'Sign out'
Chris@1295 93 end
Chris@1295 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