Don't truncate the schema_migrations table

This commit is contained in:
Jon Allured 2015-01-09 16:09:27 -06:00
parent 8d7f72ffc9
commit 04c263e48c
5 changed files with 45 additions and 0 deletions

1
.ruby-gemset Normal file
View file

@ -0,0 +1 @@
database_cleaner

View file

@ -6,6 +6,15 @@ require 'database_cleaner/active_record/truncation/shared_fast_truncation'
module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
describe "schema_migrations table" do
it "is not truncated" do
active_record_gp_migrate
DatabaseCleaner::ActiveRecord::Truncation.new.clean
result = active_record_pg_connection.execute("select count(*) from schema_migrations;")
result.values.first.should eq ["2"]
end
end
describe do describe do
before(:all) { active_record_pg_setup } before(:all) { active_record_pg_setup }

View file

@ -0,0 +1,14 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
end
end
def self.down
drop_table :users
end
end
class ::User < ActiveRecord::Base
end

View file

@ -0,0 +1,14 @@
class CreateAgents < ActiveRecord::Migration
def self.up
create_table :agents do |t|
t.string :name
end
end
def self.down
drop_table :agents
end
end
class ::Agent < ActiveRecord::Base
end

View file

@ -31,6 +31,13 @@ module PostgreSQLHelper
load_schema load_schema
end end
def active_record_gp_migrate
`dropdb #{config['database']}`
create_db
establish_connection
ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
end
def active_record_pg_connection def active_record_pg_connection
ActiveRecord::Base.connection ActiveRecord::Base.connection
end end