Fixed the wrapping of subject methods that use blocks

This commit is contained in:
Jeff Casimir 2011-07-01 15:50:57 -04:00
parent b4f632b4a6
commit 235dfd5933
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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)