spec/plugin/render_spec.rb in roda-2.22.0 vs spec/plugin/render_spec.rb in roda-2.23.0
- old
+ new
@@ -351,17 +351,17 @@
body('/a').must_equal "1"
body('/b').must_equal "2"
body('/c').must_equal "3"
end
- it "Default to :cache=>false in development mode" do
+ it "Default to :explicit_cache=>true in development mode" do
with_rack_env('development') do
app(:render){}
end
- app.render_opts[:cache].must_be_nil
+ app.render_opts[:explicit_cache].must_equal true
app(:render){}
- app.render_opts[:cache].wont_equal nil
+ app.render_opts[:explicit_cache].must_equal false
end
it "Support :cache=>false option to disable template caching" do
app(:bare) do
plugin :render, :views=>"./spec/views"
@@ -377,10 +377,61 @@
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].must_be_nil
body('/b').strip.must_equal "a"
app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].wont_equal nil
end
+ it "Support :cache=>false option to disable template caching even when :cache_key is given" do
+ app(:bare) do
+ plugin :render, :views=>"./spec/views"
+
+ route do |r|
+ @a = 'a'
+ r.is('a'){render('iv', :cache=>false, :cache_key=>:foo)}
+ render('iv', :cache_key=>:foo)
+ end
+ end
+
+ body('/a').strip.must_equal "a"
+ app.render_opts[:cache][:foo].must_be_nil
+ body('/b').strip.must_equal "a"
+ app.render_opts[:cache][:foo].wont_equal nil
+ end
+
+ it "Support :explicit_cache option to disable caching by default, but still allow caching on a per-call basis" do
+ app(:bare) do
+ plugin :render, :views=>"./spec/views", :explicit_cache=>true
+
+ route do |r|
+ @a = 'a'
+ r.is('a'){render('iv')}
+ render('iv', :cache=>true)
+ end
+ end
+
+ body('/a').strip.must_equal "a"
+ app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].must_be_nil
+ body('/b').strip.must_equal "a"
+ app.render_opts[:cache][File.expand_path('spec/views/iv.erb')].wont_equal nil
+ end
+
+ it "Support :explicit_cache plugin option with :cache_key render option" do
+ app(:bare) do
+ plugin :render, :views=>"./spec/views", :explicit_cache=>true
+
+ route do |r|
+ @a = 'a'
+ r.is('a'){render('iv', :cache_key=>:foo)}
+ render('iv', :cache=>true, :cache_key=>:foo)
+ end
+ end
+
+ body('/a').strip.must_equal "a"
+ app.render_opts[:cache][:foo].must_be_nil
+ body('/b').strip.must_equal "a"
+ app.render_opts[:cache][:foo].wont_equal nil
+ end
+
it "Support :cache=>true option to enable template caching when :template_block is used" do
c = Class.new do
def initialize(path, *, &block)
@path = path
@block = block
@@ -435,26 +486,39 @@
end
body.must_equal "1-2"
end
- it "render_opts inheritance" do
+ it "should dup render_opts when subclasses, including an empty cache" do
c = Class.new(Roda)
c.plugin :render
+ c.render_opts[:cache][:foo] = 1
sc = Class.new(c)
c.render_opts.wont_be_same_as(sc.render_opts)
c.render_opts[:cache].wont_be_same_as(sc.render_opts[:cache])
+ sc.render_opts[:cache][:foo].must_be_nil
end
- it "render plugin call should not override options" do
+ it "should use same render_opts as superclass when inheriting if :inherit_cache option is used" do
c = Class.new(Roda)
+ c.plugin :render, :inherit_cache=>true
+ c.render_opts[:cache][:foo] = 1
+ sc = Class.new(c)
+
+ c.render_opts.wont_be_same_as(sc.render_opts)
+ c.render_opts[:cache].wont_be_same_as(sc.render_opts[:cache])
+ sc.render_opts[:cache][:foo].must_equal 1
+ end
+
+ it "render plugin call should not override existing options" do
+ c = Class.new(Roda)
c.plugin :render, :layout=>:foo
c.plugin :render
c.render_opts[:layout].must_equal :foo
end
- it "with caching disabled" do
+ it "should not use cache in subclass if caching disabled in superclass" do
app(:bare) do
plugin :render, :views=>"./spec/views", :cache=>false
route do |r|
view(:inline=>"Hello <%= name %>: <%= render_opts[:cache] %>", :locals=>{:name => "Agent Smith"}, :layout=>nil)