connection_manager 1.0.4 → 1.1.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.
- checksums.yaml +8 -8
- data/CHANGE.md +12 -1
- data/README.md +99 -82
- data/connection_manager.gemspec +7 -11
- data/lib/connection_manager/builder.rb +56 -0
- data/lib/connection_manager/connection_adapters/abstract_adapter.rb +50 -0
- data/lib/connection_manager/connection_adapters/mysql_adapter.rb +39 -0
- data/lib/connection_manager/connection_handling.rb +91 -0
- data/lib/connection_manager/core.rb +24 -0
- data/lib/connection_manager/querying.rb +13 -0
- data/lib/connection_manager/railtie.rb +10 -0
- data/lib/connection_manager/relation.rb +21 -0
- data/lib/connection_manager/replication.rb +56 -85
- data/lib/connection_manager/shards.rb +2 -1
- data/lib/connection_manager/using.rb +30 -24
- data/lib/connection_manager/version.rb +1 -1
- data/lib/connection_manager.rb +26 -16
- data/spec/{mysql2_database.yml → database.yml} +30 -26
- data/spec/factories.rb +1 -1
- data/spec/helpers/database_spec_helper.rb +91 -62
- data/spec/helpers/models_spec_helper.rb +23 -12
- data/spec/lib/builder_spec.rb +31 -0
- data/spec/lib/connection_adapters/abstract_adapter_spec.rb +48 -0
- data/spec/lib/connection_adapters/mysql_adapter_spec.rb +13 -0
- data/spec/lib/connection_handling_spec.rb +65 -0
- data/spec/lib/core_spec.rb +10 -0
- data/spec/lib/integration/cross_schema_spec.rb +35 -0
- data/spec/lib/querying_spec.rb +19 -0
- data/spec/lib/relation_spec.rb +21 -0
- data/spec/lib/replication_spec.rb +19 -57
- data/spec/lib/shards_spec.rb +3 -3
- data/spec/lib/using_proxy_spec.rb +27 -0
- data/spec/lib/using_spec.rb +28 -15
- data/spec/spec_helper.rb +2 -10
- metadata +73 -35
- data/lib/connection_manager/connection_builder.rb +0 -82
- data/lib/connection_manager/connection_manager_railtie.rb +0 -8
- data/lib/connection_manager/helpers/abstract_adapter_helper.rb +0 -95
- data/lib/connection_manager/helpers/connection_helpers.rb +0 -119
- data/lib/connection_manager/patches/cross_schema_patch.rb +0 -67
- data/spec/jdbcmysql_database.yml +0 -50
- data/spec/lib/connection_builder_spec.rb +0 -28
- data/spec/lib/connection_helpers_spec.rb +0 -79
- data/spec/lib/patches/cross_schema_path_spec.rb +0 -74
- data/spec/sqlite_database.yml +0 -26
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe ConnectionManager::ConnectionHelpers do
|
3
|
-
before(:all) do
|
4
|
-
|
5
|
-
class MyConnectionClass < ActiveRecord::Base
|
6
|
-
establish_managed_connection(:test)
|
7
|
-
end
|
8
|
-
|
9
|
-
class MyReadonlyConnectionClass < ActiveRecord::Base
|
10
|
-
establish_managed_connection({
|
11
|
-
:database => "cm_test",
|
12
|
-
:adapter => "mysql2",
|
13
|
-
:username => TestDB.yml("mysql2")["test"]["username"],
|
14
|
-
:password => TestDB.yml("mysql2")["test"]["password"]
|
15
|
-
|
16
|
-
}, {:readonly => true})
|
17
|
-
end
|
18
|
-
|
19
|
-
class MyPrefixedConnection < MyConnectionClass
|
20
|
-
self.abstract_class = true
|
21
|
-
self.use_database("boo")
|
22
|
-
end
|
23
|
-
|
24
|
-
class MyFoo < MyConnectionClass
|
25
|
-
self.table_name = 'foos'
|
26
|
-
end
|
27
|
-
|
28
|
-
class MyReadonlyFoo < MyReadonlyConnectionClass
|
29
|
-
self.table_name = 'foos'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
describe '#establish_managed_connection' do
|
33
|
-
context 'the connection class' do
|
34
|
-
|
35
|
-
it "should create abstract class" do
|
36
|
-
MyConnectionClass.abstract_class.should be_true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should checkin the connection" do
|
40
|
-
ActiveRecord::Base.managed_connection_classes.include?("MyConnectionClass").should be_true
|
41
|
-
ActiveRecord::Base.managed_connection_classes.include?("MyReadonlyConnectionClass").should be_true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
context 'the model' do
|
45
|
-
it "should not be readonly" do
|
46
|
-
u = MyFoo.new
|
47
|
-
u.readonly?.should_not be_true
|
48
|
-
end
|
49
|
-
it "should be readonly if readonly option for establish_managed_connection from connaction class is true" do
|
50
|
-
u = MyReadonlyFoo.new
|
51
|
-
u.readonly?.should be_true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#use_database' do
|
57
|
-
it "should set the database/schema for the model to the supplied schema_name" do
|
58
|
-
Fruit.use_database('my_schema')
|
59
|
-
Fruit.current_database_name.should eql('my_schema')
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should set the contactinate the schema_name and table_name; and set the table_name to that value" do
|
63
|
-
Fruit.use_database('my_schema')
|
64
|
-
Fruit.table_name.should eql('my_schema.fruits')
|
65
|
-
Fruit.table_name_prefix.should eql('my_schema.')
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should set the table_name if one is supplied" do
|
69
|
-
Fruit.use_database('my_schema',{:table_name => 'apples'})
|
70
|
-
Fruit.table_name.should eql('my_schema.apples')
|
71
|
-
Fruit.table_name_prefix.should eql('my_schema.')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should have the correct database name" do
|
76
|
-
MyPrefixedConnection.current_database_name.should eql('boo')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe ActiveRecord::ConnectionAdapters::AbstractAdapter do
|
3
|
-
|
4
|
-
describe '#fetch_table_schema' do
|
5
|
-
context "table is unique in DMS" do
|
6
|
-
it "should return a string consisting of the schema name, a '.' and the table_name" do
|
7
|
-
Fruit.connection.fetch_table_schema('fruits').should eql('cm_test')
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context "table is not unique in DMS" do
|
12
|
-
it "should return a string consisting of the schema name, a '.' and the table_name" do
|
13
|
-
Fruit.connection.fetch_table_schema('type').should eql(nil)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#fetch_full_table_name' do
|
19
|
-
it "should return a string consisting of the schema name, a '.' and the table_name" do
|
20
|
-
Fruit.connection.fetch_full_table_name('fruits').should eql('cm_test.fruits')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#table_exists?' do
|
25
|
-
it "should return true for unquoted full_names" do
|
26
|
-
Fruit.connection.table_exists?('cm_test.fruits').should be_true
|
27
|
-
end
|
28
|
-
it "should return true for table only names" do
|
29
|
-
Fruit.connection.table_exists?('fruits').should be_true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
describe ActiveRecord::Base do
|
34
|
-
describe '#arel_table' do
|
35
|
-
it "should use quote_table_name" do
|
36
|
-
Fruit.arel_table.name.should eql('cm_test.fruits')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "Cross Schema Joins" do
|
41
|
-
before :each do
|
42
|
-
@user = CmUser.new(:name => "Testing")
|
43
|
-
@user.save
|
44
|
-
@foo = Foo.new(:cm_user_id => @user.id)
|
45
|
-
@foo.save
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#joins' do
|
49
|
-
it "should work" do
|
50
|
-
@user.foos.blank?.should be_false
|
51
|
-
found = Foo.joins(:cm_user).select('cm_users.name AS user_name').where('cm_users.id = ?',@user.id).first
|
52
|
-
found.user_name.blank?.should be_false
|
53
|
-
end
|
54
|
-
end
|
55
|
-
describe '#includes' do
|
56
|
-
before(:each) do
|
57
|
-
@user.foos.blank?.should be_false
|
58
|
-
search = Foo.includes(:cm_user).where('cm_users.id = ?',@user.id)
|
59
|
-
search = search.references(:cm_user) if search.respond_to?(:references)
|
60
|
-
@found = search.first
|
61
|
-
end
|
62
|
-
it "should return a results" do
|
63
|
-
@found.should be_a(Foo) # Make sure results are returns
|
64
|
-
end
|
65
|
-
it "should loan associations" do
|
66
|
-
if @found.respond_to?(:association)
|
67
|
-
@found.association(:cm_user).loaded?.should be_true
|
68
|
-
else
|
69
|
-
@found.cm_user.loaded?.should be_true
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/spec/sqlite_database.yml
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# Warning: The database defined as "test" will be erased and
|
2
|
-
# re-generated from your development database when you run "rake".
|
3
|
-
# Do not set this db to the same as development or production.
|
4
|
-
test:
|
5
|
-
adapter: sqlite3
|
6
|
-
database: spec/cm_test.sqlite3
|
7
|
-
pool: 5
|
8
|
-
timeout: 5000
|
9
|
-
|
10
|
-
slave_1_cm_test:
|
11
|
-
adapter: sqlite3
|
12
|
-
database: spec/cm_test.sqlite3
|
13
|
-
pool: 5
|
14
|
-
timeout: 5000
|
15
|
-
|
16
|
-
slave_2_cm_test:
|
17
|
-
adapter: sqlite3
|
18
|
-
database: spec/cm_test.sqlite3
|
19
|
-
pool: 5
|
20
|
-
timeout: 5000
|
21
|
-
|
22
|
-
shard_1_cm_test:
|
23
|
-
adapter: sqlite3
|
24
|
-
database: spec/legacy_cm_test.sqlite3
|
25
|
-
pool: 5
|
26
|
-
timeout: 5000
|