diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-10-10 17:15:11 +0100 |
commit | 66ee2654ff243f03595a402fa15e1eea1b5b45be (patch) | |
tree | 3f1055e03082f0c767719e8cba5155e4207779e0 /actionpack/test/controller/new_base/render_file_test.rb | |
parent | dd2779e1b83b4d867d47dd286ec0c919f5df12a9 (diff) | |
parent | b9ce8216fa849a47ad0b0f99fa510e226a23c12e (diff) | |
download | rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.gz rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.tar.bz2 rails-66ee2654ff243f03595a402fa15e1eea1b5b45be.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/controller/new_base/render_file_test.rb')
-rw-r--r-- | actionpack/test/controller/new_base/render_file_test.rb | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/actionpack/test/controller/new_base/render_file_test.rb b/actionpack/test/controller/new_base/render_file_test.rb new file mode 100644 index 0000000000..8b2fdf8f96 --- /dev/null +++ b/actionpack/test/controller/new_base/render_file_test.rb @@ -0,0 +1,99 @@ +require 'abstract_unit' + +module RenderFile + class BasicController < ActionController::Base + self.view_paths = File.dirname(__FILE__) + + def index + render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) + end + + def with_instance_variables + @secret = 'in the sauce' + render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb') + end + + def without_file_key + render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world]) + end + + def without_file_key_with_instance_variable + @secret = 'in the sauce' + render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb') + end + + def relative_path + @secret = 'in the sauce' + render :file => '../../fixtures/test/render_file_with_ivar' + end + + def relative_path_with_dot + @secret = 'in the sauce' + render :file => '../../fixtures/test/dot.directory/render_file_with_ivar' + end + + def pathname + @secret = 'in the sauce' + render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb]) + end + + def with_locals + path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb') + render :file => path, :locals => {:secret => 'in the sauce'} + end + + def without_file_key_with_locals + path = FIXTURES.join('test/render_file_with_locals.erb').to_s + render path, :locals => {:secret => 'in the sauce'} + end + end + + class TestBasic < Rack::TestCase + testing RenderFile::BasicController + + test "rendering simple template" do + get :index + assert_response "Hello world!" + end + + test "rendering template with ivar" do + get :with_instance_variables + assert_response "The secret is in the sauce\n" + end + + test "rendering path without specifying the :file key" do + get :without_file_key + assert_response "Hello world!" + end + + 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 + + test "rendering a relative path" do + get :relative_path + assert_response "The secret is in the sauce\n" + end + + test "rendering a relative path with dot" do + get :relative_path_with_dot + assert_response "The secret is in the sauce\n" + end + + test "rendering a Pathname" do + get :pathname + assert_response "The secret is in the sauce\n" + end + + test "rendering file with locals" do + get :with_locals + assert_response "The secret is in the sauce\n" + end + + 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 |