diff --git a/lib/database_cleaner/sequel/base.rb b/lib/database_cleaner/sequel/base.rb index 8cd5e30..77d03f1 100644 --- a/lib/database_cleaner/sequel/base.rb +++ b/lib/database_cleaner/sequel/base.rb @@ -15,7 +15,7 @@ module DatabaseCleaner def db return @db if @db && @db != :default raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1 - ::Sequel::DATABASES.first + ::Sequel::DATABASES.first || :default end end end diff --git a/spec/database_cleaner/active_record/truncation_spec.rb b/spec/database_cleaner/active_record/truncation_spec.rb index a529c7e..71c1587 100644 --- a/spec/database_cleaner/active_record/truncation_spec.rb +++ b/spec/database_cleaner/active_record/truncation_spec.rb @@ -31,19 +31,15 @@ module DatabaseCleaner it "should truncate all tables except for schema_migrations" do connection.stub!(:tables).and_return(%w[schema_migrations widgets dogs]) - - connection.should_receive(:truncate_table).with('widgets') - connection.should_receive(:truncate_table).with('dogs') - connection.should_not_receive(:truncate_table).with('schema_migrations') - + + connection.should_receive(:truncate_tables).with(['widgets', 'dogs']) Truncation.new.clean end it "should only truncate the tables specified in the :only option when provided" do connection.stub!(:tables).and_return(%w[schema_migrations widgets dogs]) - connection.should_receive(:truncate_table).with('widgets') - connection.should_not_receive(:truncate_table).with('dogs') + connection.should_receive(:truncate_tables).with(['widgets']) Truncation.new(:only => ['widgets']).clean end @@ -51,8 +47,7 @@ module DatabaseCleaner it "should not truncate the tables specified in the :except option" do connection.stub!(:tables).and_return(%w[schema_migrations widgets dogs]) - connection.should_receive(:truncate_table).with('dogs') - connection.should_not_receive(:truncate_table).with('widgets') + connection.should_receive(:truncate_tables).with(['dogs']) Truncation.new(:except => ['widgets']).clean end @@ -71,8 +66,7 @@ module DatabaseCleaner connection.stub!(:tables).and_return(%w[widgets dogs]) connection.stub!(:views).and_return(["widgets"]) - connection.should_receive(:truncate_table).with('dogs') - connection.should_not_receive(:truncate_table).with('widgets') + connection.should_receive(:truncate_tables).with(['dogs']) Truncation.new.clean end diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 3906723..58dd2a7 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -17,6 +17,7 @@ module DatabaseCleaner Temp_MM = ::MongoMapper if defined?(::MongoMapper) and not defined?(Temp_MM) Temp_MO = ::Mongoid if defined?(::Mongoid) and not defined?(Temp_MO) Temp_CP = ::CouchPotato if defined?(::CouchPotato) and not defined?(Temp_CP) + Temp_SQ = ::Sequel if defined?(::Sequel) and not defined?(Temp_SQ) end #Remove all ORM mocks and restore from cache @@ -26,6 +27,7 @@ module DatabaseCleaner Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper) Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid) Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato) + Object.send(:remove_const, 'Sequel') if defined?(::Sequel) # Restore ORMs @@ -43,8 +45,9 @@ module DatabaseCleaner Object.send(:remove_const, 'MongoMapper') if defined?(::MongoMapper) Object.send(:remove_const, 'Mongoid') if defined?(::Mongoid) Object.send(:remove_const, 'CouchPotato') if defined?(::CouchPotato) + Object.send(:remove_const, 'Sequel') if defined?(::Sequel) end - + let(:cleaner) { DatabaseCleaner::Base.new :autodetect } it "should raise an error when no ORM is detected" do @@ -57,6 +60,7 @@ module DatabaseCleaner Object.const_set('MongoMapper', 'Mapping mock mongos') Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') + Object.const_set('Sequel', 'Sequel mock') cleaner.orm.should == :active_record cleaner.should be_auto_detected @@ -67,6 +71,7 @@ module DatabaseCleaner Object.const_set('MongoMapper', 'Mapping mock mongos') Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') + Object.const_set('Sequel', 'Sequel mock') cleaner.orm.should == :data_mapper cleaner.should be_auto_detected @@ -76,6 +81,7 @@ module DatabaseCleaner Object.const_set('MongoMapper', 'Mapping mock mongos') Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') + Object.const_set('Sequel', 'Sequel mock') cleaner.orm.should == :mongo_mapper cleaner.should be_auto_detected @@ -84,17 +90,26 @@ module DatabaseCleaner it "should detect Mongoid fourth" do Object.const_set('Mongoid', 'Mongoid mock') Object.const_set('CouchPotato', 'Couching mock potatos') + Object.const_set('Sequel', 'Sequel mock') cleaner.orm.should == :mongoid cleaner.should be_auto_detected end - it "should detect CouchPotato last" do + it "should detect CouchPotato fifth" do Object.const_set('CouchPotato', 'Couching mock potatos') + Object.const_set('Sequel', 'Sequel mock') cleaner.orm.should == :couch_potato cleaner.should be_auto_detected end + + it "should detect Sequel last" do + Object.const_set('Sequel', 'Sequel mock') + + cleaner.orm.should == :sequel + cleaner.should be_auto_detected + end end describe "orm_module" do