connection_manager 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/Gemfile +0 -1
- data/LICENSE.txt +1 -1
- data/README.md +115 -55
- data/Rakefile +2 -0
- data/connection_manager.gemspec +9 -3
- data/lib/connection_manager/connection_builder.rb +81 -0
- data/lib/connection_manager/connection_manager_railtie.rb +4 -3
- data/lib/connection_manager/helpers/abstract_adapter_helper.rb +40 -0
- data/lib/connection_manager/helpers/connection_helpers.rb +105 -0
- data/lib/connection_manager/{cross_schema_patch.rb → patches/cross_schema_patch.rb} +2 -3
- data/lib/connection_manager/replication.rb +165 -0
- data/lib/connection_manager/shards.rb +25 -0
- data/lib/connection_manager/using.rb +95 -0
- data/lib/connection_manager/version.rb +1 -1
- data/lib/connection_manager.rb +19 -8
- data/spec/factories.rb +7 -11
- data/spec/helpers/database_spec_helper.rb +52 -41
- data/spec/helpers/models_spec_helper.rb +23 -0
- data/spec/jdbcmysql_database.yml +55 -0
- data/spec/lib/connection_builder_spec.rb +29 -0
- data/spec/lib/connection_helpers_spec.rb +74 -0
- data/spec/lib/replication_spec.rb +134 -0
- data/spec/lib/shards_spec.rb +40 -0
- data/spec/lib/using_spec.rb +77 -0
- data/spec/mysql2_database.yml +28 -2
- data/spec/spec_helper.rb +20 -6
- metadata +42 -39
- data/Gemfile.lock +0 -56
- data/lib/connection_manager/associations.rb +0 -28
- data/lib/connection_manager/connections.rb +0 -124
- data/lib/connection_manager/method_recorder.rb +0 -57
- data/lib/connection_manager/secondary_connection_builder.rb +0 -180
- data/spec/integration/secondary_connection_builder_spec.rb +0 -115
- data/spec/lib/associations_spec.rb +0 -30
- data/spec/lib/connections_spec.rb +0 -92
- data/spec/lib/method_recorder_spec.rb +0 -43
- data/spec/lib/secondary_connection_builder_spec.rb +0 -77
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ConnectionManager::Replication do
|
3
|
+
|
4
|
+
describe '#database_name' do
|
5
|
+
it "should return the name of the database the model is using" do
|
6
|
+
Fruit.database_name.should eql('cm_test')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#replicated' do
|
11
|
+
it "should raise an exception if no connections are empty, and connection.replication_keys are blank" do
|
12
|
+
Fruit.connection.stubs(:replication_keys).returns([])
|
13
|
+
lambda { Fruit.replicated }.should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not raise an exception if no connections are empty, but connection.replication_keys are not blank" do
|
17
|
+
Fruit.connection.stubs(:replication_keys).returns([:slave_1_cm_test])
|
18
|
+
lambda { Fruit.replicated }.should_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
context "the methods created from #replicated" do
|
22
|
+
it "should create a method with the name given for the :name option" do
|
23
|
+
Fruit.replicated(:name => 'foozle')
|
24
|
+
Fruit.respond_to?(:foozle).should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a method in ActiveRecord::QueryMethods with the name given for the :name option" do
|
28
|
+
f = FactoryGirl.create(:fruit)
|
29
|
+
Fruit.replicated(:name => 'fizzle')
|
30
|
+
ActiveRecord::QueryMethods.instance_methods.include?(:fizzle).should be_true
|
31
|
+
Fruit.where(:id => f.id).fizzle.first.should_not eql(Fruit.where(:id => f.id).first)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return an ActiveRecord::Relation" do
|
35
|
+
Fruit.replicated(:name => 'slaves')
|
36
|
+
Fruit.slaves.should be_kind_of(ActiveRecord::Relation)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have a different connection" do
|
40
|
+
Fruit.replicated
|
41
|
+
Fruit.slaves.connection.config.should_not eql(Fruit.connection.config)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "the objects return from a query" do
|
46
|
+
# The default connection is the orignal connection for the model
|
47
|
+
it "should have the connection as the replication" do
|
48
|
+
Fruit.replicated
|
49
|
+
FactoryGirl.create(:fruit)
|
50
|
+
Fruit.slaves.first.connection.config.should eql(Fruit.slaves.connection.config)
|
51
|
+
Fruit.slaves.first.should_not be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe'#replicated?' do
|
57
|
+
it "should be false if not replicated" do
|
58
|
+
Fruit.replicated?.should be_false
|
59
|
+
end
|
60
|
+
it "should be true if replicated" do
|
61
|
+
Fruit.replicated
|
62
|
+
Fruit.replicated?.should be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
#ConnectionManager::Connections.build_connection_classes(:env => 'test')
|
69
|
+
class CmFooSlaveConnection < ActiveRecord::Base
|
70
|
+
establish_managed_connection(:slave_1_cm_test)
|
71
|
+
end
|
72
|
+
|
73
|
+
class CmUserConnection < ActiveRecord::Base
|
74
|
+
establish_managed_connection(:cm_user_test)
|
75
|
+
end
|
76
|
+
|
77
|
+
class SlaveCmUserConnection < ActiveRecord::Base
|
78
|
+
establish_managed_connection(:slave_1_cm_user_test)
|
79
|
+
end
|
80
|
+
|
81
|
+
class User < CmUserConnection
|
82
|
+
has_many :foos
|
83
|
+
has_many(:foo_slaves, :class_name => "Foo::Slaves")
|
84
|
+
replicated('SlaveCmUserConnection')
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class Foo < ActiveRecord::Base
|
89
|
+
belongs_to :user
|
90
|
+
replicated("CmFooSlaveConnection")
|
91
|
+
end
|
92
|
+
|
93
|
+
context "eager loading (#includes)" do
|
94
|
+
before :each do
|
95
|
+
@user = User.new(:name => "Testing")
|
96
|
+
@user.save
|
97
|
+
@foo = Foo.new(:user_id => @user.id)
|
98
|
+
@foo.save
|
99
|
+
end
|
100
|
+
|
101
|
+
# We'd like this to happend magically some day. Possible in 3.2
|
102
|
+
it "should eager load with replication instances" do
|
103
|
+
user = User.includes(:foos).slaves.where(:id => @user.id).first
|
104
|
+
user.foos.first.should_not be_kind_of(Foo)
|
105
|
+
end
|
106
|
+
|
107
|
+
context "specifically defined replication association" do
|
108
|
+
it "should eager load with replication instances" do
|
109
|
+
user = User.slaves.includes(:foo_slaves).where(:id => @user.id).first
|
110
|
+
user.foo_slaves.first.should_not be_kind_of(Foo)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context "cross database joins" do
|
115
|
+
before :each do
|
116
|
+
@user = User.new(:name => "Testing")
|
117
|
+
@user.save
|
118
|
+
@foo = Foo.new(:user_id => @user.id)
|
119
|
+
@foo.save
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should work" do
|
123
|
+
@user.foos.blank?.should be_false
|
124
|
+
found = Foo.select('users.name AS user_name').joins(:user).where(:id => @foo.id).first
|
125
|
+
found.user_name.blank?.should be_false
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should work with replication" do
|
129
|
+
found = Foo.slaves.select('foos.*, users.name AS user_name').joins(:user).where(:id => @foo.id).first
|
130
|
+
found.user.blank?.should be_false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe ConnectionManager::Shards do
|
3
|
+
before(:each) do
|
4
|
+
Fruit.shard_class_names("SouthernFruit")
|
5
|
+
end
|
6
|
+
context 'shards'do
|
7
|
+
it "should return an array of results" do
|
8
|
+
a = Fruit.shards do |shard|
|
9
|
+
shard.first
|
10
|
+
end
|
11
|
+
a.should be_a_kind_of(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should execute the active record methods on the the provided models" do
|
15
|
+
fruit = FactoryGirl.create(:fruit)
|
16
|
+
klasses = ["Fruit","SouthernFruit"]
|
17
|
+
a = Fruit.shards do |shard|
|
18
|
+
shard.where(:id => fruit.id).first
|
19
|
+
end
|
20
|
+
klasses.include?(a[0].class.name).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
it "should not matter how the where statement is formated" do
|
25
|
+
fruit = FactoryGirl.create(:fruit)
|
26
|
+
a = Fruit.shards do |shard|
|
27
|
+
shard.where(:id => fruit.id).first
|
28
|
+
end
|
29
|
+
b = Fruit.shards do |shard|
|
30
|
+
shard.where(['id = ?', fruit.id]).first
|
31
|
+
end
|
32
|
+
|
33
|
+
c = Fruit.shards do |shard|
|
34
|
+
shard.where('id = ?', fruit.id).first
|
35
|
+
end
|
36
|
+
|
37
|
+
(a == b && b == c).should be_true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class CmFooSlaveConnection < ActiveRecord::Base
|
3
|
+
establish_managed_connection(:slave_1_cm_test)
|
4
|
+
end
|
5
|
+
class CmMasterConnection < ActiveRecord::Base
|
6
|
+
establish_managed_connection(:master_2_cm_test)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ConnectionManager::Using do
|
10
|
+
|
11
|
+
it "should add module to provided class" do
|
12
|
+
Fruit.send(:build_connection_override_module,"CmFooSlaveConnection")
|
13
|
+
lambda { "CmFooSlaveConnection::ConnectionOverrideMod".constantize}.should_not raise_error(NameError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should extend to module to the supplied class" do
|
17
|
+
Fruit.send(:build_connection_override_module,"CmFooSlaveConnection")
|
18
|
+
d = Fruit.dup
|
19
|
+
d.send(:extend_dup_class,d,"CmFooSlaveConnection")
|
20
|
+
d.connection.config.should_not eql(Fruit.connection.config)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should add sub class to current class with the name of the connection" do
|
24
|
+
Fruit.send(:fetch_duplicate_class,"CmFooSlaveConnection")
|
25
|
+
lambda { "Fruit::CmFooSlaveConnectionDup".constantize}.should_not raise_error(NameError)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
describe '#using' do
|
30
|
+
it "should return an ActiveRecord::Relation" do
|
31
|
+
Fruit.using("CmFooSlaveConnection").should be_kind_of(ActiveRecord::Relation)
|
32
|
+
end
|
33
|
+
it "should change the connection" do
|
34
|
+
Fruit.using("CmFooSlaveConnection").connection.config.should_not eql(Fruit.connection.config)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should create the same sql if called from model or from relation" do
|
38
|
+
Fruit.where(:name => "malarky").using("CmFooSlaveConnection").to_sql.should eql(
|
39
|
+
Fruit.using("CmFooSlaveConnection").where(:name => "malarky").to_sql)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have the same connection if called from model or from relation" do
|
43
|
+
Fruit.where(:name => "malarky").using("CmFooSlaveConnection").connection.config.should eql(
|
44
|
+
Fruit.using("CmFooSlaveConnection").where(:name => "malarky").connection.config)
|
45
|
+
Fruit.using("CmFooSlaveConnection").where(:name => "malarky").connection.config.should_not eql(
|
46
|
+
Fruit.where(:name => "malarky").connection.config)
|
47
|
+
Fruit.where(:name => "malarky").using("CmFooSlaveConnection").connection.config.should_not eql(
|
48
|
+
Fruit.where(:name => "malarky").connection.config)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should work" do
|
52
|
+
FactoryGirl.create(:fruit)
|
53
|
+
Fruit.using("CmFooSlaveConnection").first
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should really use a different connection" do
|
57
|
+
f = Fruit.using("CmMasterConnection").new
|
58
|
+
f.name = FactoryGirl.generate(:rand_name)
|
59
|
+
f.save
|
60
|
+
Fruit.where(:name => "malarky").first.should be_nil
|
61
|
+
Fruit.using("CmFooSlaveConnection").where(:name => f.name).first.should be_nil
|
62
|
+
Fruit.using("CmMasterConnection").where(:name => f.name).first.should_not be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should save to schema/database set in connection class different" do
|
66
|
+
Fruit.table_name_prefix = "cm_test."
|
67
|
+
f = Fruit.using("CmMasterConnection").new
|
68
|
+
f.name = FactoryGirl.generate(:rand_name)
|
69
|
+
f.save
|
70
|
+
Fruit.where(:name => f.name).first.should be_nil
|
71
|
+
Fruit.using("CmFooSlaveConnection").where(:name => f.name).first.should be_nil
|
72
|
+
Fruit.using("CmMasterConnection").where(:name => f.name).first.should_not be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
data/spec/mysql2_database.yml
CHANGED
@@ -7,23 +7,49 @@ common: &common
|
|
7
7
|
password: omegared
|
8
8
|
pool: 100
|
9
9
|
timeout: 5000
|
10
|
+
build_connection_class: true
|
11
|
+
|
12
|
+
master: &master
|
13
|
+
username: root
|
14
|
+
password: omegared
|
15
|
+
|
16
|
+
readonly: &readonly
|
17
|
+
username: readonly
|
18
|
+
password: omegared
|
10
19
|
|
11
20
|
test:
|
12
21
|
<<: *common
|
22
|
+
<<: *master
|
13
23
|
database: cm_test
|
24
|
+
slaves: [slave_1_cm_test, slave_2_cm_test]
|
14
25
|
|
15
26
|
cm_user_test:
|
16
27
|
<<: *common
|
28
|
+
<<: *master
|
17
29
|
database: cm_user_test
|
30
|
+
slaves: [slave_1_cm_user_test]
|
18
31
|
|
19
32
|
slave_1_cm_test:
|
20
|
-
<<: *common
|
33
|
+
<<: *common
|
34
|
+
<<: *readonly
|
21
35
|
database: cm_test
|
22
36
|
|
23
37
|
slave_2_cm_test:
|
24
38
|
<<: *common
|
39
|
+
<<: *readonly
|
25
40
|
database: cm_test
|
41
|
+
|
42
|
+
master_2_cm_test:
|
43
|
+
<<: *common
|
44
|
+
<<: *master
|
45
|
+
database: cm_master_2_test
|
26
46
|
|
27
47
|
shard_1_cm_test:
|
28
48
|
<<: *common
|
29
|
-
|
49
|
+
<<: *master
|
50
|
+
database: legacy_cm_test
|
51
|
+
|
52
|
+
slave_1_cm_user_test:
|
53
|
+
<<: *common
|
54
|
+
<<: *readonly
|
55
|
+
database: cm_user_test
|
data/spec/spec_helper.rb
CHANGED
@@ -1,25 +1,39 @@
|
|
1
|
+
ENV["AR_ENV"] ="test"
|
1
2
|
require 'connection_manager'
|
2
3
|
require 'rspec'
|
3
4
|
require 'bundler/setup'
|
4
5
|
require 'active_record'
|
6
|
+
require 'active_support'
|
7
|
+
require 'logger'
|
5
8
|
require 'factory_girl'
|
6
9
|
require 'helpers/database_spec_helper'
|
10
|
+
if(defined? RUBY_ENGINE and 'jruby' == RUBY_ENGINE)
|
11
|
+
TestDB.connect('jdbcmysql')
|
12
|
+
else
|
13
|
+
TestDB.connect('mysql2')
|
14
|
+
end
|
7
15
|
|
8
|
-
|
16
|
+
TestMigrations.down
|
9
17
|
TestMigrations.up
|
10
18
|
FactoryGirl.find_definitions
|
11
|
-
|
12
19
|
RSpec.configure do |config|
|
13
20
|
config.mock_with :mocha
|
14
21
|
# Loads database.yml and establishes primary connection
|
15
22
|
# Create tables when tests are completed
|
16
23
|
config.before(:all) {
|
17
|
-
require 'helpers/models_spec_helper'
|
18
|
-
}
|
24
|
+
require 'helpers/models_spec_helper.rb'
|
25
|
+
}
|
19
26
|
# Drops tables when tests are completed
|
20
|
-
config.after(:
|
21
|
-
|
27
|
+
config.after(:all){
|
28
|
+
TestDB.clean
|
29
|
+
}
|
30
|
+
# Make sure every test is isolated.
|
31
|
+
config.before(:each){
|
32
|
+
ModelsHelper.models.each{|m| Object.send(:remove_const, m)}
|
33
|
+
load 'helpers/models_spec_helper.rb'
|
34
|
+
FactoryGirl.reload
|
22
35
|
}
|
36
|
+
|
23
37
|
end
|
24
38
|
|
25
39
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connection_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70326690672520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70326690672520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: rspec
|
27
|
+
requirement: &70326690672100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70326690672100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: autotest
|
38
|
+
requirement: &70326690671520 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70326690671520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement: &
|
48
|
+
name: mocha
|
49
|
+
requirement: &70326690664940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70326690664940
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
60
|
-
requirement: &
|
59
|
+
name: factory_girl
|
60
|
+
requirement: &70326690664440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,21 +65,21 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70326690664440
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: &
|
70
|
+
name: activesupport
|
71
|
+
requirement: &70326690663900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
76
|
+
version: '3.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70326690663900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mysql2
|
82
|
-
requirement: &
|
82
|
+
requirement: &70326690663440 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70326690663440
|
91
91
|
description: Simplifies connecting to Muliple and Replication databases with rails
|
92
92
|
and active_record
|
93
93
|
email:
|
@@ -99,27 +99,29 @@ files:
|
|
99
99
|
- .gitignore
|
100
100
|
- .rspec
|
101
101
|
- Gemfile
|
102
|
-
- Gemfile.lock
|
103
102
|
- LICENSE.txt
|
104
103
|
- README.md
|
105
104
|
- Rakefile
|
106
105
|
- connection_manager.gemspec
|
107
106
|
- lib/connection_manager.rb
|
108
|
-
- lib/connection_manager/
|
107
|
+
- lib/connection_manager/connection_builder.rb
|
109
108
|
- lib/connection_manager/connection_manager_railtie.rb
|
110
|
-
- lib/connection_manager/
|
111
|
-
- lib/connection_manager/
|
112
|
-
- lib/connection_manager/
|
113
|
-
- lib/connection_manager/
|
109
|
+
- lib/connection_manager/helpers/abstract_adapter_helper.rb
|
110
|
+
- lib/connection_manager/helpers/connection_helpers.rb
|
111
|
+
- lib/connection_manager/patches/cross_schema_patch.rb
|
112
|
+
- lib/connection_manager/replication.rb
|
113
|
+
- lib/connection_manager/shards.rb
|
114
|
+
- lib/connection_manager/using.rb
|
114
115
|
- lib/connection_manager/version.rb
|
115
116
|
- spec/factories.rb
|
116
117
|
- spec/helpers/database_spec_helper.rb
|
117
118
|
- spec/helpers/models_spec_helper.rb
|
118
|
-
- spec/
|
119
|
-
- spec/lib/
|
120
|
-
- spec/lib/
|
121
|
-
- spec/lib/
|
122
|
-
- spec/lib/
|
119
|
+
- spec/jdbcmysql_database.yml
|
120
|
+
- spec/lib/connection_builder_spec.rb
|
121
|
+
- spec/lib/connection_helpers_spec.rb
|
122
|
+
- spec/lib/replication_spec.rb
|
123
|
+
- spec/lib/shards_spec.rb
|
124
|
+
- spec/lib/using_spec.rb
|
123
125
|
- spec/mysql2_database.yml
|
124
126
|
- spec/spec.opts
|
125
127
|
- spec/spec_helper.rb
|
@@ -153,11 +155,12 @@ test_files:
|
|
153
155
|
- spec/factories.rb
|
154
156
|
- spec/helpers/database_spec_helper.rb
|
155
157
|
- spec/helpers/models_spec_helper.rb
|
156
|
-
- spec/
|
157
|
-
- spec/lib/
|
158
|
-
- spec/lib/
|
159
|
-
- spec/lib/
|
160
|
-
- spec/lib/
|
158
|
+
- spec/jdbcmysql_database.yml
|
159
|
+
- spec/lib/connection_builder_spec.rb
|
160
|
+
- spec/lib/connection_helpers_spec.rb
|
161
|
+
- spec/lib/replication_spec.rb
|
162
|
+
- spec/lib/shards_spec.rb
|
163
|
+
- spec/lib/using_spec.rb
|
161
164
|
- spec/mysql2_database.yml
|
162
165
|
- spec/spec.opts
|
163
166
|
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
connection_manager (0.2.5)
|
5
|
-
activerecord (~> 3.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ZenTest (4.7.0)
|
11
|
-
activemodel (3.2.3)
|
12
|
-
activesupport (= 3.2.3)
|
13
|
-
builder (~> 3.0.0)
|
14
|
-
activerecord (3.2.3)
|
15
|
-
activemodel (= 3.2.3)
|
16
|
-
activesupport (= 3.2.3)
|
17
|
-
arel (~> 3.0.2)
|
18
|
-
tzinfo (~> 0.3.29)
|
19
|
-
activesupport (3.2.3)
|
20
|
-
i18n (~> 0.6)
|
21
|
-
multi_json (~> 1.0)
|
22
|
-
arel (3.0.2)
|
23
|
-
autotest (4.4.6)
|
24
|
-
ZenTest (>= 4.4.1)
|
25
|
-
builder (3.0.0)
|
26
|
-
diff-lcs (1.1.3)
|
27
|
-
factory_girl (3.2.0)
|
28
|
-
activesupport (>= 3.0.0)
|
29
|
-
i18n (0.6.0)
|
30
|
-
metaclass (0.0.1)
|
31
|
-
mocha (0.11.3)
|
32
|
-
metaclass (~> 0.0.1)
|
33
|
-
multi_json (1.3.2)
|
34
|
-
mysql2 (0.3.11)
|
35
|
-
rspec (2.9.0)
|
36
|
-
rspec-core (~> 2.9.0)
|
37
|
-
rspec-expectations (~> 2.9.0)
|
38
|
-
rspec-mocks (~> 2.9.0)
|
39
|
-
rspec-core (2.9.0)
|
40
|
-
rspec-expectations (2.9.1)
|
41
|
-
diff-lcs (~> 1.1.3)
|
42
|
-
rspec-mocks (2.9.0)
|
43
|
-
sqlite3 (1.3.6)
|
44
|
-
tzinfo (0.3.33)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
ruby
|
48
|
-
|
49
|
-
DEPENDENCIES
|
50
|
-
autotest
|
51
|
-
connection_manager!
|
52
|
-
factory_girl
|
53
|
-
mocha
|
54
|
-
mysql2
|
55
|
-
rspec
|
56
|
-
sqlite3
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module ConnectionManager
|
2
|
-
module Associations
|
3
|
-
@defined_associations
|
4
|
-
|
5
|
-
# Stores defined associtions and their options
|
6
|
-
def defined_associations
|
7
|
-
@defined_associations ||= {}
|
8
|
-
end
|
9
|
-
|
10
|
-
def belongs_to(*options)
|
11
|
-
defined_associations[:belongs_to] ||= []
|
12
|
-
defined_associations[:belongs_to] << options
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def has_many(*options)
|
17
|
-
defined_associations[:has_many] ||= []
|
18
|
-
defined_associations[:has_many] << options
|
19
|
-
super
|
20
|
-
end
|
21
|
-
|
22
|
-
def has_one(*options)
|
23
|
-
defined_associations[:has_one] ||= []
|
24
|
-
defined_associations[:has_one] << options
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|