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]
|
||||
end
|
||||
|
||||
def initialize(desired_orm = nil, opts = {})
|
||||
self.orm = desired_orm
|
||||
def initialize(orm = :null, opts = {})
|
||||
self.orm = orm
|
||||
self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
|
||||
Safeguard.new.run
|
||||
end
|
||||
|
@ -44,8 +44,9 @@ module DatabaseCleaner
|
|||
|
||||
attr_reader :orm
|
||||
|
||||
def orm=(desired_orm)
|
||||
@orm = desired_orm && desired_orm.to_sym
|
||||
def orm= orm
|
||||
raise ArgumentError if orm.nil?
|
||||
@orm = orm.to_sym
|
||||
end
|
||||
|
||||
extend Forwardable
|
||||
|
|
|
@ -4,13 +4,12 @@ require 'forwardable'
|
|||
|
||||
module DatabaseCleaner
|
||||
|
||||
class NoORMDetected < StandardError; end
|
||||
class UnknownStrategySpecified < ArgumentError; end
|
||||
|
||||
class Cleaners < Hash
|
||||
# FIXME this method conflates creation with lookup... both a command and a query. yuck.
|
||||
def [](orm, opts = {})
|
||||
raise NoORMDetected unless orm
|
||||
raise ArgumentError if orm.nil?
|
||||
fetch([orm, opts]) { add_cleaner(orm, opts) }
|
||||
end
|
||||
|
||||
|
|
|
@ -46,15 +46,14 @@ module DatabaseCleaner
|
|||
expect(cleaner.orm).to eq :mongoid
|
||||
end
|
||||
|
||||
it "should default to nil" do
|
||||
it "should default to :null" do
|
||||
cleaner = Base.new
|
||||
expect(cleaner.orm).to be_nil
|
||||
expect(cleaner.orm).to eq :null
|
||||
end
|
||||
|
||||
it "can handle being set to nil" do
|
||||
it "raises ArgumentError when explicitly set to nil" do
|
||||
cleaner = Base.new
|
||||
cleaner.orm = nil
|
||||
expect(cleaner.orm).to be_nil
|
||||
expect { cleaner.orm = nil }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,8 @@ RSpec.describe DatabaseCleaner::Configuration do
|
|||
subject(:config) { described_class.new }
|
||||
|
||||
context "orm specification" do
|
||||
it "should not accept unrecognised orms" do
|
||||
expect { config[nil] }.to raise_error(DatabaseCleaner::NoORMDetected)
|
||||
it "should not accept nil orms" do
|
||||
expect { config[nil] }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
it "should accept :active_record" do
|
||||
|
|
Loading…
Reference in a new issue