Overwrite #kind_of? and #is_a? in Draper::Base

This commit is contained in:
Tobias Maier 2011-12-07 17:08:23 +01:00
parent f42f670812
commit 7ac940f226
2 changed files with 25 additions and 0 deletions

View File

@ -175,6 +175,11 @@ module Draper
end
end
def kind_of?(klass)
model.kind_of?(klass) || super(klass)
end
alias :is_a? :kind_of?
def self.method_missing(method, *args, &block)
model_class.send(method, *args, &block)
end

View File

@ -445,4 +445,24 @@ describe Draper::Base do
end
end
end
describe "#kind_of?" do
context "pretends to be of kind of model class" do
it "#kind_of? Decorator" do
subject.should be_kind_of Decorator
end
it "#is_a? Decorator" do
subject.is_a?(Decorator).should be_true
end
it "#kind_of? Product" do
subject.should be_kind_of Product
end
it "#is_a? Product" do
subject.is_a?(Product).should be_true
end
end
end
end