Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing bug with blocks being past into missing methods.

  • Loading branch information...
commit 28725f2923274adceeb042b93401de3ab9095200 1 parent 0ca0998
@forrest authored
View
8 lib/prawnto/template_handlers/renderer.rb
@@ -40,20 +40,20 @@ def push_instance_variables_to(object, exclude = [])
end
# This method is a little hacky with pushing the instance variables back. I would prefer to use bindings, but wasn't having much luck.
- def method_missing(m, *args)
+ def method_missing(m, *args, &block)
begin
super
rescue
if pdf.respond_to?(m.to_s)
- pdf.send(m, *args)
+ pdf.send(m, *args, &block)
elsif @calling_object.respond_to?(m.to_s)
push_instance_variables_to @calling_object
- res = @calling_object.send(m, *args)
+ res = @calling_object.send(m, *args, &block)
copy_instance_variables_from @calling_object
res
elsif @calling_object != @view_context and @view_context.respond_to?(m.to_s)
push_instance_variables_to @view_context
- res = @view_context.send(m, *args)
+ res = @view_context.send(m, *args, &block)
copy_instance_variables_from @view_context
res
else
View
BIN  spec/assets/yield_block_in_helper_test.pdf
Binary file not shown
View
8 spec/dummy/app/controllers/test_controller.rb
@@ -10,9 +10,13 @@ def dsl_render
render :action => "dsl_render"
end
- def complex
+ def instance_var_test
@x = 1
- render :action => "complex"
+ render :action => "instance_var_test"
+ end
+
+ def yield_block_in_helper_test
+ render :action => "yield_block_in_helper_test"
end
end
View
4 spec/dummy/app/helpers/application_helper.rb
@@ -11,4 +11,8 @@ def set_x_to_3_in_helper
@x = 3
end
+ def yield_this_block
+ yield
+ end
+
end
View
0  spec/dummy/app/views/test/complex.pdf.prawn → ...pp/views/test/instance_var_test.pdf.prawn
File renamed without changes
View
4 spec/dummy/app/views/test/yield_block_in_helper_test.pdf.prawn
@@ -0,0 +1,4 @@
+text "test 1"
+yield_this_block {
+ text "test 2"
+}
View
3  spec/dummy/config/routes.rb
@@ -1,7 +1,8 @@
Rails.application.routes.draw do
get "/default_render" => "test#default_render"
get "/dsl_render" => "test#dsl_render"
- get "/complex" => "test#complex"
+ get "/instance_var_test" => "test#instance_var_test"
+ get "/yield_block_in_helper_test" => "test#yield_block_in_helper_test"
root :to => "test#default_render"
end
View
18 spec/integrations/test_controller_spec.rb
@@ -11,6 +11,18 @@
body_binary = response.body.bytes.to_a
body_binary.should == asset_binary
end
+
+
+ it "shares values/changes of instance vars between view and helpers" do
+ expect { get "/instance_var_test.pdf" }.should_not raise_error
+ end
+
+ it "should render items in a block passed to a helper" do
+ get "/yield_block_in_helper_test.pdf"
+ asset_binary = File.open(TEST_ASSETS + "/yield_block_in_helper_test.pdf").read.bytes.to_a
+ body_binary = response.body.bytes.to_a
+ body_binary.should == asset_binary
+ end
end
@@ -24,9 +36,5 @@
body_binary.should == asset_binary
end
end
-
- it "uses changed instance values in helpers" do
- expect { get "/complex.pdf" }.should_not raise_error
- end
-
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.