Merge branch 'comparable' of https://github.com/st0012/database_cleaner into st0012-comparable

This commit is contained in:
Ernesto Tagwerker 2015-12-31 10:30:08 -03:00
commit 370d22b70d
2 changed files with 32 additions and 5 deletions

View file

@ -1,6 +1,12 @@
require 'database_cleaner/null_strategy'
module DatabaseCleaner
class Base
include Comparable
def <=>(other)
(self.orm <=> other.orm) == 0 ? self.db <=> other.db : self.orm <=> other.orm
end
def initialize(desired_orm = nil,opts = {})
if [:autodetect, nil, "autodetect"].include?(desired_orm)
autodetect
@ -96,11 +102,6 @@ module DatabaseCleaner
!!@autodetected
end
#TODO make strategies directly comparable
def ==(other)
self.orm == other.orm && self.db == other.db
end
def autodetect_orm
if defined? ::ActiveRecord
:active_record

View file

@ -213,6 +213,32 @@ module DatabaseCleaner
one.should eq two
two.should eq one
end
it "should not be equal if orm are not the same" do
strategy = mock("strategy")
strategy.stub!(:to_ary => [strategy])
one = DatabaseCleaner::Base.new(:mongo_id,:connection => :default)
one.strategy = strategy
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
two.strategy = strategy
one.should_not eq two
two.should_not eq one
end
it "should not be equal if connection are not the same" do
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
one.strategy = :truncation
two = DatabaseCleaner::Base.new(:active_record,:connection => :other)
two.strategy = :truncation
one.should_not eq two
two.should_not eq one
end
end
describe "initialization" do