-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest_helper.rb
44 lines (36 loc) · 1.35 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
ENV['RAILS_ENV'] = 'test'
require 'active_record'
require 'minitest/autorun'
require 'active_record_replica'
require 'awesome_print'
require 'logger'
require 'erb'
l = Logger.new('test.log')
l.level = ::Logger::DEBUG
ActiveRecord::Base.logger = l
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read('test/database.yml')).result)
# Define Schema in second database (replica)
# Note: This is not be required when the primary database is being replicated to the replica db
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']['replica'])
# Create table users in database active_record_replica_test
ActiveRecord::Schema.define :version => 0 do
create_table :users, :force => true do |t|
t.string :name
t.string :address
end
end
# Define Schema in primary database
ActiveRecord::Base.establish_connection(:test)
# Create table users in database active_record_replica_test
ActiveRecord::Schema.define :version => 0 do
create_table :users, :force => true do |t|
t.string :name
t.string :address
end
end
# AR Model
class User < ActiveRecord::Base
end
# Install ActiveRecord replica. Done automatically by railtie in a Rails environment
# Also tell it to use the test environment since Rails.env is not available
ActiveRecordReplica.install!(nil, 'test')