From 235dfd593342390d4af8d36827689dc44b33e6d2 Mon Sep 17 00:00:00 2001 From: Jeff Casimir Date: Fri, 1 Jul 2011 15:50:57 -0400 Subject: [PATCH] Fixed the wrapping of subject methods that use blocks --- lib/draper/base.rb | 4 ++-- spec/base_spec.rb | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/draper/base.rb b/lib/draper/base.rb index 24f90ab..3e76fab 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -37,8 +37,8 @@ module Draper def build_methods select_methods.each do |method| (class << self; self; end).class_eval do - define_method method do |*args| - source.send method, *args + define_method method do |*args, &block| + source.send method, *args, &block end end end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index b22d4e1..febda50 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -3,12 +3,26 @@ require 'draper' describe Draper::Base do subject{ Draper::Base.new(source) } - let(:source){ "Sample String" } + let(:source){ "Sample String" } it "should return the wrapped object when asked for source" do subject.source.should == source end + it "should wrap source methods so they still accept blocks" do + subject.gsub("Sample"){|match| "Super"}.should == "Super String" + end + + it "should return a collection of wrapped objects when given a collection of source objects" do + pending("need to fix the proxying of blocks") + sources = ["one", "two", "three"] + output = Draper::Base.new(sources) + output.should respond_to(:each) + output.size.should == sources.size + output.each{ |decorated| decorated.should be_instance_of(Draper::Base) } + debugger + end + it "echos the methods of the wrapped class" do source.methods.each do |method| subject.should respond_to(method)