connection_manager 0.0.1
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 +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +20 -0
- data/README.md +135 -0
- data/Rakefile +1 -0
- data/connection_manager.gemspec +24 -0
- data/lib/connection_manager.rb +9 -0
- data/lib/connection_manager/associations.rb +29 -0
- data/lib/connection_manager/connection_manager_railtie.rb +9 -0
- data/lib/connection_manager/connections.rb +110 -0
- data/lib/connection_manager/replication_builder.rb +135 -0
- data/lib/connection_manager/version.rb +4 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +13 -0
- data/test_app/.gitignore +15 -0
- data/test_app/.rspec +1 -0
- data/test_app/Gemfile +14 -0
- data/test_app/Gemfile.lock +140 -0
- data/test_app/README +261 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/models/.gitkeep +0 -0
- data/test_app/app/models/basket.rb +4 -0
- data/test_app/app/models/fruit.rb +6 -0
- data/test_app/app/models/fruit_basket.rb +4 -0
- data/test_app/app/models/region.rb +3 -0
- data/test_app/app/models/type.rb +2 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/application.rb +52 -0
- data/test_app/config/boot.rb +6 -0
- data/test_app/config/database.yml +42 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +30 -0
- data/test_app/config/environments/production.rb +60 -0
- data/test_app/config/environments/test.rb +39 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/inflections.rb +10 -0
- data/test_app/config/initializers/load_connection_manager.rb +6 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/routes.rb +58 -0
- data/test_app/db/migrate/20111127040654_create_fruits.rb +9 -0
- data/test_app/db/migrate/20111127040720_create_baskets.rb +9 -0
- data/test_app/db/migrate/20111127040846_create_fruit_baskets.rb +9 -0
- data/test_app/db/migrate/20111127040915_create_regions.rb +9 -0
- data/test_app/db/migrate/20111127060322_create_types.rb +9 -0
- data/test_app/db/schema.rb +16 -0
- data/test_app/db/seeds.rb +7 -0
- data/test_app/log/.gitkeep +0 -0
- data/test_app/script/rails +6 -0
- data/test_app/spec/connection_manager/associations_spec.rb +29 -0
- data/test_app/spec/connection_manager/connections_spec.rb +51 -0
- data/test_app/spec/connection_manager/replication_builder_spec.rb +33 -0
- data/test_app/spec/factories/baskets.rb +7 -0
- data/test_app/spec/factories/fruit_baskets.rb +8 -0
- data/test_app/spec/factories/fruits.rb +8 -0
- data/test_app/spec/factories/regions.rb +7 -0
- data/test_app/spec/factories/types.rb +7 -0
- data/test_app/spec/models/type_spec.rb +5 -0
- data/test_app/spec/spec.opts +4 -0
- data/test_app/spec/spec_helper.rb +42 -0
- data/test_app/test_app +0 -0
- metadata +158 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
|
5
|
+
#
|
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
|
7
|
+
# database schema. If you need to create the application database on another
|
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
11
|
+
#
|
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
|
13
|
+
|
|
14
|
+
ActiveRecord::Schema.define(:version => 0) do
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
|
3
|
+
#
|
|
4
|
+
# Examples:
|
|
5
|
+
#
|
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Foo < ActiveRecord::Base
|
|
4
|
+
belongs_to :that
|
|
5
|
+
has_many :foo_bars
|
|
6
|
+
has_many :bars, :through => :foo_bars
|
|
7
|
+
has_one :noob
|
|
8
|
+
end
|
|
9
|
+
class Bar < ActiveRecord::Base
|
|
10
|
+
has_many :foo_bars
|
|
11
|
+
has_many :foos, :through => :foo_bars
|
|
12
|
+
end
|
|
13
|
+
describe ConnectionManager::Associations do
|
|
14
|
+
|
|
15
|
+
it "should add associations as keys to @defined_associations" do
|
|
16
|
+
Foo.defined_associations.keys.should eql([:belongs_to,:has_many,:has_one])
|
|
17
|
+
Bar.defined_associations.keys.should eql([:has_many])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "defined_association values" do
|
|
21
|
+
it "should be an array of association options (which are Arrays as well)" do
|
|
22
|
+
Foo.defined_associations[:belongs_to].should eql([[:that]])
|
|
23
|
+
Foo.defined_associations[:has_many].should eql([[:foo_bars],[:bars, {:through=>:foo_bars, :extend=>[]}]]) # when options are present active_record addes the :extend option defaulted to []
|
|
24
|
+
Foo.defined_associations[:has_one].should eql([[:noob]])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
describe ConnectionManager::Connections do
|
|
3
|
+
|
|
4
|
+
context '#all' do
|
|
5
|
+
it "should return the database.yml entries for the current rails environment" do
|
|
6
|
+
ConnectionManager::Connections.all.should eql(["TestAppConnection", "Slave1TestAppConnection"])
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context '#replication_connections' do
|
|
11
|
+
it "should return a hash where the keys are the generic class names for available_connections" do
|
|
12
|
+
ConnectionManager::Connections.replication_connections.keys.
|
|
13
|
+
should eql([:test_test_app, :slave_test_app])
|
|
14
|
+
end
|
|
15
|
+
it "should return a hash where the values are an array of connection class names as strings" do
|
|
16
|
+
first_value = ConnectionManager::Connections.replication_connections.values.first
|
|
17
|
+
first_value.class.should eql(Array)
|
|
18
|
+
defined?((ConnectionManager::Connections.class_eval(first_value[0]))).should be_true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context '#connection_class_name' do
|
|
23
|
+
it "should return a string for a class name appended with 'Connection' " do
|
|
24
|
+
ConnectionManager::Connections.connection_class_name("my_database").should eql("MyDatabaseConnection")
|
|
25
|
+
end
|
|
26
|
+
it "should return remove the appended rails env" do
|
|
27
|
+
ConnectionManager::Connections.connection_class_name("my_database_test").should eql("MyDatabaseConnection")
|
|
28
|
+
end
|
|
29
|
+
it "should handle sqlite database names correctly " do
|
|
30
|
+
ConnectionManager::Connections.connection_class_name("db/my_database_test.sqlite3").should eql("MyDatabaseConnection")
|
|
31
|
+
end
|
|
32
|
+
it "should use the database name from the database.yml if supplied string is only is only the Rails.env" do
|
|
33
|
+
ConnectionManager::Connections.stubs(:database_name_from_yml).returns("MyTest")
|
|
34
|
+
ConnectionManager::Connections.connection_class_name("test").should eql("MyTestConnection")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context '#build_connection_class' do
|
|
39
|
+
before(:all) do
|
|
40
|
+
ConnectionManager::Connections.build_connection_class("MyConnectionClass", 'test')
|
|
41
|
+
end
|
|
42
|
+
it "should add a class with supplied class name to ConnectionManager::Connections" do
|
|
43
|
+
defined?(ConnectionManager::Connections::MyConnectionClass).should be_true
|
|
44
|
+
ConnectionManager::Connections::MyConnectionClass.is_a?(Class).should be_true
|
|
45
|
+
end
|
|
46
|
+
it "should have a super class of ActiveRecord::Base" do
|
|
47
|
+
ConnectionManager::Connections::MyConnectionClass.superclass.should eql(ActiveRecord::Base)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ConnectionManager::ReplicationBuilder do
|
|
4
|
+
|
|
5
|
+
context '#database_name' do
|
|
6
|
+
it "should return the name of the database the model is using" do
|
|
7
|
+
Fruit.database_name.should eql('test_app')
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context '#other_association_options' do
|
|
12
|
+
|
|
13
|
+
it "should add :class_name options set to the replication subclass if :class_name is blank" do
|
|
14
|
+
options = Fruit.replication_association_options(:has_one, :plant, 'Slave')
|
|
15
|
+
options[:class_name].should eql("Plant::Slave")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should append :class_name with the replication subclass if :class_name is not bank" do
|
|
19
|
+
options = Fruit.replication_association_options(:has_one, :plant, 'Slave', :class_name => 'Plant')
|
|
20
|
+
options[:class_name].should eql("Plant::Slave")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "has_one or has_many" do
|
|
24
|
+
it "should add the :foreign_key if the :foreign_key options is not present" do
|
|
25
|
+
options = Fruit.replication_association_options(:has_one, :plant, 'Slave')
|
|
26
|
+
options[:foreign_key].should eql('fruit_id')
|
|
27
|
+
options = Fruit.replication_association_options(:has_many, :plant, 'Slave')
|
|
28
|
+
options[:foreign_key].should eql('fruit_id')
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
|
4
|
+
require 'rspec/rails'
|
|
5
|
+
require 'rspec/autorun'
|
|
6
|
+
|
|
7
|
+
# Use class/modules from gem directories for testing
|
|
8
|
+
path = "../../../lib/connection_manager"
|
|
9
|
+
require "#{File.expand_path("#{path}.rb", __FILE__)}"
|
|
10
|
+
require "#{File.expand_path("#{path}/connections.rb", __FILE__)}"
|
|
11
|
+
require "#{File.expand_path("#{path}/associations.rb", __FILE__)}"
|
|
12
|
+
require "#{File.expand_path("#{path}/replication_builder.rb", __FILE__)}"
|
|
13
|
+
require "#{File.expand_path("#{path}/version.rb", __FILE__)}"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
17
|
+
# in spec/support/ and its subdirectories.
|
|
18
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
|
19
|
+
|
|
20
|
+
RSpec.configure do |config|
|
|
21
|
+
# == Mock Framework
|
|
22
|
+
#
|
|
23
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
24
|
+
#
|
|
25
|
+
config.mock_with :mocha
|
|
26
|
+
# config.mock_with :flexmock
|
|
27
|
+
# config.mock_with :rr
|
|
28
|
+
# config.mock_with :rspec
|
|
29
|
+
|
|
30
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
31
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
|
32
|
+
|
|
33
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
34
|
+
# examples within a transaction, remove the following line or assign false
|
|
35
|
+
# instead of true.
|
|
36
|
+
config.use_transactional_fixtures = true
|
|
37
|
+
|
|
38
|
+
# If true, the base class of anonymous controllers will be inferred
|
|
39
|
+
# automatically. This will be the default behavior in future versions of
|
|
40
|
+
# rspec-rails.
|
|
41
|
+
config.infer_base_class_for_anonymous_controllers = false
|
|
42
|
+
end
|
data/test_app/test_app
ADDED
|
Binary file
|
metadata
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: connection_manager
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Joshua Mckinney
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-11-29 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: activerecord
|
|
16
|
+
requirement: &70269785054740 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '3.0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70269785054740
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: rspec
|
|
27
|
+
requirement: &70269785054320 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70269785054320
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: autotest
|
|
38
|
+
requirement: &70269785053860 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :development
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70269785053860
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: mocha
|
|
49
|
+
requirement: &70269785082360 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *70269785082360
|
|
58
|
+
description: Simplifies connecting to Muliple and Replication databases with rails
|
|
59
|
+
and active_record
|
|
60
|
+
email:
|
|
61
|
+
- joshmckin@gmail.com
|
|
62
|
+
executables: []
|
|
63
|
+
extensions: []
|
|
64
|
+
extra_rdoc_files: []
|
|
65
|
+
files:
|
|
66
|
+
- .gitignore
|
|
67
|
+
- Gemfile
|
|
68
|
+
- Gemfile.lock
|
|
69
|
+
- LICENSE.txt
|
|
70
|
+
- README.md
|
|
71
|
+
- Rakefile
|
|
72
|
+
- connection_manager.gemspec
|
|
73
|
+
- lib/connection_manager.rb
|
|
74
|
+
- lib/connection_manager/associations.rb
|
|
75
|
+
- lib/connection_manager/connection_manager_railtie.rb
|
|
76
|
+
- lib/connection_manager/connections.rb
|
|
77
|
+
- lib/connection_manager/replication_builder.rb
|
|
78
|
+
- lib/connection_manager/version.rb
|
|
79
|
+
- spec/spec.opts
|
|
80
|
+
- spec/spec_helper.rb
|
|
81
|
+
- test_app/.gitignore
|
|
82
|
+
- test_app/.rspec
|
|
83
|
+
- test_app/Gemfile
|
|
84
|
+
- test_app/Gemfile.lock
|
|
85
|
+
- test_app/README
|
|
86
|
+
- test_app/Rakefile
|
|
87
|
+
- test_app/app/models/.gitkeep
|
|
88
|
+
- test_app/app/models/basket.rb
|
|
89
|
+
- test_app/app/models/fruit.rb
|
|
90
|
+
- test_app/app/models/fruit_basket.rb
|
|
91
|
+
- test_app/app/models/region.rb
|
|
92
|
+
- test_app/app/models/type.rb
|
|
93
|
+
- test_app/config.ru
|
|
94
|
+
- test_app/config/application.rb
|
|
95
|
+
- test_app/config/boot.rb
|
|
96
|
+
- test_app/config/database.yml
|
|
97
|
+
- test_app/config/environment.rb
|
|
98
|
+
- test_app/config/environments/development.rb
|
|
99
|
+
- test_app/config/environments/production.rb
|
|
100
|
+
- test_app/config/environments/test.rb
|
|
101
|
+
- test_app/config/initializers/backtrace_silencers.rb
|
|
102
|
+
- test_app/config/initializers/inflections.rb
|
|
103
|
+
- test_app/config/initializers/load_connection_manager.rb
|
|
104
|
+
- test_app/config/initializers/mime_types.rb
|
|
105
|
+
- test_app/config/initializers/secret_token.rb
|
|
106
|
+
- test_app/config/initializers/session_store.rb
|
|
107
|
+
- test_app/config/initializers/wrap_parameters.rb
|
|
108
|
+
- test_app/config/locales/en.yml
|
|
109
|
+
- test_app/config/routes.rb
|
|
110
|
+
- test_app/db/migrate/20111127040654_create_fruits.rb
|
|
111
|
+
- test_app/db/migrate/20111127040720_create_baskets.rb
|
|
112
|
+
- test_app/db/migrate/20111127040846_create_fruit_baskets.rb
|
|
113
|
+
- test_app/db/migrate/20111127040915_create_regions.rb
|
|
114
|
+
- test_app/db/migrate/20111127060322_create_types.rb
|
|
115
|
+
- test_app/db/schema.rb
|
|
116
|
+
- test_app/db/seeds.rb
|
|
117
|
+
- test_app/log/.gitkeep
|
|
118
|
+
- test_app/script/rails
|
|
119
|
+
- test_app/spec/connection_manager/associations_spec.rb
|
|
120
|
+
- test_app/spec/connection_manager/connections_spec.rb
|
|
121
|
+
- test_app/spec/connection_manager/replication_builder_spec.rb
|
|
122
|
+
- test_app/spec/factories/baskets.rb
|
|
123
|
+
- test_app/spec/factories/fruit_baskets.rb
|
|
124
|
+
- test_app/spec/factories/fruits.rb
|
|
125
|
+
- test_app/spec/factories/regions.rb
|
|
126
|
+
- test_app/spec/factories/types.rb
|
|
127
|
+
- test_app/spec/models/type_spec.rb
|
|
128
|
+
- test_app/spec/spec.opts
|
|
129
|
+
- test_app/spec/spec_helper.rb
|
|
130
|
+
- test_app/test_app
|
|
131
|
+
homepage: ''
|
|
132
|
+
licenses: []
|
|
133
|
+
post_install_message:
|
|
134
|
+
rdoc_options: []
|
|
135
|
+
require_paths:
|
|
136
|
+
- lib
|
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
|
+
none: false
|
|
139
|
+
requirements:
|
|
140
|
+
- - ! '>='
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
|
+
none: false
|
|
145
|
+
requirements:
|
|
146
|
+
- - ! '>='
|
|
147
|
+
- !ruby/object:Gem::Version
|
|
148
|
+
version: '0'
|
|
149
|
+
requirements: []
|
|
150
|
+
rubyforge_project: connection_manager
|
|
151
|
+
rubygems_version: 1.8.6
|
|
152
|
+
signing_key:
|
|
153
|
+
specification_version: 3
|
|
154
|
+
summary: Simplifies connecting to Muliple and Replication databases with rails and
|
|
155
|
+
active_record
|
|
156
|
+
test_files:
|
|
157
|
+
- spec/spec.opts
|
|
158
|
+
- spec/spec_helper.rb
|