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.
Files changed (67) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +1 -0
  3. data/Gemfile.lock +8 -3
  4. data/README.md +26 -26
  5. data/connection_manager.gemspec +2 -0
  6. data/lib/connection_manager.rb +1 -0
  7. data/lib/connection_manager/connections.rb +34 -25
  8. data/lib/connection_manager/replication_builder.rb +11 -12
  9. data/lib/connection_manager/version.rb +1 -1
  10. data/spec/database.yml +20 -0
  11. data/spec/factories.rb +31 -0
  12. data/spec/helpers/database_spec_helper.rb +68 -0
  13. data/spec/helpers/models_spec_helper.rb +26 -0
  14. data/spec/integration/replication_builder_spec.rb +97 -0
  15. data/{test_app/spec/connection_manager → spec/lib}/associations_spec.rb +0 -0
  16. data/spec/lib/connections_spec.rb +93 -0
  17. data/{test_app/spec/connection_manager → spec/lib}/replication_builder_spec.rb +17 -1
  18. data/spec/spec_helper.rb +17 -5
  19. metadata +49 -60
  20. data/test_app/.gitignore +0 -15
  21. data/test_app/.rspec +0 -1
  22. data/test_app/Gemfile +0 -14
  23. data/test_app/Gemfile.lock +0 -140
  24. data/test_app/README +0 -261
  25. data/test_app/Rakefile +0 -7
  26. data/test_app/app/models/.gitkeep +0 -0
  27. data/test_app/app/models/basket.rb +0 -4
  28. data/test_app/app/models/fruit.rb +0 -6
  29. data/test_app/app/models/fruit_basket.rb +0 -4
  30. data/test_app/app/models/region.rb +0 -3
  31. data/test_app/app/models/type.rb +0 -2
  32. data/test_app/config.ru +0 -4
  33. data/test_app/config/application.rb +0 -52
  34. data/test_app/config/boot.rb +0 -6
  35. data/test_app/config/database.yml +0 -42
  36. data/test_app/config/environment.rb +0 -5
  37. data/test_app/config/environments/development.rb +0 -30
  38. data/test_app/config/environments/production.rb +0 -60
  39. data/test_app/config/environments/test.rb +0 -39
  40. data/test_app/config/initializers/backtrace_silencers.rb +0 -7
  41. data/test_app/config/initializers/inflections.rb +0 -10
  42. data/test_app/config/initializers/load_connection_manager.rb +0 -6
  43. data/test_app/config/initializers/mime_types.rb +0 -5
  44. data/test_app/config/initializers/secret_token.rb +0 -7
  45. data/test_app/config/initializers/session_store.rb +0 -8
  46. data/test_app/config/initializers/wrap_parameters.rb +0 -14
  47. data/test_app/config/locales/en.yml +0 -5
  48. data/test_app/config/routes.rb +0 -58
  49. data/test_app/db/migrate/20111127040654_create_fruits.rb +0 -9
  50. data/test_app/db/migrate/20111127040720_create_baskets.rb +0 -9
  51. data/test_app/db/migrate/20111127040846_create_fruit_baskets.rb +0 -9
  52. data/test_app/db/migrate/20111127040915_create_regions.rb +0 -9
  53. data/test_app/db/migrate/20111127060322_create_types.rb +0 -9
  54. data/test_app/db/schema.rb +0 -16
  55. data/test_app/db/seeds.rb +0 -7
  56. data/test_app/log/.gitkeep +0 -0
  57. data/test_app/script/rails +0 -6
  58. data/test_app/spec/connection_manager/connections_spec.rb +0 -51
  59. data/test_app/spec/factories/baskets.rb +0 -7
  60. data/test_app/spec/factories/fruit_baskets.rb +0 -8
  61. data/test_app/spec/factories/fruits.rb +0 -8
  62. data/test_app/spec/factories/regions.rb +0 -7
  63. data/test_app/spec/factories/types.rb +0 -7
  64. data/test_app/spec/models/type_spec.rb +0 -5
  65. data/test_app/spec/spec.opts +0 -4
  66. data/test_app/spec/spec_helper.rb +0 -42
  67. data/test_app/test_app +0 -0
@@ -1,9 +0,0 @@
1
- class CreateRegions < ActiveRecord::Migration
2
- def change
3
- create_table :regions do |t|
4
- t.string :name
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class CreateTypes < ActiveRecord::Migration
2
- def change
3
- create_table :types do |t|
4
- t.string :name
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -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)
File without changes
@@ -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
-
@@ -1,7 +0,0 @@
1
- # Read about factories at http://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :basket do
5
- name "MyString"
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- # Read about factories at http://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :fruit_basket do
5
- fruit
6
- basket
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # Read about factories at http://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :fruit do
5
- name "MyString"
6
- region
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- # Read about factories at http://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :region do
5
- name "MyString"
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # Read about factories at http://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :type do
5
- name "MyString"
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Type do
4
- pending "add some examples to (or delete) #{__FILE__}"
5
- end
@@ -1,4 +0,0 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse
@@ -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