Fix equality to not use extend.

This can totally kill performance.
This commit is contained in:
Steve Klabnik 2013-03-28 10:39:35 -07:00
parent dc430b3e82
commit 81e800961a
3 changed files with 5 additions and 10 deletions

View File

@ -9,6 +9,10 @@ module Draper
other.respond_to?(:decorated?) && other.decorated? &&
other.respond_to?(:source) && self == other.source
end
def self.test(first, other)
first == other
end
end
end
end

View File

@ -163,7 +163,7 @@ module Draper
#
# @return [Boolean]
def ==(other)
source.extend(Draper::Decoratable::Equality) == other
Draper::Decoratable::Equality.test(source, other)
end
# Checks if `self.kind_of?(klass)` or `source.kind_of?(klass)`

View File

@ -380,15 +380,6 @@ module Draper
end
describe "#==" do
it "ensures the source has a decoration-aware #==" do
source = Object.new
decorator = Decorator.new(source)
expect(source).not_to be_a_kind_of Draper::Decoratable::Equality
decorator == :something
expect(source).to be_a_kind_of Draper::Decoratable::Equality
end
it "is true when source #== is true" do
source = Model.new
decorator = Decorator.new(source)