mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
raise ArgumentError when DC[nil] is invoked or DC.orm = nil.
This commit is contained in:
parent
b555ef6e87
commit
cdaec35574
4 changed files with 12 additions and 13 deletions
|
@ -11,8 +11,8 @@ module DatabaseCleaner
|
||||||
[orm, db] <=> [other.orm, other.db]
|
[orm, db] <=> [other.orm, other.db]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(desired_orm = nil, opts = {})
|
def initialize(orm = :null, opts = {})
|
||||||
self.orm = desired_orm
|
self.orm = orm
|
||||||
self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
|
self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
|
||||||
Safeguard.new.run
|
Safeguard.new.run
|
||||||
end
|
end
|
||||||
|
@ -44,8 +44,9 @@ module DatabaseCleaner
|
||||||
|
|
||||||
attr_reader :orm
|
attr_reader :orm
|
||||||
|
|
||||||
def orm=(desired_orm)
|
def orm= orm
|
||||||
@orm = desired_orm && desired_orm.to_sym
|
raise ArgumentError if orm.nil?
|
||||||
|
@orm = orm.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
|
@ -4,13 +4,12 @@ require 'forwardable'
|
||||||
|
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
|
|
||||||
class NoORMDetected < StandardError; end
|
|
||||||
class UnknownStrategySpecified < ArgumentError; end
|
class UnknownStrategySpecified < ArgumentError; end
|
||||||
|
|
||||||
class Cleaners < Hash
|
class Cleaners < Hash
|
||||||
# FIXME this method conflates creation with lookup... both a command and a query. yuck.
|
# FIXME this method conflates creation with lookup... both a command and a query. yuck.
|
||||||
def [](orm, opts = {})
|
def [](orm, opts = {})
|
||||||
raise NoORMDetected unless orm
|
raise ArgumentError if orm.nil?
|
||||||
fetch([orm, opts]) { add_cleaner(orm, opts) }
|
fetch([orm, opts]) { add_cleaner(orm, opts) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,14 @@ module DatabaseCleaner
|
||||||
expect(cleaner.orm).to eq :mongoid
|
expect(cleaner.orm).to eq :mongoid
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should default to nil" do
|
it "should default to :null" do
|
||||||
cleaner = Base.new
|
cleaner = Base.new
|
||||||
expect(cleaner.orm).to be_nil
|
expect(cleaner.orm).to eq :null
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can handle being set to nil" do
|
it "raises ArgumentError when explicitly set to nil" do
|
||||||
cleaner = Base.new
|
cleaner = Base.new
|
||||||
cleaner.orm = nil
|
expect { cleaner.orm = nil }.to raise_error(ArgumentError)
|
||||||
expect(cleaner.orm).to be_nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,8 @@ RSpec.describe DatabaseCleaner::Configuration do
|
||||||
subject(:config) { described_class.new }
|
subject(:config) { described_class.new }
|
||||||
|
|
||||||
context "orm specification" do
|
context "orm specification" do
|
||||||
it "should not accept unrecognised orms" do
|
it "should not accept nil orms" do
|
||||||
expect { config[nil] }.to raise_error(DatabaseCleaner::NoORMDetected)
|
expect { config[nil] }.to raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should accept :active_record" do
|
it "should accept :active_record" do
|
||||||
|
|
Loading…
Reference in a new issue