OSDN Git Service

5cc7901f1aae04c156a21ec36e3f888e4caa6921
[redminele/redmine.git] / test / functional / application_controller_test.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2007  Jean-Philippe Lang
3 #
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.
8
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.
13
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.
17
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'application_controller'
20
21 # Re-raise errors caught by the controller.
22 class ApplicationController; def rescue_action(e) raise e end; end
23
24 class ApplicationControllerTest < ActionController::TestCase
25   include Redmine::I18n
26   
27   def setup
28     @controller = ApplicationController.new
29     @request    = ActionController::TestRequest.new
30     @response   = ActionController::TestResponse.new
31   end
32
33   # check that all language files are valid
34   def test_localization
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)
39     end
40     set_language_if_valid('en')
41   end
42   
43   def test_call_hook_mixed_in
44     assert @controller.respond_to?(:call_hook)
45   end
46   
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({})
51       end
52     end
53     
54     context "with limit" do
55       should "return 0, limit" do
56         assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
57       end
58       
59       should "not exceed 100" do
60         assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
61       end
62
63       should "not be negative" do
64         assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
65       end
66     end
67     
68     context "with offset" do
69       should "return offset, 25" do
70         assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
71       end
72
73       should "not be negative" do
74         assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
75       end
76       
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})
80         end
81       end
82     end
83     
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})
88       end
89
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})
93       end
94       
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})
99         end
100       end
101     end
102   end
103 end