rails/actionpack/test/controller/new_base/render_partial_test.rb

64 lines
2.1 KiB
Ruby
Raw Normal View History

2009-09-19 17:10:41 +00:00
require 'abstract_unit'
2009-05-14 22:30:35 +00:00
module RenderPartial
2009-05-14 22:30:35 +00:00
class BasicController < ActionController::Base
self.view_paths = [ActionView::FixtureResolver.new(
"render_partial/basic/_basic.html.erb" => "BasicPartial!",
"render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>",
"render_partial/basic/with_json.html.erb" => "<%= render 'with_json.json' %>",
"render_partial/basic/_with_json.json.erb" => "<%= render 'final' %>",
2010-09-17 20:39:14 +00:00
"render_partial/basic/_final.json.erb" => "{ final: json }",
"render_partial/basic/overriden.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'overriden' %><%= @test_unchanged %>",
"render_partial/basic/_overriden.html.erb" => "ParentPartial!",
"render_partial/child/_overriden.html.erb" => "OverridenPartial!"
2009-05-14 22:30:35 +00:00
)]
def html_with_json_inside_json
render :action => "with_json"
end
2009-05-14 22:30:35 +00:00
def changing
@test_unchanged = 'hello'
render :action => "basic"
end
2010-09-17 20:39:14 +00:00
def overriden
@test_unchanged = 'hello'
end
2009-05-14 22:30:35 +00:00
end
2010-09-17 20:39:14 +00:00
class ChildController < BasicController; end
class TestPartial < Rack::TestCase
2009-05-14 22:30:35 +00:00
testing BasicController
2009-05-14 22:30:35 +00:00
test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do
get :changing
assert_response("goodbyeBasicPartial!goodbye")
2009-05-14 22:30:35 +00:00
end
test "rendering a template with renders another partial with other format that renders other partial in the same format" do
get :html_with_json_inside_json
assert_content_type "text/html; charset=utf-8"
assert_response "{ final: json }"
end
2009-05-14 22:30:35 +00:00
end
2010-09-17 20:39:14 +00:00
class TestInheritedPartial < Rack::TestCase
testing ChildController
test "partial from parent controller gets picked if missing in child one" do
get :changing
assert_response("goodbyeBasicPartial!goodbye")
end
test "partial from child controller gets picked" do
get :overriden
assert_response("goodbyeOverridenPartial!goodbye")
end
end
end