1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'application_controller'
21 # Re-raise errors caught by the controller.
22 class ApplicationController; def rescue_action(e) raise e end; end
24 class ApplicationControllerTest < ActionController::TestCase
28 @controller = ApplicationController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
33 # check that all language files are valid
35 lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
36 assert_equal lang_files_count, valid_languages.size
37 valid_languages.each do |lang|
38 assert set_language_if_valid(lang)
40 set_language_if_valid('en')
43 def test_call_hook_mixed_in
44 assert @controller.respond_to?(:call_hook)
47 context "test_api_offset_and_limit" do
48 context "without params" do
49 should "return 0, 25" do
50 assert_equal [0, 25], @controller.api_offset_and_limit({})
54 context "with limit" do
55 should "return 0, limit" do
56 assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
59 should "not exceed 100" do
60 assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
63 should "not be negative" do
64 assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
68 context "with offset" do
69 should "return offset, 25" do
70 assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
73 should "not be negative" do
74 assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
77 context "and limit" do
78 should "return offset, limit" do
79 assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
84 context "with page" do
85 should "return offset, 25" do
86 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
87 assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
90 should "not be negative" do
91 assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
92 assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
95 context "and limit" do
96 should "return offset, limit" do
97 assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
98 assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})