aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/base
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-12-22 21:42:52 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-12-22 21:42:52 +0000
commitc172154054f2f1908820459bb63e8e8645136ea7 (patch)
tree03d4caf01cd4c822f56ff9e54b5dddedddcc5bde /activeresource/test/base
parent68d2926ab09d49086eb4101c53d8ae604bd4b334 (diff)
downloadrails-c172154054f2f1908820459bb63e8e8645136ea7.tar.gz
rails-c172154054f2f1908820459bb63e8e8645136ea7.tar.bz2
rails-c172154054f2f1908820459bb63e8e8645136ea7.zip
Base#==, eql?, and hash methods. == returns true if its argument is identical to self or if it's an instance of the same class, is not new?, and has the same id. eql? is an alias for ==. hash delegates to id.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5773 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test/base')
-rw-r--r--activeresource/test/base/equality_test.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/activeresource/test/base/equality_test.rb b/activeresource/test/base/equality_test.rb
new file mode 100644
index 0000000000..4a3f75f998
--- /dev/null
+++ b/activeresource/test/base/equality_test.rb
@@ -0,0 +1,43 @@
+require "#{File.dirname(__FILE__)}/../abstract_unit"
+require "fixtures/person"
+require "fixtures/street_address"
+
+class BaseEqualityTest < Test::Unit::TestCase
+ def setup
+ @new = Person.new
+ @one = Person.new(:id => 1)
+ @two = Person.new(:id => 2)
+ @street = StreetAddress.new(:id => 2)
+ end
+
+ def test_should_equal_self
+ assert @new == @new, '@new == @new'
+ assert @one == @one, '@one == @one'
+ end
+
+ def test_shouldnt_equal_new_resource
+ assert @new != @one, '@new != @one'
+ assert @one != @new, '@one != @new'
+ end
+
+ def test_shouldnt_equal_different_class
+ assert @two != @street, 'person != street_address with same id'
+ assert @street != @two, 'street_address != person with same id'
+ end
+
+ def test_eql_should_alias_equals_operator
+ assert_equal @new == @new, @new.eql?(@new)
+ assert_equal @new == @one, @new.eql?(@one)
+
+ assert_equal @one == @one, @one.eql?(@one)
+ assert_equal @one == @new, @one.eql?(@new)
+
+ assert_equal @one == @street, @one.eql?(@street)
+ end
+
+ def test_hash_should_be_id_hash
+ [@new, @one, @two, @street].each do |resource|
+ assert_equal resource.id.hash, resource.hash
+ end
+ end
+end