Permalink
Browse files

Example using an edge side include body part to fetch queued renderin…

…g results
  • Loading branch information...
1 parent 7c1714c commit 5d76dee329282acc918de50fecde869f1431e2f1 @jeremy jeremy committed Mar 13, 2009
Showing with 27 additions and 22 deletions.
  1. +0 −13 actionpack/lib/action_view/body_parts/open_uri.rb
  2. +27 −9 actionpack/test/template/body_parts_test.rb
@@ -1,13 +0,0 @@
-require 'action_view/body_parts/threaded'
-require 'open-uri'
-
-module ActionView
- module BodyParts
- class OpenUri < Threaded
- def initialize(url)
- url = URI::Generic === url ? url : URI.parse(url)
- super(true) { |parts| parts << url.read }
- end
- end
- end
-end
@@ -36,39 +36,49 @@ def test_flush_output_buffer
end
end
+
class QueuedPartTest < ActionController::TestCase
- class SimpleQueued < ActionView::BodyParts::Queued
+ class EdgeSideInclude < ActionView::BodyParts::Queued
+ QUEUE_REDEMPTION_URL = 'http://queue/jobs/%s'
+ ESI_INCLUDE_TAG = '<esi:include src="%s" />'
+
+ def self.redemption_tag(receipt)
+ ESI_INCLUDE_TAG % QUEUE_REDEMPTION_URL % receipt
+ end
+
protected
def submit(job)
- job
+ job.reverse
end
def redeem(receipt)
- receipt.to_s.reverse
+ self.class.redemption_tag(receipt)
end
end
class TestController < ActionController::Base
def index
- queued_render 'foo'
- queued_render 'bar'
- queued_render 'baz'
+ edge_side_include 'foo'
+ edge_side_include 'bar'
+ edge_side_include 'baz'
@performed_render = true
end
- def queued_render(job)
- response.template.punctuate_body! SimpleQueued.new(job)
+ def edge_side_include(job)
+ response.template.punctuate_body! EdgeSideInclude.new(job)
end
end
tests TestController
def test_queued_parts
get :index
- assert_equal 'oofrabzab', @response.body
+ expected = %(oof rab zab).map { |receipt| EdgeSideInclude.redemption_tag(receipt) }
+ assert_equal expected, @response.body
end
end
+
class ThreadedPartTest < ActionController::TestCase
class TestController < ActionController::Base
def index
@@ -113,7 +123,15 @@ def test_concurrent_threaded_parts
end
end
+
class OpenUriPartTest < ActionController::TestCase
+ class OpenUri < ActionView::BodyParts::Threaded
+ def initialize(url)
+ url = URI::Generic === url ? url : URI.parse(url)
+ super(true) { |parts| parts << url.read }
+ end
+ end
+
class TestController < ActionController::Base
def index
render_url 'http://localhost/foo'

0 comments on commit 5d76dee

Please sign in to comment.