2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2013-01-07 02:20:49 +04:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2007-02-02 17:47:13 +03:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2009-09-13 21:14:35 +04:00
|
|
|
require 'application_controller'
|
2007-02-02 17:47:13 +03:00
|
|
|
|
|
|
|
# Re-raise errors caught by the controller.
|
|
|
|
class ApplicationController; def rescue_action(e) raise e end; end
|
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class ApplicationControllerTest < ActionController::TestCase
|
2009-02-21 14:04:50 +03:00
|
|
|
include Redmine::I18n
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2007-02-02 17:47:13 +03:00
|
|
|
def setup
|
|
|
|
@controller = ApplicationController.new
|
|
|
|
@request = ActionController::TestRequest.new
|
|
|
|
@response = ActionController::TestResponse.new
|
|
|
|
end
|
|
|
|
|
2007-05-24 21:29:11 +04:00
|
|
|
# check that all language files are valid
|
2007-02-02 17:47:13 +03:00
|
|
|
def test_localization
|
2009-02-21 14:04:50 +03:00
|
|
|
lang_files_count = Dir["#{RAILS_ROOT}/config/locales/*.yml"].size
|
|
|
|
assert_equal lang_files_count, valid_languages.size
|
|
|
|
valid_languages.each do |lang|
|
2007-02-02 17:47:13 +03:00
|
|
|
assert set_language_if_valid(lang)
|
|
|
|
end
|
2008-02-16 21:09:26 +03:00
|
|
|
set_language_if_valid('en')
|
2007-02-02 17:47:13 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-11-06 08:37:29 +03:00
|
|
|
def test_call_hook_mixed_in
|
|
|
|
assert @controller.respond_to?(:call_hook)
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "test_api_offset_and_limit" do
|
|
|
|
context "without params" do
|
|
|
|
should "return 0, 25" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "with limit" do
|
|
|
|
should "return 0, limit" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 30], @controller.send(:api_offset_and_limit, {:limit => 30})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
should "not exceed 100" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 100], @controller.send(:api_offset_and_limit, {:limit => 120})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not be negative" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {:limit => -10})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "with offset" do
|
|
|
|
should "return offset, 25" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [10, 25], @controller.send(:api_offset_and_limit, {:offset => 10})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not be negative" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {:offset => -10})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "and limit" do
|
|
|
|
should "return offset, limit" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [10, 50], @controller.send(:api_offset_and_limit, {:offset => 10, :limit => 50})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "with page" do
|
|
|
|
should "return offset, 25" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {:page => 1})
|
|
|
|
assert_equal [50, 25], @controller.send(:api_offset_and_limit, {:page => 3})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
should "not be negative" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {:page => 0})
|
|
|
|
assert_equal [0, 25], @controller.send(:api_offset_and_limit, {:page => -2})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 16:33:01 +03:00
|
|
|
context "and limit" do
|
|
|
|
should "return offset, limit" do
|
2011-03-25 00:22:21 +03:00
|
|
|
assert_equal [0, 100], @controller.send(:api_offset_and_limit, {:page => 1, :limit => 100})
|
|
|
|
assert_equal [200, 100], @controller.send(:api_offset_and_limit, {:page => 3, :limit => 100})
|
2010-12-23 16:33:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-02-02 17:47:13 +03:00
|
|
|
end
|