2009-09-19 13:10:41 -04:00
|
|
|
require 'abstract_unit'
|
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
|
2010-01-17 23:06:28 -05:00
|
|
|
before_filter :authenticate
|
|
|
|
|
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
|
2010-01-17 23:06:28 -05:00
|
|
|
ret = (self.response_body = "success")
|
2009-03-17 21:04:22 -04:00
|
|
|
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
|
2010-01-17 23:06:28 -05:00
|
|
|
|
|
|
|
def show_actions
|
2010-01-20 01:35:09 -05:00
|
|
|
render :text => "actions: #{action_methods.to_a.sort.join(', ')}"
|
2010-01-17 23:06:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
def authenticate
|
|
|
|
end
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
class EmptyController < ActionController::Base ; end
|
2010-06-22 14:47:31 -04:00
|
|
|
class SubEmptyController < EmptyController ; end
|
|
|
|
class NonDefaultPathController < ActionController::Base
|
|
|
|
def self.controller_path; "i_am_not_default"; end
|
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
|
|
|
|
module Submodule
|
|
|
|
class ContainedEmptyController < ActionController::Base ; end
|
2010-06-22 14:47:31 -04:00
|
|
|
class ContainedSubEmptyController < ContainedEmptyController ; end
|
|
|
|
class ContainedNonDefaultPathController < ActionController::Base
|
2011-05-29 15:40:24 -04:00
|
|
|
def self.controller_path; "i_am_extremely_not_default"; end
|
2010-06-22 14:47:31 -04:00
|
|
|
end
|
2009-05-20 15:15:06 -04:00
|
|
|
end
|
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class BaseTest < Rack::TestCase
|
2009-05-20 15:15:06 -04:00
|
|
|
# :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"
|
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"
|
|
|
|
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-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
|
|
|
|
|
2010-06-22 14:47:31 -04:00
|
|
|
test "non-default controller path" do
|
|
|
|
assert_equal 'i_am_not_default', NonDefaultPathController.controller_path
|
|
|
|
assert_equal NonDefaultPathController.controller_path, NonDefaultPathController.new.controller_path
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sub controller path" do
|
|
|
|
assert_equal 'dispatching/sub_empty', SubEmptyController.controller_path
|
|
|
|
assert_equal SubEmptyController.controller_path, SubEmptyController.new.controller_path
|
|
|
|
end
|
|
|
|
|
2009-05-20 15:15:06 -04:00
|
|
|
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
|
|
|
|
2010-06-22 14:47:31 -04:00
|
|
|
test "namespaced non-default controller path" do
|
2011-05-29 15:40:24 -04:00
|
|
|
assert_equal 'i_am_extremely_not_default', Submodule::ContainedNonDefaultPathController.controller_path
|
2010-06-22 14:47:31 -04:00
|
|
|
assert_equal Submodule::ContainedNonDefaultPathController.controller_path, Submodule::ContainedNonDefaultPathController.new.controller_path
|
|
|
|
end
|
|
|
|
|
|
|
|
test "namespaced sub controller path" do
|
|
|
|
assert_equal 'dispatching/submodule/contained_sub_empty', Submodule::ContainedSubEmptyController.controller_path
|
|
|
|
assert_equal Submodule::ContainedSubEmptyController.controller_path, Submodule::ContainedSubEmptyController.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
|
2010-01-17 23:06:28 -05:00
|
|
|
|
2010-06-22 14:47:31 -04:00
|
|
|
test "non-default path controller name" do
|
|
|
|
assert_equal 'non_default_path', NonDefaultPathController.controller_name
|
|
|
|
assert_equal 'contained_non_default_path', Submodule::ContainedNonDefaultPathController.controller_name
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sub controller name" do
|
|
|
|
assert_equal 'sub_empty', SubEmptyController.controller_name
|
|
|
|
assert_equal 'contained_sub_empty', Submodule::ContainedSubEmptyController.controller_name
|
|
|
|
end
|
|
|
|
|
2010-01-17 23:06:28 -05:00
|
|
|
test "action methods" do
|
|
|
|
assert_equal Set.new(%w(
|
2010-01-19 06:22:22 -05:00
|
|
|
index
|
2010-01-17 23:06:28 -05:00
|
|
|
modify_response_headers
|
|
|
|
modify_response_body_twice
|
|
|
|
modify_response_body
|
|
|
|
show_actions
|
|
|
|
)), SimpleController.action_methods
|
|
|
|
|
|
|
|
assert_equal Set.new, EmptyController.action_methods
|
|
|
|
assert_equal Set.new, Submodule::ContainedEmptyController.action_methods
|
|
|
|
|
|
|
|
get "/dispatching/simple/show_actions"
|
2010-01-19 06:22:22 -05:00
|
|
|
assert_body "actions: index, modify_response_body, modify_response_body_twice, modify_response_headers, show_actions"
|
2010-01-17 23:06:28 -05:00
|
|
|
end
|
2009-03-12 15:19:13 -04:00
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|