Fix equality to not use extend.
This can totally kill performance.
This commit is contained in:
parent
dc430b3e82
commit
81e800961a
|
@ -9,6 +9,10 @@ module Draper
|
||||||
other.respond_to?(:decorated?) && other.decorated? &&
|
other.respond_to?(:decorated?) && other.decorated? &&
|
||||||
other.respond_to?(:source) && self == other.source
|
other.respond_to?(:source) && self == other.source
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.test(first, other)
|
||||||
|
first == other
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -163,7 +163,7 @@ module Draper
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def ==(other)
|
def ==(other)
|
||||||
source.extend(Draper::Decoratable::Equality) == other
|
Draper::Decoratable::Equality.test(source, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if `self.kind_of?(klass)` or `source.kind_of?(klass)`
|
# Checks if `self.kind_of?(klass)` or `source.kind_of?(klass)`
|
||||||
|
|
|
@ -380,15 +380,6 @@ module Draper
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#==" do
|
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
|
it "is true when source #== is true" do
|
||||||
source = Model.new
|
source = Model.new
|
||||||
decorator = Decorator.new(source)
|
decorator = Decorator.new(source)
|
||||||
|
|
Loading…
Reference in New Issue