aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases/base/equality_test.rb
diff options
context:
space:
mode:
authortaryn <teast@globalpersonals.co.uk>2009-08-19 12:05:36 +0100
committerJoshua Peek <josh@joshpeek.com>2009-08-19 09:03:57 -0500
commit36bf5873474c7f3a8c69e6e037ad53aa6d66491a (patch)
tree56c8ba2eb7d882f59b1e0eda28673d1f17d17a6d /activeresource/test/cases/base/equality_test.rb
parentc2f90d6530dfd0ed68df9f4c429d0f498235e1d4 (diff)
downloadrails-36bf5873474c7f3a8c69e6e037ad53aa6d66491a.tar.gz
rails-36bf5873474c7f3a8c69e6e037ad53aa6d66491a.tar.bz2
rails-36bf5873474c7f3a8c69e6e037ad53aa6d66491a.zip
Moved all test cases into a new test/cases directory to match Active Record test directory structure.
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activeresource/test/cases/base/equality_test.rb')
-rw-r--r--activeresource/test/cases/base/equality_test.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/activeresource/test/cases/base/equality_test.rb b/activeresource/test/cases/base/equality_test.rb
new file mode 100644
index 0000000000..84f1a7b998
--- /dev/null
+++ b/activeresource/test/cases/base/equality_test.rb
@@ -0,0 +1,52 @@
+require '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
+
+ 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