1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/controller/new_base/render_file_test.rb

100 lines
2.8 KiB
Ruby
Raw Normal View History

2009-09-19 13:10:41 -04:00
require 'abstract_unit'
2009-05-13 20:00:36 -04:00
module RenderFile
class BasicController < ActionController::Base
self.view_paths = File.dirname(__FILE__)
2009-05-13 20:00:36 -04:00
def index
render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def with_instance_variables
@secret = 'in the sauce'
render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def without_file_key
render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def without_file_key_with_instance_variable
@secret = 'in the sauce'
render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def relative_path
@secret = 'in the sauce'
render :file => '../../fixtures/test/render_file_with_ivar'
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def relative_path_with_dot
@secret = 'in the sauce'
render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def pathname
@secret = 'in the sauce'
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
2009-05-13 20:00:36 -04:00
end
2009-05-13 20:00:36 -04:00
def with_locals
path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
2009-05-13 20:00:36 -04:00
render :file => path, :locals => {:secret => 'in the sauce'}
end
2009-05-13 20:00:36 -04:00
def without_file_key_with_locals
path = FIXTURES.join('test/render_file_with_locals.erb').to_s
2009-05-13 20:00:36 -04:00
render path, :locals => {:secret => 'in the sauce'}
end
end
class TestBasic < Rack::TestCase
2009-05-13 20:00:36 -04:00
testing RenderFile::BasicController
2009-05-13 20:00:36 -04:00
test "rendering simple template" do
get :index
assert_response "Hello world!"
end
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-05-13 20:00:36 -04:00
test "rendering path without specifying the :file key" do
get :without_file_key
assert_response "Hello world!"
end
2009-05-13 20:00:36 -04:00
test "rendering path without specifying the :file key with ivar" do
get :without_file_key_with_instance_variable
assert_response "The secret is in the sauce\n"
end
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-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-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-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
2009-05-13 20:00:36 -04:00
test "rendering path without specifying the :file key with locals" do
get :without_file_key_with_locals
assert_response "The secret is in the sauce\n"
end
end
end