From 6079ec1f77daf364a2b25cf651e9b3c9e1b95a16 Mon Sep 17 00:00:00 2001 From: Rasik Pandey Date: Wed, 28 Jan 2009 19:39:06 +0000 Subject: [PATCH] ActiveResource#eqls? and == should not take into account object identity and prefix options should be considered. [#1098 state:resolved] Signed-off-by: Pratik Naik --- activeresource/lib/active_resource/base.rb | 4 ++-- activeresource/test/base/equality_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 4192fab525..54dde43087 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -746,8 +746,8 @@ def to_param # # => true # def ==(other) - other.equal?(self) || (other.instance_of?(self.class) && !other.new? && other.id == id) - end + other.equal?(self) || (other.instance_of?(self.class) && other.id == id && other.prefix_options == prefix_options) + end # Tests for equality (delegates to ==). def eql?(other) diff --git a/activeresource/test/base/equality_test.rb b/activeresource/test/base/equality_test.rb index 1fb8938e95..84f1a7b998 100644 --- a/activeresource/test/base/equality_test.rb +++ b/activeresource/test/base/equality_test.rb @@ -40,4 +40,13 @@ def test_hash_should_be_id_hash assert_equal resource.id.hash, resource.hash end end + + def test_with_prefix_options + assert_equal @one == @one, @one.eql?(@one) + assert_equal @one == @one.dup, @one.eql?(@one.dup) + new_one = @one.dup + new_one.prefix_options = {:foo => 'bar'} + assert_not_equal @one, new_one + end + end -- GitLab