seamless_database_pool 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -278,12 +278,12 @@ module ActiveRecord
278
278
  available = @available_read_connections.last
279
279
  if available.expired?
280
280
  begin
281
- @logger.info("Adding dead database connection back to the pool: #{available.inspect}") if @logger
281
+ @logger.info("Adding dead database connection back to the pool") if @logger
282
282
  available.reconnect!
283
283
  rescue => e
284
284
  # Couldn't reconnect so try again in a little bit
285
285
  if @logger
286
- @logger.warn("Failed to reconnect with: #{available.inspect}")
286
+ @logger.warn("Failed to reconnect to database when adding connection back to the pool")
287
287
  @logger.warn(e)
288
288
  end
289
289
  available.expires = 30.seconds.from_now
@@ -14,7 +14,6 @@ describe "Test connection adapters" do
14
14
 
15
15
  before(:all) do
16
16
  ActiveRecord::Base.establish_connection('adapter' => "sqlite3", 'database' => ":memory:")
17
- model.use_database_connection(adapter)
18
17
  model.create_tables
19
18
  end
20
19
 
@@ -143,7 +142,7 @@ describe "Test connection adapters" do
143
142
 
144
143
  it "should send tables to the read connection" do
145
144
  results = connection.tables
146
- results.should == ["test_models"]
145
+ results.should == [model.table_name]
147
146
  results.should == master_connection.tables
148
147
  results.should be_read_only
149
148
  end
@@ -205,6 +204,23 @@ describe "Test connection adapters" do
205
204
  end
206
205
  end
207
206
  end
207
+
208
+ it "should properly dump the schema" do
209
+ schema = <<-EOS
210
+ ActiveRecord::Schema.define(:version => 0) do
211
+ create_table "#{model.table_name}", :force => true do |t|
212
+ t.string "name"
213
+ t.integer "value"
214
+ end
215
+ end
216
+ EOS
217
+ schema = schema.gsub(/^ +/, '').gsub(/ +/, ' ').strip
218
+
219
+ io = StringIO.new
220
+ ActiveRecord::SchemaDumper.dump(connection, io)
221
+ generated_schema = io.string.gsub(/^#.*$/, '').gsub(/\n+/, "\n").gsub(/^ +/, '').gsub(/ +/, ' ').strip
222
+ generated_schema.should == schema
223
+ end
208
224
  end
209
225
  end
210
226
  end
data/spec/database.yml CHANGED
@@ -27,6 +27,8 @@ postgresql:
27
27
  mysql:
28
28
  adapter: seamless_database_pool
29
29
  database: seamless_database_pool_test
30
+ username: root
31
+ password:
30
32
  master:
31
33
  adapter: mysql
32
34
  pool_weight: 0
data/spec/test_model.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module SeamlessDatabasePool
2
2
  class TestModel < ActiveRecord::Base
3
+ self.abstract_class = true
4
+
3
5
  class << self
4
6
  def database_configs
5
7
  adapters = ENV['TEST_ADAPTERS'].blank? ? [] : ENV['TEST_ADAPTERS'].split(/\s+/)
@@ -15,10 +17,12 @@ module SeamlessDatabasePool
15
17
  end
16
18
 
17
19
  def db_model(db_name)
18
- model_class_name = db_name.classify
20
+ model_class_name = "#{db_name.classify}TestModel"
19
21
  unless const_defined?(model_class_name)
20
22
  klass = Class.new(self)
21
23
  const_set(model_class_name, klass)
24
+ klass = const_get(model_class_name)
25
+ klass.use_database_connection(db_name)
22
26
  end
23
27
  const_get(model_class_name)
24
28
  end
@@ -28,10 +32,14 @@ module SeamlessDatabasePool
28
32
  t.column :name, :string
29
33
  t.column :value, :integer
30
34
  end unless table_exists?
35
+ connection.clear_cache!
36
+ undefine_attribute_methods
31
37
  end
32
38
 
33
39
  def drop_tables
34
40
  connection.drop_table(table_name)
41
+ connection.clear_cache!
42
+ undefine_attribute_methods
35
43
  end
36
44
 
37
45
  def cleanup_database!
metadata CHANGED
@@ -1,94 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: seamless_database_pool
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.12
4
5
  prerelease:
5
- version: 1.0.11
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Brian Durand
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-11-21 00:00:00 -06:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: activerecord
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70158253976860 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 2.2.2
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70158253976860
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70158253974440 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "2.0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: jeweler
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70158253974440
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &70158253971880 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
47
44
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: sqlite3
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70158253971880
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: &70158253970680 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
58
55
  type: :development
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: mysql
62
56
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70158253970680
58
+ - !ruby/object:Gem::Dependency
59
+ name: mysql
60
+ requirement: &70158253960160 !ruby/object:Gem::Requirement
64
61
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
69
66
  type: :development
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
72
- name: pg
73
67
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *70158253960160
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: &70158253958100 !ruby/object:Gem::Requirement
75
72
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
80
77
  type: :development
81
- version_requirements: *id006
78
+ prerelease: false
79
+ version_requirements: *70158253958100
82
80
  description:
83
81
  email: brian@embellishedvisions.com
84
82
  executables: []
85
-
86
83
  extensions: []
87
-
88
- extra_rdoc_files:
84
+ extra_rdoc_files:
89
85
  - MIT-LICENSE
90
86
  - README.rdoc
91
- files:
87
+ files:
92
88
  - MIT-LICENSE
93
89
  - README.rdoc
94
90
  - Rakefile
@@ -107,40 +103,29 @@ files:
107
103
  - spec/spec_helper.rb
108
104
  - spec/test_adapter/active_record/connection_adapters/read_only_adapter.rb
109
105
  - spec/test_model.rb
110
- has_rdoc: true
111
106
  homepage: http://github.com/bdurand/seamless_database_pool
112
107
  licenses: []
113
-
114
108
  post_install_message:
115
109
  rdoc_options: []
116
-
117
- require_paths:
110
+ require_paths:
118
111
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
112
+ required_ruby_version: !ruby/object:Gem::Requirement
120
113
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
119
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: "0"
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
131
124
  requirements: []
132
-
133
125
  rubyforge_project:
134
- rubygems_version: 1.6.2
126
+ rubygems_version: 1.8.11
135
127
  signing_key:
136
128
  specification_version: 3
137
- summary: Add support for master/slave database clusters in ActiveRecord to improve performance.
138
- test_files:
139
- - spec/connection_adapters_spec.rb
140
- - spec/connection_statistics_spec.rb
141
- - spec/controller_filter_spec.rb
142
- - spec/seamless_database_pool_adapter_spec.rb
143
- - spec/seamless_database_pool_spec.rb
144
- - spec/spec_helper.rb
145
- - spec/test_adapter/active_record/connection_adapters/read_only_adapter.rb
146
- - spec/test_model.rb
129
+ summary: Add support for master/slave database clusters in ActiveRecord to improve
130
+ performance.
131
+ test_files: []