Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 6a78ebdb3312a191d8a2e51cf7e3c9717602c98c 1 parent 3c91221
@oggy authored
Showing with 92 additions and 15 deletions.
  1. +89 −15 spec/caching_spec.rb
  2. +3 −0  spec/support/progressive_rendering_test.rb
View
104 spec/caching_spec.rb
@@ -22,7 +22,6 @@
describe "action caching" do
before do
- controller.caches_action :action
push_attribute_value ActionController::Base, :cache_store, ActiveSupport::Cache::MemoryStore.new
end
@@ -30,22 +29,97 @@
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
View
3  spec/support/progressive_rendering_test.rb
@@ -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))
Please sign in to comment.
Something went wrong with that request. Please try again.