2009-03-18 18:58:47 -04:00
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
2009-03-12 15:19:13 -04:00
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
# Tests the controller dispatching happy path
|
2009-04-29 14:42:27 -04:00
|
|
|
module Dispatching
|
2009-05-01 20:27:44 -04:00
|
|
|
class SimpleController < ActionController::Base
|
2009-03-17 21:04:22 -04:00
|
|
|
def index
|
|
|
|
render :text => "success"
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
def modify_response_body
|
|
|
|
self.response_body = "success"
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
def modify_response_body_twice
|
|
|
|
ret = (self.response_body = "success")
|
|
|
|
self.response_body = "#{ret}!"
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
def modify_response_headers
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
class EmptyController < ActionController::Base ; end
|
|
|
|
|
|
|
|
module Submodule
|
|
|
|
class ContainedEmptyController < ActionController::Base ; end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BaseTest < SimpleRouteCase
|
|
|
|
# :api: plugin
|
|
|
|
test "simple dispatching" do
|
|
|
|
get "/dispatching/simple/index"
|
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
assert_body "success"
|
|
|
|
assert_status 200
|
2009-04-27 21:21:26 -04:00
|
|
|
assert_content_type "text/html; charset=utf-8"
|
|
|
|
assert_header "Content-Length", "7"
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
# :api: plugin
|
|
|
|
test "directly modifying response body" do
|
|
|
|
get "/dispatching/simple/modify_response_body"
|
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
assert_body "success"
|
2009-05-20 15:15:06 -04:00
|
|
|
assert_header "Content-Length", "7" # setting the body manually sets the content length
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
# :api: plugin
|
|
|
|
test "directly modifying response body twice" do
|
|
|
|
get "/dispatching/simple/modify_response_body_twice"
|
|
|
|
|
2009-03-17 21:04:22 -04:00
|
|
|
assert_body "success!"
|
2009-04-27 21:21:26 -04:00
|
|
|
assert_header "Content-Length", "8"
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
|
|
|
|
2009-05-20 15:15:06 -04:00
|
|
|
test "controller path" do
|
2009-04-29 14:42:27 -04:00
|
|
|
assert_equal 'dispatching/empty', EmptyController.controller_path
|
|
|
|
assert_equal EmptyController.controller_path, EmptyController.new.controller_path
|
2009-05-20 15:15:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "namespaced controller path" do
|
2009-04-29 14:42:27 -04:00
|
|
|
assert_equal 'dispatching/submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
|
|
|
|
assert_equal Submodule::ContainedEmptyController.controller_path, Submodule::ContainedEmptyController.new.controller_path
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
test "controller name" do
|
2009-04-29 14:42:27 -04:00
|
|
|
assert_equal 'empty', EmptyController.controller_name
|
|
|
|
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
|
2009-04-29 15:19:17 -04:00
|
|
|
end
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
2009-03-17 21:04:22 -04:00
|
|
|
end
|