annotate test/functional/application_controller_test.rb @ 1176:7d9db6065048 bug_352

Close obsolete branch bug_352
author Chris Cannam
date Wed, 01 Feb 2012 16:09:00 +0000
parents 0c939c159af4
children cbb26bc654de
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 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@0 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@0 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 'application_controller'
Chris@0 20
Chris@0 21 class ApplicationControllerTest < ActionController::TestCase
Chris@0 22 include Redmine::I18n
Chris@0 23
Chris@0 24 def setup
Chris@0 25 @controller = ApplicationController.new
Chris@0 26 @request = ActionController::TestRequest.new
Chris@0 27 @response = ActionController::TestResponse.new
Chris@0 28 end
Chris@0 29
Chris@0 30 # check that all language files are valid
Chris@0 31 def test_localization
Chris@0 32 lang_files_count = Dir["#{RAILS_ROOT}/config/locales/*.yml"].size
Chris@0 33 assert_equal lang_files_count, valid_languages.size
Chris@0 34 valid_languages.each do |lang|
Chris@0 35 assert set_language_if_valid(lang)
Chris@0 36 end
Chris@0 37 set_language_if_valid('en')
Chris@0 38 end
Chris@0 39
Chris@0 40 def test_call_hook_mixed_in
Chris@0 41 assert @controller.respond_to?(:call_hook)
Chris@0 42 end
Chris@119 43
Chris@119 44 context "test_api_offset_and_limit" do
Chris@119 45 context "without params" do
Chris@119 46 should "return 0, 25" do
Chris@119 47 assert_equal [0, 25], @controller.api_offset_and_limit({})
Chris@119 48 end
Chris@119 49 end
Chris@119 50
Chris@119 51 context "with limit" do
Chris@119 52 should "return 0, limit" do
Chris@119 53 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
Chris@119 54 end
Chris@119 55
Chris@119 56 should "not exceed 100" do
Chris@119 57 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
Chris@119 58 end
Chris@119 59
Chris@119 60 should "not be negative" do
Chris@119 61 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
Chris@119 62 end
Chris@119 63 end
Chris@119 64
Chris@119 65 context "with offset" do
Chris@119 66 should "return offset, 25" do
Chris@119 67 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
Chris@119 68 end
Chris@119 69
Chris@119 70 should "not be negative" do
Chris@119 71 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
Chris@119 72 end
Chris@119 73
Chris@119 74 context "and limit" do
Chris@119 75 should "return offset, limit" do
Chris@119 76 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
Chris@119 77 end
Chris@119 78 end
Chris@119 79 end
Chris@119 80
Chris@119 81 context "with page" do
Chris@119 82 should "return offset, 25" do
Chris@119 83 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
Chris@119 84 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
Chris@119 85 end
Chris@119 86
Chris@119 87 should "not be negative" do
Chris@119 88 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
Chris@119 89 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
Chris@119 90 end
Chris@119 91
Chris@119 92 context "and limit" do
Chris@119 93 should "return offset, limit" do
Chris@119 94 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
Chris@119 95 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
Chris@119 96 end
Chris@119 97 end
Chris@119 98 end
Chris@119 99 end
Chris@0 100 end