mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge branch 'st0012-comparable'
This commit is contained in:
commit
49b314f688
2 changed files with 32 additions and 5 deletions
|
@ -1,6 +1,12 @@
|
||||||
require 'database_cleaner/null_strategy'
|
require 'database_cleaner/null_strategy'
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
class Base
|
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 = {})
|
def initialize(desired_orm = nil,opts = {})
|
||||||
if [:autodetect, nil, "autodetect"].include?(desired_orm)
|
if [:autodetect, nil, "autodetect"].include?(desired_orm)
|
||||||
autodetect
|
autodetect
|
||||||
|
@ -96,11 +102,6 @@ module DatabaseCleaner
|
||||||
!!@autodetected
|
!!@autodetected
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO make strategies directly comparable
|
|
||||||
def ==(other)
|
|
||||||
self.orm == other.orm && self.db == other.db
|
|
||||||
end
|
|
||||||
|
|
||||||
def autodetect_orm
|
def autodetect_orm
|
||||||
if defined? ::ActiveRecord
|
if defined? ::ActiveRecord
|
||||||
:active_record
|
:active_record
|
||||||
|
|
|
@ -213,6 +213,32 @@ module DatabaseCleaner
|
||||||
one.should eq two
|
one.should eq two
|
||||||
two.should eq one
|
two.should eq one
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "initialization" do
|
describe "initialization" do
|
||||||
|
|
Loading…
Reference in a new issue