Skip to content

Commit

Permalink
Add tests for case equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuraa committed May 13, 2011
1 parent 92346c9 commit edd1956
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
24 changes: 24 additions & 0 deletions test/functional/test_equality.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'test_helper'

class Person
include MongoMapper::Document

one :address
end

class Address
include MongoMapper::Document

belongs_to :person
end

class EqualityTest < Test::Unit::TestCase
context "Case equality" do
should "work with proxies" do
person = Person.create
address = Address.create(:person => person)
Person.should === address.person
Address.should === person.address
end
end
end
7 changes: 1 addition & 6 deletions test/unit/associations/test_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def setup
@blank_proxy = FakeBlankProxy.new(@owner, @association)
end

should 'return true for === target' do
@proxy = FakeProxy.new(@owner, @association)
@proxy.should === Array
end

should "set target to nil when reset is called" do
@proxy.reset
@proxy.target.should be_nil
Expand Down Expand Up @@ -102,4 +97,4 @@ def setup
lambda { @proxy.send(:gsub) }.should raise_error
end
end
end
end
37 changes: 37 additions & 0 deletions test/unit/test_equality.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'test_helper'

class Equality
include MongoMapper::Plugins::Equality
end

class Equality2 < Equality; end

class Faker
def initialize(faked)
@faked = faked
end

def is_a?(klass)
@faked.is_a? klass
end
end

class EqualityTest < Test::Unit::TestCase
context "Case equality" do
should "work with regular instance" do
Equality.should === Equality.new
end

should "work with instances of subclasses" do
Equality.should === Equality2.new
end

should "work with a faker class" do
Equality.should === Faker.new(Equality.new)
end

should "not work with other instances" do
Equality.should_not === 1
end
end
end

0 comments on commit edd1956

Please sign in to comment.