Sha256: 2016f28fb5a587ec8c2ede96945b405733c42c79e799cc25223c62b6daca98ab

Contents?: true

Size: 1.15 KB

Versions: 75

Compression:

Stored size: 1.15 KB

Contents

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

Version data entries

75 entries across 75 versions & 5 rubygems

Version Path
backlog-0.3.5 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.3.7 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.3.8 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.3.9 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.4.0 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.0 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.1 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.2 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.10 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.3 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.4 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.5 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.6 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.7 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.8 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.5.9 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.6.2 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.6.1 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.6.0 vendor/rails/activeresource/test/base/equality_test.rb
backlog-0.6.3 vendor/rails/activeresource/test/base/equality_test.rb