spec/plugin/render_spec.rb in roda-2.28.0 vs spec/plugin/render_spec.rb in roda-2.29.0
- old
+ new
@@ -48,11 +48,11 @@
body("/about").strip.must_equal "<h1>About Roda</h1>"
body("/home").strip.must_equal "<title>Roda: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
body("/inline").strip.must_equal "Hello <%= name %>"
end
- it "with str as ext" do
+ deprecated "with str as ext" do
app.plugin :render, :ext => "str"
body("/about").strip.must_equal "<h1>About Roda</h1>"
body("/home").strip.must_equal "<title>Roda: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
body("/inline").strip.must_equal "Hello <%= name %>"
end
@@ -67,11 +67,11 @@
body("/home").strip.must_equal "a<h1>Home</h1>\n<p>Hello Agent Smith</p>\nb"
end
end
describe "render plugin with :layout_opts=>{:merge_locals=>true}" do
- before do
+ deprecated "should choose method opts before plugin opts, and layout specific before locals" do
app(:bare) do
plugin :render, :views=>"./spec/views", :check_paths=>true, :locals=>{:a=>1, :b=>2, :c=>3, :d=>4, :e=>5}, :layout_opts=>{:inline=>'<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>|<%= f %>|<%= yield %>', :merge_locals=>true, :locals=>{:a=>-1, :f=>6}}
route do |r|
r.on "base" do
@@ -83,13 +83,11 @@
r.on "no_merge" do
view(:inline=>'(<%= a %>|<%= b %>|<%= c %>|<%= d %>|<%= e %>)', :locals=>{:b=>-2, :d=>-4, :f=>-6}, :layout_opts=>{:merge_locals=>false, :locals=>{:d=>0, :c=>-3, :e=>-5}})
end
end
end
- end
- it "should choose method opts before plugin opts, and layout specific before locals" do
body("/base").must_equal '-1|2|3|4|5|6|(1|2|3|4|5)'
body("/override").must_equal '-1|-2|-3|0|-5|-6|(1|-2|3|-4|5)'
body("/no_merge").must_equal '-1|2|-3|0|-5|6|(1|-2|3|-4|5)'
end
end
@@ -107,10 +105,23 @@
end
body.gsub(/\n+/, "\n").must_equal "Header\nThis is the actual content.\nFooter\n"
end
+ it "should have :layout_opts=>:views plugin option respect :root app option" do
+ app(:bare) do
+ self.opts[:root] = 'spec'
+ plugin :render, :layout_opts=>{:views=>"views"}, :allowed_paths=>["spec/views"]
+
+ route do |r|
+ view(:content=>'a', :layout_opts=>{:locals=>{:title=>"Home"}})
+ end
+ end
+
+ body.strip.must_equal "<title>Roda: Home</title>\na"
+ end
+
it "views without default layouts" do
app(:bare) do
plugin :render, :views=>"./spec/views", :layout=>false
route do |r|
@@ -131,11 +142,11 @@
end
body.strip.must_equal "<title>Alternative Layout: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"
end
- it "locals overrides" do
+ deprecated "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'}})
@@ -143,11 +154,11 @@
end
body.strip.must_equal "Roda:AA::Home:BB"
end
- it ":layout=>true/false/string/hash/not-present respects plugin layout switch and template" do
+ deprecated ":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|
opts = {:content=>'bar'}
@@ -360,10 +371,30 @@
app.render_opts[:explicit_cache].must_equal true
app(:render){}
app.render_opts[:explicit_cache].must_equal false
end
+ deprecated "Support :cache=>false plugin option to disable template caching, even when :cache=>true method option is given" do
+ app(:bare) do
+ plugin :render, :views=>"./spec/views", :cache=>false
+
+ route do |r|
+ @a = 'a'
+ r.is('a'){render('iv', :cache=>false)}
+ r.is('b'){render('iv', :cache=>true)}
+ render('iv')
+ end
+ end
+
+ body('/a').strip.must_equal "a"
+ app.render_opts[:cache].must_equal false
+ body('/b').strip.must_equal "a"
+ app.render_opts[:cache].must_equal false
+ body('/c').strip.must_equal "a"
+ app.render_opts[:cache].must_equal false
+ end
+
it "Support :cache=>false option to disable template caching" do
app(:bare) do
plugin :render, :views=>"./spec/views"
route do |r|
@@ -457,11 +488,11 @@
app.render_opts[:cache][['iv', c, nil, nil, proca]].must_be_nil
body('/b').strip.must_equal "iv-a"
app.render_opts[:cache][['iv', c, nil, nil, proca]].wont_equal nil
end
- it "Support :cache_key option to force the key used when caching" do
+ it "Support :cache_key option to force the key used when caching, unless :cache=>false option is used" do
app(:bare) do
plugin :render, :views=>"./spec/views"
route do |r|
@a = 'a'
@@ -542,11 +573,11 @@
body("/inline").strip.must_equal "Hello Agent Smith: false"
Class.new(app).render_opts[:cache].must_equal false
end
- it "with :check_paths=>true" do
+ it "with :check_paths=>true plugin option used" do
render_opts = {}
app(:bare) do
plugin :render, :views=>"./spec/views", :check_paths=>true
route do |r|
@@ -595,9 +626,53 @@
render_opts[:check_paths] = true
body.strip.must_equal "b"
proc{req("/a")}.must_raise Roda::RodaError
req("/c")
+ end
+
+ deprecated "with :check_paths plugin option not set" do
+ render_opts = {}
+ app(:bare) do
+ plugin :render, :views=>"./spec/views"
+
+ route do |r|
+ r.get 'a' do
+ render("a", render_opts)
+ end
+
+ r.get 'c' do
+ render("about/_test", :locals=>{:title=>'a'})
+ end
+
+ render("b", render_opts)
+ end
+ end
+
+ body.strip.must_equal "b"
+ body("/a").strip.must_equal 'a'
+ body("/c").strip.must_equal "<h1>Subdir: a</h1>"
+
+ app.plugin :render, :allowed_paths=>[]
+ body.strip.must_equal "b"
+ body("/a").strip.must_equal 'a'
+ body("/c").strip.must_equal "<h1>Subdir: a</h1>"
+
+ app.plugin :render, :allowed_paths=>['spec/views/about']
+ body.strip.must_equal "b"
+ body("/a").strip.must_equal 'a'
+ body("/c").strip.must_equal "<h1>Subdir: a</h1>"
+
+ app.plugin :render, :allowed_paths=>%w'spec/views/about spec/views/b'
+ body.strip.must_equal "b"
+ body("/a").strip.must_equal 'a'
+ body("/c").strip.must_equal "<h1>Subdir: a</h1>"
+
+ render_opts[:check_paths] = true
+ app.plugin :render, :check_paths=>false
+ body.strip.must_equal "b"
+ proc{req("/a")}.must_raise Roda::RodaError
+ body("/c").strip.must_equal "<h1>Subdir: a</h1>"
end
it "with a cache_class set" do
app(:bare) do
test_cache = Class.new(Roda::RodaCache) do