diff options
Diffstat (limited to 'actionpack/test/new_base')
-rw-r--r-- | actionpack/test/new_base/render_file_test.rb | 110 | ||||
-rw-r--r-- | actionpack/test/new_base/render_layout_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/new_base/test_helper.rb | 24 |
3 files changed, 151 insertions, 1 deletions
diff --git a/actionpack/test/new_base/render_file_test.rb b/actionpack/test/new_base/render_file_test.rb new file mode 100644 index 0000000000..769949be0c --- /dev/null +++ b/actionpack/test/new_base/render_file_test.rb @@ -0,0 +1,110 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module RenderFile + + class BasicController < ActionController::Base + self.view_paths = "." + + 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 = File.expand_path('../fixtures/test/render_file_with_locals.erb') + render path, :locals => {:secret => 'in the sauce'} + end + end + + class TestBasic < SimpleRouteCase + testing RenderFile::BasicController + + def setup + @old_pwd = Dir.pwd + Dir.chdir(File.dirname(__FILE__)) + end + + def teardown + Dir.chdir(@old_pwd) + end + + 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
\ No newline at end of file diff --git a/actionpack/test/new_base/render_layout_test.rb b/actionpack/test/new_base/render_layout_test.rb index 5d28926cc6..7f627f86ec 100644 --- a/actionpack/test/new_base/render_layout_test.rb +++ b/actionpack/test/new_base/render_layout_test.rb @@ -6,7 +6,8 @@ module ControllerLayouts self.view_paths = [ActionView::Template::FixturePath.new( "layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI", "layouts/override.html.erb" => "Override! <%= yield %>", - "basic.html.erb" => "Hello world!" + "basic.html.erb" => "Hello world!", + "controller_layouts/implicit/layout_false.html.erb" => "hai(layout_false.html.erb)" )] def index @@ -17,6 +18,12 @@ module ControllerLayouts render :template => "basic", :layout => "override" end + def layout_false + render :layout => false + end + + + def builder_override end @@ -56,4 +63,13 @@ module ControllerLayouts get "/controller_layouts/implicit/override" assert_body "Override! Hello world!" end + + class TestLayoutOptions < SimpleRouteCase + testing ControllerLayouts::ImplicitController + + test "rendering with :layout => false leaves out the implicit layout" do + get :layout_false + assert_response "hai(layout_false.html.erb)" + end + end end
\ No newline at end of file diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index 78662dc989..a7302af060 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -59,12 +59,28 @@ class Rack::TestCase < ActiveSupport::TestCase @app ||= ActionController::Dispatcher.new end + def self.testing(klass = nil) + if klass + @testing = "/#{klass.name.underscore}".sub!(/_controller$/, '') + else + @testing + end + end + def self.get(url) setup do |test| test.get url end end + def get(thing, *args) + if thing.is_a?(Symbol) + super("#{self.class.testing}/#{thing}") + else + super + end + end + def assert_body(body) assert_equal body, Array.wrap(last_response.body).join end @@ -85,6 +101,14 @@ class Rack::TestCase < ActiveSupport::TestCase end end + def assert_response(body, status = 200, headers = {}) + assert_body body + assert_status status + headers.each do |header, value| + assert_header header, value + end + end + def assert_content_type(type) assert_equal type, last_response.headers["Content-Type"] end |