require File.expand_path('../test_helper', __FILE__) describe Renee::Render do describe "#render" do after { remove_views } it "should allow rendering string with engine" do mock_app { path("/a") { get { inline! "
test
", :erb } } path("/b") { get { inline! "<%= foo %>
", :erb, :locals => { :foo => "bar" } } } path("/c") { get { halt inline("<%= foo %>
", :erb, :locals => { :foo => "bar" }) } } } get('/a') assert_equal 200, response.status assert_equal "test
", response.body get('/b') assert_equal 200, response.status assert_equal "bar
", response.body get('/c') assert_equal 200, response.status assert_equal "bar
", response.body end # string, with engine it "should allow rendering template file with engine" do create_view :index, "%p test", :haml create_view :foo, "%p= foo", :haml mock_app { path("/a") { get { render! 'index', :haml } } path("/b") { get { render! 'foo', :haml, :locals => { :foo => "bar" } } } path("/c") { get { halt render('foo', :haml, :locals => { :foo => "bar" }) } } } get('/a') assert_equal 200, response.status assert_equal "test
\n", response.body get('/b') assert_equal 200, response.status assert_equal "bar
\n", response.body get('/c') assert_equal 200, response.status assert_equal "bar
\n", response.body end # template, with engine it "should allow rendering template file with unspecified engine" do create_view :index, "%p test", :haml create_view :foo, "%p= foo", :haml mock_app { path("/a") { get { render! "index" } } path("/b") { get { render! "foo.haml", :locals => { :foo => "bar" } } } } get('/a') assert_equal 200, response.status assert_equal "test
\n", response.body get('/b') assert_equal 200, response.status assert_equal "bar
\n", response.body end # template, unspecified engine it "should allow rendering template file with engine and layout" do create_view :index, "%p test", :haml create_view :foo, "%p= foo", :haml create_view :layout, "%div.wrapper= yield", :haml mock_app { path("/a") { get { render! 'index', :haml, :layout => :layout } } path("/b") { get { render! 'foo', :layout => :layout, :locals => { :foo => "bar" } } } } get('/a') assert_equal 200, response.status assert_equal %Q{test
bar
test
bar
bar
\n}, response.body end # with engine and layout specified it "should allow rendering template with different layout engines" do create_view :index, "%p test", :haml create_view :foo, "%p= foo", :haml create_view :base, "test
\nbar
\ntest
\nstart\nbanana
\nend\nbar
\n", response.body end # partials, locals it "should allow partials to be rendered with object" do create_view "_foo", %Q{start\n%p= foo\nend}, :haml create_view :index, %Q{%p test\n= partial("foo", :object => "banana")\n%p bar}, :haml mock_app { path("/").get { render! "index" } } get('/') assert_equal 200, response.status assert_equal "test
\nstart\nbanana
\nend\nbar
\n", response.body end # partials, object it "should allow partials to be rendered with collection" do create_view "_foo", %Q{%p= foo}, :haml create_view :index, %Q{%p test\n= partial("foo", :collection => ["banana", "strawberry"])\n%p bar}, :haml mock_app { path("/").get { render! "index" } } get('/') assert_equal 200, response.status assert_equal "test
\nbanana
\n\nstrawberry
\nbar
\n", response.body end # partials, collection end end