connection_manager 0.0.1 → 0.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.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/Gemfile.lock +8 -3
- data/README.md +26 -26
- data/connection_manager.gemspec +2 -0
- data/lib/connection_manager.rb +1 -0
- data/lib/connection_manager/connections.rb +34 -25
- data/lib/connection_manager/replication_builder.rb +11 -12
- data/lib/connection_manager/version.rb +1 -1
- data/spec/database.yml +20 -0
- data/spec/factories.rb +31 -0
- data/spec/helpers/database_spec_helper.rb +68 -0
- data/spec/helpers/models_spec_helper.rb +26 -0
- data/spec/integration/replication_builder_spec.rb +97 -0
- data/{test_app/spec/connection_manager → spec/lib}/associations_spec.rb +0 -0
- data/spec/lib/connections_spec.rb +93 -0
- data/{test_app/spec/connection_manager → spec/lib}/replication_builder_spec.rb +17 -1
- data/spec/spec_helper.rb +17 -5
- metadata +49 -60
- data/test_app/.gitignore +0 -15
- data/test_app/.rspec +0 -1
- data/test_app/Gemfile +0 -14
- data/test_app/Gemfile.lock +0 -140
- data/test_app/README +0 -261
- data/test_app/Rakefile +0 -7
- data/test_app/app/models/.gitkeep +0 -0
- data/test_app/app/models/basket.rb +0 -4
- data/test_app/app/models/fruit.rb +0 -6
- data/test_app/app/models/fruit_basket.rb +0 -4
- data/test_app/app/models/region.rb +0 -3
- data/test_app/app/models/type.rb +0 -2
- data/test_app/config.ru +0 -4
- data/test_app/config/application.rb +0 -52
- data/test_app/config/boot.rb +0 -6
- data/test_app/config/database.yml +0 -42
- data/test_app/config/environment.rb +0 -5
- data/test_app/config/environments/development.rb +0 -30
- data/test_app/config/environments/production.rb +0 -60
- data/test_app/config/environments/test.rb +0 -39
- data/test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test_app/config/initializers/inflections.rb +0 -10
- data/test_app/config/initializers/load_connection_manager.rb +0 -6
- data/test_app/config/initializers/mime_types.rb +0 -5
- data/test_app/config/initializers/secret_token.rb +0 -7
- data/test_app/config/initializers/session_store.rb +0 -8
- data/test_app/config/initializers/wrap_parameters.rb +0 -14
- data/test_app/config/locales/en.yml +0 -5
- data/test_app/config/routes.rb +0 -58
- data/test_app/db/migrate/20111127040654_create_fruits.rb +0 -9
- data/test_app/db/migrate/20111127040720_create_baskets.rb +0 -9
- data/test_app/db/migrate/20111127040846_create_fruit_baskets.rb +0 -9
- data/test_app/db/migrate/20111127040915_create_regions.rb +0 -9
- data/test_app/db/migrate/20111127060322_create_types.rb +0 -9
- data/test_app/db/schema.rb +0 -16
- data/test_app/db/seeds.rb +0 -7
- data/test_app/log/.gitkeep +0 -0
- data/test_app/script/rails +0 -6
- data/test_app/spec/connection_manager/connections_spec.rb +0 -51
- data/test_app/spec/factories/baskets.rb +0 -7
- data/test_app/spec/factories/fruit_baskets.rb +0 -8
- data/test_app/spec/factories/fruits.rb +0 -8
- data/test_app/spec/factories/regions.rb +0 -7
- data/test_app/spec/factories/types.rb +0 -7
- data/test_app/spec/models/type_spec.rb +0 -5
- data/test_app/spec/spec.opts +0 -4
- data/test_app/spec/spec_helper.rb +0 -42
- data/test_app/test_app +0 -0
data/test_app/db/schema.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|
data/test_app/db/seeds.rb
DELETED
@@ -1,7 +0,0 @@
|
|
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)
|
data/test_app/log/.gitkeep
DELETED
File without changes
|
data/test_app/script/rails
DELETED
@@ -1,6 +0,0 @@
|
|
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'
|
@@ -1,51 +0,0 @@
|
|
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
|
-
|
data/test_app/spec/spec.opts
DELETED
@@ -1,42 +0,0 @@
|
|
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
DELETED
Binary file
|