Permalink
Browse files

Test we didn't break page, action caching when not streaming.

  • Loading branch information...
1 parent 3c91221 commit 6a78ebdb3312a191d8a2e51cf7e3c9717602c98c @oggy committed Apr 19, 2011
Showing with 92 additions and 15 deletions.
  1. +89 −15 spec/caching_spec.rb
  2. +3 −0 spec/support/progressive_rendering_test.rb
View
@@ -22,30 +22,104 @@
describe "action caching" do
before do
- controller.caches_action :action
push_attribute_value ActionController::Base, :cache_store, ActiveSupport::Cache::MemoryStore.new
end
after do
pop_attribute_value ActionController::Base, :cache_store
end
- describe "when no layout is used" do
- it "should render the page correctly" do
- view "a<% flush %>b"
- action { render :progressive => true, :layout => nil }
- run
- received.should == chunks('a', 'b', :end => true)
+ describe "when rendering progressively" do
+ describe "when no layout is used" do
+ before do
+ controller.caches_action :action
+ end
+
+ it "should render the page correctly" do
+ view "a<% flush %>b"
+ action { render :progressive => true, :layout => nil }
+ run
+ received.should == chunks('a', 'b', :end => true)
+ end
+
+ it "should use the cached copy if it exists" do
+ view "<% data.render_count += 1 %>a<% flush %>b"
+ action { render :progressive => true, :layout => nil }
+ data.render_count = 0
+ run
+ run
+ received.should == 'ab'
+ data.render_count.should == 1
+ end
+ end
+ end
+
+ describe "when not rendering progressively" do
+ describe "when no layout is used" do
+ before do
+ controller.caches_action :action
+ action { render :progressive => false, :layout => nil }
+ end
+
+ it "should render the page correctly" do
+ view "a<% flush %>b"
+ run
+ received.should == 'ab'
+ end
+
+ it "should use the cached copy if it exists" do
+ view "<% data.render_count += 1 %>a<% flush %>b"
+ data.render_count = 0
+ run
+ run
+ received.should == 'ab'
+ data.render_count.should == 1
+ end
end
- it "should use the cached copy if it exists" do
- view "<% data.render_count += 1 %>a<% flush %>b"
- action { render :progressive => true, :layout => nil }
- data.render_count = 0
- run
- run
- received.should == 'ab'
- data.render_count.should == 1
+ describe "when the layout is cached" do
+ before do
+ controller.caches_action :action, :layout => true
+ action { render :progressive => false, :layout => 'layout' }
+ end
+
+ it "should cache the layout" do
+ layout "<% data.render_count += 1 %>[<%= yield %>]"
+ view "view"
+ data.render_count = 0
+
+ run
+ received.should == '[view]'
+ data.render_count.should == 1
+
+ run
+ received.should == '[view]'
+ data.render_count.should == 1
+ end
+ end
+
+ describe "when the layout is not cached" do
+ before do
+ controller.caches_action :action, :layout => false
+ # AC always does render(:layout => true) to render the layout when the
+ # body is cached, even if an explicit layout name is given. Hence, our
+ # layout name must match the controller name.
+ action { render :progressive => false, :layout => 'test' }
+ end
+
+ it "should not cache the layout" do
+ template 'layouts/test', "<% data.render_count += 1 %>[<%= yield %>]"
+ view "view"
+ data.render_count = 0
+
+ run
+ received.should == '[view]'
+ data.render_count.should == 1
+
+ run
+ received.should == '[view]'
+ data.render_count.should == 2
+ end
end
end
end
@@ -15,6 +15,9 @@ def setup_progressive_rendering_test
ActionController::Routing::Routes.add_route('/', :controller => 'test', :action => 'action')
push_constant_value Object, :TestController, Class.new(Controller)
+ # Since we use Class.new, the class name is undefined in AC::Layout's
+ # inherited hook, and so layout is not automatically called - do it now.
+ TestController.layout('test', {}, true)
TestController.view_paths = [VIEW_PATH]
@log_buffer = ''
TestController.logger = Logger.new(StringIO.new(@log_buffer))

0 comments on commit 6a78ebd

Please sign in to comment.