To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / c2 / c22f3e78d33cc33390133e36001a79182aa59239.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (3.27 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 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 |
class ApplicationControllerTest < ActionController::TestCase |
| 22 |
include Redmine::I18n |
| 23 |
|
| 24 |
def setup |
| 25 |
@controller = ApplicationController.new |
| 26 |
@request = ActionController::TestRequest.new |
| 27 |
@response = ActionController::TestResponse.new |
| 28 |
end |
| 29 |
|
| 30 |
# check that all language files are valid |
| 31 |
def test_localization |
| 32 |
lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
|
| 33 |
assert_equal lang_files_count, valid_languages.size |
| 34 |
valid_languages.each do |lang| |
| 35 |
assert set_language_if_valid(lang) |
| 36 |
end |
| 37 |
set_language_if_valid('en')
|
| 38 |
end |
| 39 |
|
| 40 |
def test_call_hook_mixed_in |
| 41 |
assert @controller.respond_to?(:call_hook) |
| 42 |
end |
| 43 |
|
| 44 |
context "test_api_offset_and_limit" do |
| 45 |
context "without params" do |
| 46 |
should "return 0, 25" do |
| 47 |
assert_equal [0, 25], @controller.api_offset_and_limit({})
|
| 48 |
end |
| 49 |
end |
| 50 |
|
| 51 |
context "with limit" do |
| 52 |
should "return 0, limit" do |
| 53 |
assert_equal [0, 30], @controller.api_offset_and_limit({:limit => 30})
|
| 54 |
end |
| 55 |
|
| 56 |
should "not exceed 100" do |
| 57 |
assert_equal [0, 100], @controller.api_offset_and_limit({:limit => 120})
|
| 58 |
end |
| 59 |
|
| 60 |
should "not be negative" do |
| 61 |
assert_equal [0, 25], @controller.api_offset_and_limit({:limit => -10})
|
| 62 |
end |
| 63 |
end |
| 64 |
|
| 65 |
context "with offset" do |
| 66 |
should "return offset, 25" do |
| 67 |
assert_equal [10, 25], @controller.api_offset_and_limit({:offset => 10})
|
| 68 |
end |
| 69 |
|
| 70 |
should "not be negative" do |
| 71 |
assert_equal [0, 25], @controller.api_offset_and_limit({:offset => -10})
|
| 72 |
end |
| 73 |
|
| 74 |
context "and limit" do |
| 75 |
should "return offset, limit" do |
| 76 |
assert_equal [10, 50], @controller.api_offset_and_limit({:offset => 10, :limit => 50})
|
| 77 |
end |
| 78 |
end |
| 79 |
end |
| 80 |
|
| 81 |
context "with page" do |
| 82 |
should "return offset, 25" do |
| 83 |
assert_equal [0, 25], @controller.api_offset_and_limit({:page => 1})
|
| 84 |
assert_equal [50, 25], @controller.api_offset_and_limit({:page => 3})
|
| 85 |
end |
| 86 |
|
| 87 |
should "not be negative" do |
| 88 |
assert_equal [0, 25], @controller.api_offset_and_limit({:page => 0})
|
| 89 |
assert_equal [0, 25], @controller.api_offset_and_limit({:page => -2})
|
| 90 |
end |
| 91 |
|
| 92 |
context "and limit" do |
| 93 |
should "return offset, limit" do |
| 94 |
assert_equal [0, 100], @controller.api_offset_and_limit({:page => 1, :limit => 100})
|
| 95 |
assert_equal [200, 100], @controller.api_offset_and_limit({:page => 3, :limit => 100})
|
| 96 |
end |
| 97 |
end |
| 98 |
end |
| 99 |
end |
| 100 |
end |