Skip to content

Commit

Permalink
Fixed the wrapping of subject methods that use blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jcasimir committed Jul 1, 2011
1 parent b4f632b commit 235dfd5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/draper/base.rb
Expand Up @@ -37,8 +37,8 @@ def select_methods
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
Expand Down
16 changes: 15 additions & 1 deletion spec/base_spec.rb
Expand Up @@ -3,12 +3,26 @@

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)
Expand Down

0 comments on commit 235dfd5

Please sign in to comment.