2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2009-05-13 20:00:36 -04:00
|
|
|
|
|
|
|
module RenderFile
|
|
|
|
class BasicController < ActionController::Base
|
2017-05-15 10:17:28 -04:00
|
|
|
self.view_paths = __dir__
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def index
|
2017-05-15 10:17:28 -04:00
|
|
|
render file: File.expand_path("../../fixtures/test/hello_world", __dir__)
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def with_instance_variables
|
2016-08-06 12:54:50 -04:00
|
|
|
@secret = "in the sauce"
|
2017-05-15 10:17:28 -04:00
|
|
|
render file: File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def relative_path
|
2016-08-06 12:54:50 -04:00
|
|
|
@secret = "in the sauce"
|
2016-08-06 13:35:13 -04:00
|
|
|
render file: "../../fixtures/test/render_file_with_ivar"
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def relative_path_with_dot
|
2016-08-06 12:54:50 -04:00
|
|
|
@secret = "in the sauce"
|
2016-08-06 13:35:13 -04:00
|
|
|
render file: "../../fixtures/test/dot.directory/render_file_with_ivar"
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def pathname
|
2016-08-06 12:54:50 -04:00
|
|
|
@secret = "in the sauce"
|
2017-05-15 10:17:28 -04:00
|
|
|
render file: Pathname.new(__dir__).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
def with_locals
|
2017-05-15 10:17:28 -04:00
|
|
|
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
|
2016-08-16 03:30:11 -04:00
|
|
|
render file: path, locals: { secret: "in the sauce" }
|
2009-05-13 20:00:36 -04:00
|
|
|
end
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-10-04 00:18:32 -04:00
|
|
|
class TestBasic < Rack::TestCase
|
2009-05-13 20:00:36 -04:00
|
|
|
testing RenderFile::BasicController
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering simple template" do
|
|
|
|
get :index
|
|
|
|
assert_response "Hello world!"
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering template with ivar" do
|
|
|
|
get :with_instance_variables
|
|
|
|
assert_response "The secret is in the sauce\n"
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering a relative path" do
|
|
|
|
get :relative_path
|
|
|
|
assert_response "The secret is in the sauce\n"
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering a relative path with dot" do
|
|
|
|
get :relative_path_with_dot
|
|
|
|
assert_response "The secret is in the sauce\n"
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering a Pathname" do
|
|
|
|
get :pathname
|
|
|
|
assert_response "The secret is in the sauce\n"
|
|
|
|
end
|
2009-10-03 23:02:51 -04:00
|
|
|
|
2009-05-13 20:00:36 -04:00
|
|
|
test "rendering file with locals" do
|
|
|
|
get :with_locals
|
|
|
|
assert_response "The secret is in the sauce\n"
|
|
|
|
end
|
|
|
|
end
|
2009-09-13 17:30:27 -04:00
|
|
|
end
|