Automatically create a named accessor method for the wrapped model

This commit is contained in:
Jeff Casimir 2011-10-19 23:26:00 -04:00
parent 19f1fc7b69
commit 5cb6f7210a
2 changed files with 6 additions and 0 deletions

View File

@ -51,6 +51,7 @@ module Draper
def self.decorates(input)
self.model_class = input.to_s.camelize.constantize
model_class.send :include, Draper::ModelSupport
define_method(input){ @model }
end
# Specifies a black list of methods which may *not* be proxied to

View File

@ -40,6 +40,11 @@ describe Draper::Base do
BusinessDecorator.model_class.should == Business
end.should_not raise_error
end
it "creates a named accessor for the wrapped model" do
pd = ProductDecorator.new(source)
pd.send(:product).should == source
end
end
context(".model / .to_model") do