2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2009-03-19 16:35:39 -04:00
|
|
|
|
2009-04-27 21:21:26 -04:00
|
|
|
module RenderImplicitAction
|
|
|
|
class SimpleController < ::ApplicationController
|
2009-06-17 18:32:55 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
2011-04-02 22:45:07 -04:00
|
|
|
"render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
|
|
|
|
"render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!",
|
|
|
|
"render_implicit_action/simple/not_implemented.html.erb" => "Not Implemented"
|
2017-05-15 10:17:28 -04:00
|
|
|
), ActionView::FileSystemResolver.new(File.expand_path("../../controller", __dir__))]
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-04-27 21:21:26 -04:00
|
|
|
def hello_world() end
|
2009-03-19 16:35:39 -04:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class RenderImplicitActionTest < Rack::TestCase
|
2009-05-20 15:15:06 -04:00
|
|
|
test "render a simple action with new explicit call to render" do
|
|
|
|
get "/render_implicit_action/simple/hello_world"
|
|
|
|
|
|
|
|
assert_body "Hello world!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
test "render an action with a missing method and has special characters" do
|
|
|
|
get "/render_implicit_action/simple/hyphen-ated"
|
|
|
|
|
|
|
|
assert_body "Hello hyphen-ated!"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2011-03-30 11:22:05 -04:00
|
|
|
|
2011-04-02 22:45:07 -04:00
|
|
|
test "render an action called not_implemented" do
|
|
|
|
get "/render_implicit_action/simple/not_implemented"
|
|
|
|
|
|
|
|
assert_body "Not Implemented"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
2014-04-17 15:50:39 -04:00
|
|
|
test "render does not traverse the file system" do
|
|
|
|
assert_raises(AbstractController::ActionNotFound) do
|
|
|
|
action_name = %w(.. .. fixtures shared).join(File::SEPARATOR)
|
|
|
|
SimpleController.action(action_name).call(Rack::MockRequest.env_for("/"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-06 12:39:10 -04:00
|
|
|
test "available_action? returns true for implicit actions" do
|
|
|
|
assert SimpleController.new.available_action?(:hello_world)
|
|
|
|
assert SimpleController.new.available_action?(:"hyphen-ated")
|
|
|
|
assert SimpleController.new.available_action?(:not_implemented)
|
2011-03-30 11:22:05 -04:00
|
|
|
end
|
2014-04-17 15:50:39 -04:00
|
|
|
|
|
|
|
test "available_action? does not allow File::SEPARATOR on the name" do
|
|
|
|
action_name = %w(evil .. .. path).join(File::SEPARATOR)
|
|
|
|
assert_equal false, SimpleController.new.available_action?(action_name.to_sym)
|
|
|
|
|
|
|
|
action_name = %w(evil path).join(File::SEPARATOR)
|
|
|
|
assert_equal false, SimpleController.new.available_action?(action_name.to_sym)
|
|
|
|
end
|
2009-04-29 20:32:39 -04:00
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|