diff --git a/spec/database_cleaner/active_record/deletion/mysql2_spec.rb b/spec/database_cleaner/active_record/deletion/mysql2_spec.rb new file mode 100644 index 0000000..c76184e --- /dev/null +++ b/spec/database_cleaner/active_record/deletion/mysql2_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'active_record' +require 'support/active_record/mysql2_setup' +require 'database_cleaner/active_record/deletion' + +module ActiveRecord + module AbstractMysqlAdapter + describe do + before(:all) { active_record_mysql2_setup } + + let(:connection) { active_record_mysql2_connection } + + subject { DatabaseCleaner::ActiveRecord::Deletion.new } + + describe "#delete_table" do + it "should delete the table" do + 2.times { User.create } + + allow(subject).to receive(:tables_with_new_rows).and_return(["users"]) + + subject.clean + + User.count.should eq 0 + end + end + end + end +end diff --git a/spec/database_cleaner/active_record/deletion/mysql_spec.rb b/spec/database_cleaner/active_record/deletion/mysql_spec.rb new file mode 100644 index 0000000..0d71e2c --- /dev/null +++ b/spec/database_cleaner/active_record/deletion/mysql_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' +require 'active_record' +require 'support/active_record/mysql_setup' +require 'database_cleaner/active_record/deletion' + +module ActiveRecord + module AbstractMysqlAdapter + describe do + before(:all) { active_record_mysql_setup } + + let(:connection) { active_record_mysql_connection } + + describe "#delete_table" do + it "should delete the table" do + 2.times { User.create } + DatabaseCleaner::ActiveRecord::Deletion.new.clean + + User.count.should eq 0 + end + end + end + end +end diff --git a/spec/database_cleaner/active_record/deletion/postgresql_spec.rb b/spec/database_cleaner/active_record/deletion/postgresql_spec.rb new file mode 100644 index 0000000..c22c8df --- /dev/null +++ b/spec/database_cleaner/active_record/deletion/postgresql_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' +require 'active_record' +require 'support/active_record/postgresql_setup' +require 'database_cleaner/active_record/deletion' + +module ActiveRecord + module ConnectionAdapters + describe "schema_migrations table" do + it "is not deleted" do + active_record_pg_migrate + DatabaseCleaner::ActiveRecord::Deletion.new.clean + result = active_record_pg_connection.execute("select count(*) from schema_migrations;") + result.values.first.should eq ["2"] + end + end + + describe do + before(:all) { active_record_pg_setup } + + let(:connection) do + active_record_pg_connection + end + + before(:each) do + connection.tables.each do |table| + connection.delete_table table + end + end + + describe "#delete_table" do + it "deletes the table" do + 2.times { User.create } + + connection.delete_table('users') + User.count.should eq 0 + end + + it "deletes the table without id sequence" do + 2.times { Agent.create } + + connection.delete_table('agents') + Agent.count.should eq 0 + end + end + + describe ":except option cleanup" do + it "should not delete the tables specified in the :except option" do + 2.times { User.create } + + ::DatabaseCleaner::ActiveRecord::Deletion.new(:except => ['users']).clean + expect( User.count ).to eq 2 + end + end + + describe '#database_cleaner_table_cache' do + it 'should default to the list of tables with their schema' do + connection.database_cleaner_table_cache.first.should match(/^public\./) + end + end + end + end +end diff --git a/spec/database_cleaner/active_record/deletion/sqlite3_spec.rb b/spec/database_cleaner/active_record/deletion/sqlite3_spec.rb new file mode 100644 index 0000000..af9ef09 --- /dev/null +++ b/spec/database_cleaner/active_record/deletion/sqlite3_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' +require 'active_record' +require 'support/active_record/sqlite3_setup' +require 'database_cleaner/active_record/deletion' + +module ActiveRecord + module ConnectionAdapters + describe do + before(:all) { active_record_sqlite3_setup } + + let(:connection) do + active_record_sqlite3_connection + end + + before(:each) do + connection.tables.each do |table| + connection.delete_table table + end + end + + describe "#delete_table" do + it "deletes the table" do + 2.times { User.create } + + connection.delete_table('users') + User.count.should eq 0 + end + end + end + end +end