2013-12-03 15:55:45 -05:00
|
|
|
# This file copies the test database into locations for the `Foo` and `Bar` namespace,
|
|
|
|
# then defines those namespaces, then establishes the sqlite3 connection for the namespaces
|
|
|
|
# to simulate an application with multiple database connections.
|
|
|
|
|
2015-12-13 01:14:59 -05:00
|
|
|
# Load database yaml to use
|
2014-03-14 16:11:10 -04:00
|
|
|
configs = YAML.load_file("#{Rails.root}/config/database.yml")
|
|
|
|
|
2015-12-13 01:14:59 -05:00
|
|
|
# If we are testing with sqlite make it quick
|
2013-12-03 15:55:45 -05:00
|
|
|
db_directory = "#{Rails.root}/db"
|
2015-12-13 01:14:59 -05:00
|
|
|
|
|
|
|
# Set up alternate databases
|
2014-03-14 16:11:10 -04:00
|
|
|
if ENV["DB"] == "sqlite"
|
2015-12-13 01:14:59 -05:00
|
|
|
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
|
|
|
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
module Foo
|
|
|
|
class Base < ActiveRecord::Base
|
|
|
|
self.abstract_class = true
|
|
|
|
end
|
|
|
|
|
|
|
|
class Version < Base
|
|
|
|
include PaperTrail::VersionConcern
|
|
|
|
end
|
|
|
|
|
|
|
|
class Document < Base
|
2016-03-05 17:07:32 -05:00
|
|
|
has_paper_trail class_name: "Foo::Version"
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
|
|
|
end
|
2014-03-14 16:11:10 -04:00
|
|
|
|
|
|
|
Foo::Base.configurations = configs
|
|
|
|
Foo::Base.establish_connection(:foo)
|
|
|
|
ActiveRecord::Base.establish_connection(:foo)
|
|
|
|
ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
|
2013-12-03 15:55:45 -05:00
|
|
|
|
|
|
|
module Bar
|
|
|
|
class Base < ActiveRecord::Base
|
|
|
|
self.abstract_class = true
|
|
|
|
end
|
|
|
|
|
|
|
|
class Version < Base
|
|
|
|
include PaperTrail::VersionConcern
|
|
|
|
end
|
|
|
|
|
|
|
|
class Document < Base
|
2016-03-05 17:07:32 -05:00
|
|
|
has_paper_trail class_name: "Bar::Version"
|
2013-12-03 15:55:45 -05:00
|
|
|
end
|
|
|
|
end
|
2014-03-14 16:11:10 -04:00
|
|
|
|
|
|
|
Bar::Base.configurations = configs
|
|
|
|
Bar::Base.establish_connection(:bar)
|
|
|
|
ActiveRecord::Base.establish_connection(:bar)
|
|
|
|
|
|
|
|
ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
|