spec/plugin/render_spec.rb in roda-2.0.0 vs spec/plugin/render_spec.rb in roda-2.1.0

- old
+ new

@@ -105,10 +105,22 @@ end body.strip.should == "<title>Alternative Layout: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>" end + it "locals overrides" do + app(:bare) do + plugin :render, :views=>"./spec/views", :locals=>{:title=>'Home', :b=>'B'}, :layout_opts=>{:template=>'multiple-layout', :locals=>{:title=>'Roda', :a=>'A'}} + + route do |r| + view("multiple", :locals=>{:b=>"BB"}, :layout_opts=>{:locals=>{:a=>'AA'}}) + end + end + + body.strip.should == "Roda:AA::Home:BB" + end + it ":layout=>true/false/string/hash/not-present respects plugin layout switch and template" do app(:bare) do plugin :render, :views=>"./spec/views", :layout_opts=>{:template=>'layout-yield', :locals=>{:title=>'a'}} route do |r| @@ -147,21 +159,48 @@ body('/f').gsub("\n", '').should == "bar" body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar" body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar" app.plugin :render, :layout=>nil - body.gsub("\n", '').should == "<title>Alternative Layout: a</title>bar" + body.gsub("\n", '').should == "HeaderbarFooter" body('/a').gsub("\n", '').should == "bar" body('/f').gsub("\n", '').should == "bar" body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar" body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar" app.plugin :render, :layout=>false + body.gsub("\n", '').should == "HeaderbarFooter" + body('/a').gsub("\n", '').should == "bar" + body('/f').gsub("\n", '').should == "bar" + body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar" + body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar" + + app.plugin :render, :layout_opts=>{:template=>'layout-alternative', :locals=>{:title=>'a'}} body.gsub("\n", '').should == "<title>Alternative Layout: a</title>bar" body('/a').gsub("\n", '').should == "bar" body('/f').gsub("\n", '').should == "bar" body('/s').gsub("\n", '').should == "<title>Roda: a</title>bar" body('/h').gsub("\n", '').should == "<title>Roda: a</title>bar" + end + + it "app :root option affects :views default" do + app + app.plugin :render + app.render_opts[:views].should == File.join(Dir.pwd, 'views') + + app.opts[:root] = '/foo' + app.plugin :render + app.render_opts[:views].should == '/foo/views' + + app.opts[:root] = '/foo/bar' + app.plugin :render + app.render_opts[:views].should == '/foo/bar/views' + + app.opts[:root] = nil + app.plugin :render + app.render_opts[:views].should == File.join(Dir.pwd, 'views') + app.plugin :render, :views=>'bar' + app.render_opts[:views].should == File.join(Dir.pwd, 'bar') end it "inline layouts and inline views" do app(:render) do view({:inline=>'bar'}, :layout=>{:inline=>'Foo: <%= yield %>'})