make decorators be kind_of their models class, so that cancan rules

apply to them
This commit is contained in:
Alexander Presber 2011-11-01 20:57:46 +01:00
parent ad94f54369
commit ac1f308398
2 changed files with 11 additions and 0 deletions

View File

@ -146,6 +146,11 @@ module Draper
@model == (other.respond_to?(:model) ? other.model : other)
end
def kind_of?(klass)
return true if klass == model.class
super
end
def respond_to?(method, include_private = false)
super || (allow?(method) && model.respond_to?(method))
end

View File

@ -362,4 +362,10 @@ describe Draper::Base do
decorator.sample_truncate.should == "Once..."
end
end
describe "decorator in cancan rules" do
it "should answer yes to kind_of? source class" do
subject.kind_of?(source.class).should == true
end
end
end