prevent double decoration, closes #173

This commit is contained in:
Vasiliy Ermolovich 2012-04-23 14:15:13 +03:00
parent eaecb62b36
commit c945cce6f3
2 changed files with 6 additions and 1 deletions

View File

@ -26,7 +26,7 @@ module Draper
def initialize(input, options = {})
input.inspect # forces evaluation of a lazy query from AR
self.class.model_class = input.class if model_class.nil?
@model = input
@model = input.kind_of?(Draper::Base) ? input.model : input
self.options = options
end

View File

@ -44,6 +44,11 @@ describe Draper::Base do
ProductDecorator.new(source).model_class.should == Product
end
it "returns decorator if it's decorated model already" do
product_decorator = ProductDecorator.new(source)
ProductDecorator.new(product_decorator).model.should be_instance_of Product
end
it "should handle plural-like words properly'" do
class Business; end
expect do