active_record_shards 2.6.5 → 2.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -96,3 +96,6 @@ Copyright (c) 2011 Zendesk. See LICENSE for details.
96
96
 
97
97
  ## Authors
98
98
  Mick Staugaard, Eric Chapweske
99
+
100
+ [![Build Status](https://secure.travis-ci.org/osheroff/active_record_shards.png)](http://travis-ci.org/osheroff/active_record_shards)
101
+
@@ -33,7 +33,7 @@ module ActiveRecordShards
33
33
  def method_missing(method, *args, &block)
34
34
  # would love to not rely on version here, unfortunately @association_collection
35
35
  # is a sensitive little bitch of an object.
36
- if ActiveRecord::VERSION::MAJOR >= 3
36
+ if ActiveRecord::VERSION::STRING >= "3.1.0"
37
37
  reflection = @association_collection.proxy_association.reflection
38
38
  else
39
39
  reflection = @association_collection.proxy_reflection
@@ -39,3 +39,18 @@ ActiveRecord::Base.singleton_class.class_eval do
39
39
  end
40
40
  alias_method_chain :establish_connection, :connection_pool_name
41
41
  end
42
+
43
+ # backport improved connection fetching from rails 3.2
44
+ if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
45
+ class ActiveRecord::Base
46
+ def self.arel_engine
47
+ @arel_engine ||= begin
48
+ if self == ActiveRecord::Base
49
+ ActiveRecord::Base
50
+ else
51
+ connection_handler.retrieve_connection_pool(self) ? self : superclass.arel_engine
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -91,10 +91,10 @@ module ActiveRecordShards
91
91
  @disallow_slave = (@disallow_slave || 0) + 1 if which == :master
92
92
 
93
93
  # setting read-only scope on ActiveRecord::Base never made any sense, anyway
94
- if self == ActiveRecord::Base
94
+ if self == ActiveRecord::Base || !switch_to_slave
95
95
  yield
96
96
  else
97
- with_scope({:find => {:readonly => on_slave?}}, :merge, &block)
97
+ with_scope({:find => {:readonly => true}}, &block)
98
98
  end
99
99
  ensure
100
100
  @disallow_slave -= 1 if which == :master
@@ -177,7 +177,7 @@ module ActiveRecordShards
177
177
  end
178
178
 
179
179
  def connection_pool_key
180
- if ActiveRecord::VERSION::MAJOR >= 3
180
+ if ActiveRecord::VERSION::STRING >= "3.1.0"
181
181
  specification_cache[connection_pool_name]
182
182
  else
183
183
  connection_pool_name
@@ -95,7 +95,7 @@ end
95
95
  ActiveRecord::Migration.class_eval do
96
96
  extend ActiveRecordShards::MigrationClassExtension
97
97
 
98
- if ActiveRecord::VERSION::MAJOR >= 3
98
+ if ActiveRecord::VERSION::STRING >= "3.1.0"
99
99
  include ActiveRecordShards::ActualMigrationExtension
100
100
  define_method :migration_shard do
101
101
  self.class.migration_shard
@@ -9,7 +9,7 @@ require 'active_record_shards/connection_pool'
9
9
  require 'active_record_shards/migration'
10
10
  require 'active_record_shards/default_slave_patches'
11
11
 
12
- if ActiveRecord::VERSION::MAJOR >= 3 && ActiveRecord::VERSION::MINOR >= 2
12
+ if ActiveRecord::VERSION::STRING >= "3.2.0"
13
13
  require 'active_record_shards/connection_specification'
14
14
  end
15
15
 
@@ -18,7 +18,7 @@ ActiveRecord::Base.extend(ActiveRecordShards::Model)
18
18
  ActiveRecord::Base.extend(ActiveRecordShards::ConnectionSwitcher)
19
19
  ActiveRecord::Base.extend(ActiveRecordShards::DefaultSlavePatches)
20
20
 
21
- if ActiveRecord::VERSION::MAJOR >= 3 && ActiveRecord::VERSION::MINOR >= 1
21
+ if ActiveRecord::VERSION::STRING >= "3.1.0"
22
22
  ActiveRecord::Associations::CollectionProxy.send(:include, ActiveRecordShards::AssociationCollectionConnectionSelection)
23
23
  else
24
24
  ActiveRecord::Associations::AssociationCollection.send(:include, ActiveRecordShards::AssociationCollectionConnectionSelection)
@@ -186,6 +186,16 @@ class ConnectionSwitchingTest < ActiveSupport::TestCase
186
186
  assert_using_database('ars_test', Ticket)
187
187
  end
188
188
 
189
+ if ActiveRecord::VERSION::MAJOR >= 3
190
+ should "be able to find by column" do
191
+ Account.where(:name => "peter").to_sql # does not blow up
192
+ end
193
+
194
+ should "have correct engine" do
195
+ assert_equal Account, Account.arel_engine
196
+ end
197
+ end
198
+
189
199
  context "shard switching" do
190
200
  should "just stay on the main db" do
191
201
  assert_using_database('ars_test2', Ticket)
@@ -320,6 +330,19 @@ class ConnectionSwitchingTest < ActiveSupport::TestCase
320
330
  assert_equal('master_name', @model.name)
321
331
  end
322
332
 
333
+ # TODO mocha raises stack level too deep on ActiveRecord 3.2+
334
+ if ActiveRecord::VERSION::STRING < "3.2.0"
335
+ should "not unnecessary call with_scope" do
336
+ Account.expects(:with_scope).never
337
+ Account.on_master.first
338
+ end
339
+ end
340
+
341
+ should "not unset readonly" do
342
+ @model = Account.on_master.scoped(:readonly => true).first
343
+ assert(@model.readonly?)
344
+ end
345
+
323
346
  should "not be marked as read only" do
324
347
  assert(!@model.readonly?)
325
348
  end
data/test/schema.rb CHANGED
@@ -1,6 +1,4 @@
1
- old_stdout = $stdout.clone
2
- devnull = File.open("/dev/null", "w+")
3
- $stdout.reopen(devnull)
1
+ ActiveRecord::Migration.verbose = false
4
2
 
5
3
  ActiveRecord::Schema.define(:version => 1) do
6
4
  create_table "accounts", :force => true do |t|
@@ -24,5 +22,3 @@ ActiveRecord::Schema.define(:version => 1) do
24
22
  t.datetime "updated_at"
25
23
  end
26
24
  end
27
-
28
- $stdout.reopen(old_stdout)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.5
4
+ version: 2.6.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-06-18 00:00:00.000000000 Z
14
+ date: 2013-01-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord
@@ -163,6 +163,22 @@ dependencies:
163
163
  - - ! '>='
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
+ - !ruby/object:Gem::Dependency
167
+ name: test-unit
168
+ requirement: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 2.5.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: 2.5.1
166
182
  - !ruby/object:Gem::Dependency
167
183
  name: debugger
168
184
  requirement: !ruby/object:Gem::Requirement
@@ -226,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
242
  version: '0'
227
243
  segments:
228
244
  - 0
229
- hash: 1805531677850049369
245
+ hash: -1200466778001401541
230
246
  required_rubygems_version: !ruby/object:Gem::Requirement
231
247
  none: false
232
248
  requirements:
@@ -235,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
251
  version: '0'
236
252
  segments:
237
253
  - 0
238
- hash: 1805531677850049369
254
+ hash: -1200466778001401541
239
255
  requirements: []
240
256
  rubyforge_project:
241
257
  rubygems_version: 1.8.24