Permalink
Browse files

everything green

  • Loading branch information...
1 parent dd9005f commit 42fe8320835655c2e5c89b27d5665b1fc5cb456e @grosser committed Jun 17, 2011
Showing with 25 additions and 18 deletions.
  1. +16 −11 lib/easy_esi.rb
  2. +7 −5 test/easy_esi_test.rb
  3. +1 −1 test/views/esi_enabled/_unserialize.erb
  4. +1 −1 test/views/esi_enabled/show.erb
View
@@ -2,11 +2,12 @@ class EasyEsi
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
def self.include_for(data)
- %{<esi:include src="#{serialize(data)}"/>}
+ %{<esi:include src="#{serialize(data)}"/>}.html_safe
end
def self.replace_includes(text)
- text.gsub!(%r{<esi:include src="([^"]*)"/>}) do
+ text.gsub(%r{<esi:include src="[^"]*"/>}) do |match|
+ match =~ /"(.*)"/
yield unserialize($1)
end
end
@@ -16,7 +17,7 @@ def self.unserialize(data)
end
def self.serialize(data)
- Base64.encode64 data.to_yaml
+ Base64.encode64(data.to_yaml).gsub("\n",'')
end
private
@@ -38,12 +39,15 @@ def esi_render data
# when action_cache halts the filter chain, we still need to replace esi includes
class ActionController::Caching::Actions::ActionCacheFilter
-# def filter_with_esi(controller)
-# result = filter_without_esi(controller)
-# controller.send(:render_esi) if controller.esi_enabled
-# result
-# end
-# alias_method_chain :filter, :esi
+ def filter_with_esi(controller, &block)
+ controller.instance_variable_set "@do_not_replace", true
+ result = filter_without_esi(controller, &block)
+ controller.instance_variable_set "@do_not_replace", false
+ puts controller.response_body+'filter'
+ controller.send(:render_esi) if controller.esi_enabled
+ result
+ end
+ alias_method_chain :filter, :esi
end
class ActionController::Base
@@ -57,8 +61,9 @@ def self.enable_esi
protected
def render_esi
- EasyEsi.replace_includes(controller.response_body) do |data|
- @template.render data
+ return if @do_not_replace or response_body.is_a?(File)
+ self.response_body = EasyEsi.replace_includes(response_body) do |data|
+ _render_template(data)
end
end
end
View
@@ -64,6 +64,7 @@ def initialize(*args)
def setup
@routes = ROUTES
@controller = EsiDisabledController.new
+ @controller.cache_store.clear
# @request = ActionController::TestRequest.new
# @response = ActionController::TestResponse.new
end
@@ -124,6 +125,7 @@ def setup
@controller = EsiEnabledController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+ @controller.cache_store.clear
end
test "caches actions" do
@@ -139,18 +141,18 @@ def setup
test "it renders correctly" do
get :show, :in_action => 'A', :in_esi => 'B'
- @response.body.should == "A B"
+ @response.body.strip.should == "A B"
end
test "it up-to-date esi partial when action was cached" do
get :show, :in_action => 'A', :in_esi => 'B'
get :show, :in_action => 'X', :in_esi => 'C'
- @response.body.should == "A C"
+ @response.body.strip.should == "A C"
end
test "it renders up-to-date esi-partial when action was not cached" do
get :uncached, :in_action => 'X', :in_esi => 'C'
- @response.body.should == "X C"
+ @response.body.strip.should == "X C"
end
test "it renders up-to-date esi-partial with hash" do
@@ -162,12 +164,12 @@ def setup
test "it can serialize arbitrary data" do
data = {'src' => 'something else', 1 => :x, 2 => ['"','/','___----']}
get :serialize, :render_data => data
- @response.body.should == data.inspect
+ @response.body.strip.should == data.inspect
end
test "it can send a file" do
get :send_a_file
- @response.body.is_a?(Proc).should == true
+ @response.body.should == File.read('VERSION')
end
end
@@ -1 +1 @@
-<%=data.inspect%>
+<%= data.inspect.html_safe %>
@@ -1 +1 @@
-<%= params[:in_action] %> <%= esi_render 'a_partial' %>
+<%= params[:in_action] %> <%= esi_render 'a_partial' %>

0 comments on commit 42fe832

Please sign in to comment.