Fixed the wrapping of subject methods that use blocks
This commit is contained in:
parent
b4f632b4a6
commit
235dfd5933
|
@ -37,8 +37,8 @@ module Draper
|
||||||
def build_methods
|
def build_methods
|
||||||
select_methods.each do |method|
|
select_methods.each do |method|
|
||||||
(class << self; self; end).class_eval do
|
(class << self; self; end).class_eval do
|
||||||
define_method method do |*args|
|
define_method method do |*args, &block|
|
||||||
source.send method, *args
|
source.send method, *args, &block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,12 +3,26 @@ require 'draper'
|
||||||
|
|
||||||
describe Draper::Base do
|
describe Draper::Base do
|
||||||
subject{ Draper::Base.new(source) }
|
subject{ Draper::Base.new(source) }
|
||||||
let(:source){ "Sample String" }
|
let(:source){ "Sample String" }
|
||||||
|
|
||||||
it "should return the wrapped object when asked for source" do
|
it "should return the wrapped object when asked for source" do
|
||||||
subject.source.should == source
|
subject.source.should == source
|
||||||
end
|
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
|
it "echos the methods of the wrapped class" do
|
||||||
source.methods.each do |method|
|
source.methods.each do |method|
|
||||||
subject.should respond_to(method)
|
subject.should respond_to(method)
|
||||||
|
|
Loading…
Reference in New Issue