2009-03-12 19:19:13 +00:00
|
|
|
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
|
|
|
$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'active_support'
|
|
|
|
require 'active_support/test_case'
|
|
|
|
require 'action_controller'
|
|
|
|
require 'action_view/base'
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'ruby-debug'
|
|
|
|
Debugger.settings[:autoeval] = true
|
|
|
|
Debugger.start
|
|
|
|
rescue LoadError
|
|
|
|
# Debugging disabled. `gem install ruby-debug` to enable.
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'action_controller/abstract'
|
|
|
|
require 'action_controller/new_base'
|
|
|
|
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'rack/test'
|
|
|
|
|
|
|
|
module ActionController
|
|
|
|
class Base2 < AbstractBase
|
|
|
|
include AbstractController::Callbacks
|
|
|
|
include AbstractController::Renderer
|
|
|
|
include AbstractController::Helpers
|
|
|
|
include AbstractController::Layouts
|
|
|
|
include AbstractController::Logger
|
|
|
|
|
|
|
|
include ActionController::HideActions
|
|
|
|
include ActionController::UrlFor
|
2009-03-18 01:04:22 +00:00
|
|
|
include ActionController::Renderer
|
2009-03-12 19:19:13 +00:00
|
|
|
|
|
|
|
CORE_METHODS = self.public_instance_methods
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
# Temporary base class
|
|
|
|
class Rack::TestCase < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
setup do
|
|
|
|
ActionController::Base.session_options[:key] = "abc"
|
|
|
|
ActionController::Base.session_options[:secret] = ("*" * 30)
|
|
|
|
ActionController::Routing.use_controllers! %w(happy_path/simple_dispatch)
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
|
|
|
def self.get(url)
|
|
|
|
setup do |test|
|
|
|
|
test.get url
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
end
|
2009-03-12 19:19:13 +00:00
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
def app
|
|
|
|
@app ||= ActionController::Dispatcher.new
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
def assert_body(body)
|
|
|
|
assert_equal [body], last_response.body
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
def assert_status(code)
|
|
|
|
assert_equal code, last_response.status
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
def assert_content_type(type)
|
|
|
|
assert_equal type, last_response.headers["Content-Type"]
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
|
|
|
def assert_header(name, value)
|
|
|
|
assert_equal value, last_response.headers[name]
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
# Tests the controller dispatching happy path
|
|
|
|
module HappyPath
|
|
|
|
class SimpleDispatchController < ActionController::Base2
|
|
|
|
def index
|
|
|
|
render :text => "success"
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
def modify_response_body
|
|
|
|
self.response_body = "success"
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
|
|
|
def modify_response_body_twice
|
|
|
|
ret = (self.response_body = "success")
|
|
|
|
self.response_body = "#{ret}!"
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
|
|
|
def modify_response_headers
|
|
|
|
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
class SimpleRouteCase < Rack::TestCase
|
|
|
|
setup do
|
|
|
|
ActionController::Routing::Routes.draw do |map|
|
2009-03-12 19:19:13 +00:00
|
|
|
map.connect ':controller/:action'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
class TestSimpleDispatch < SimpleRouteCase
|
|
|
|
|
|
|
|
get "/happy_path/simple_dispatch/index"
|
|
|
|
|
|
|
|
test "sets the body" do
|
|
|
|
assert_body "success"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sets the status code" do
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-03-12 19:19:13 +00:00
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
test "sets the content type" do
|
|
|
|
assert_content_type Mime::HTML
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sets the content length" do
|
|
|
|
assert_header "Content-Length", 7
|
|
|
|
end
|
|
|
|
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
# :api: plugin
|
|
|
|
class TestDirectResponseMod < SimpleRouteCase
|
|
|
|
get "/happy_path/simple_dispatch/modify_response_body"
|
|
|
|
|
|
|
|
test "sets the body" do
|
|
|
|
assert_body "success"
|
|
|
|
end
|
2009-03-12 19:19:13 +00:00
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
test "setting the body manually sets the content length" do
|
|
|
|
assert_header "Content-Length", 7
|
|
|
|
end
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
|
|
|
|
# :api: plugin
|
|
|
|
class TestDirectResponseModTwice < SimpleRouteCase
|
|
|
|
get "/happy_path/simple_dispatch/modify_response_body_twice"
|
|
|
|
|
|
|
|
test "self.response_body= returns the body being set" do
|
|
|
|
assert_body "success!"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updating the response body updates the content length" do
|
|
|
|
assert_header "Content-Length", 8
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
class EmptyController < ActionController::Base2 ; end
|
|
|
|
module Submodule
|
|
|
|
class ContainedEmptyController < ActionController::Base2 ; end
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
class ControllerClassTests < Test::Unit::TestCase
|
|
|
|
def test_controller_path
|
|
|
|
assert_equal 'empty', EmptyController.controller_path
|
|
|
|
assert_equal EmptyController.controller_path, EmptyController.new.controller_path
|
|
|
|
assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
|
|
|
|
assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
|
2009-03-12 19:19:13 +00:00
|
|
|
end
|
2009-03-18 01:04:22 +00:00
|
|
|
def test_controller_name
|
|
|
|
assert_equal 'empty', EmptyController.controller_name
|
|
|
|
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
|
|
|
|
end
|
|
|
|
end
|