activerecord-turntable 3.0.0.alpha1 → 3.0.0.alpha2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af3117e04f949c697cf878879a85c2205f7e19b6
4
- data.tar.gz: 5437cc1aec6b98bb507639d81e9687eac526d8d1
3
+ metadata.gz: ab82abdd16e36a30d5c3b55f5cb5ff61d7142dcd
4
+ data.tar.gz: 4ece75789087ee54b31484601390ed16392aca31
5
5
  SHA512:
6
- metadata.gz: 039ffd448816f9792c8fb29fb7844e08ab0c1ea7227367158810dc718d580ee047922d1e23117875611e3d606d6a1b3a3494d732e962dc84e774a0755240a8bd
7
- data.tar.gz: 939620c1056efc1b1f843dc348c5420ea811c87987a5149565b8049ed488689f4b224c28c962316b201c58cd33ebdba0cdf85ee42fb7623225561091ce1275a9
6
+ metadata.gz: f11dca6559d5539c44cf82d863e88acb793eace6fc527d1fe900d8c424fc3f633615242eebd9e86c7977b92b05cb64e0e2f799826e19c12fc13ac84165fac13d
7
+ data.tar.gz: 250ab4d9806440953e10acb8f7b94a6b0fc564f54859e8f6c99e69396c598246b1d85f6a0193d76e4555ef366baee651091740733948808c1f6111c259568e4c
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- - 2.3.1
3
+ - 2.2.6
4
+ - 2.3.3
5
5
  - ruby-head
6
6
  gemfile:
7
7
  - gemfiles/rails5_0.gemfile
data/CHANGELOG.md CHANGED
@@ -1,10 +1,17 @@
1
- ## activerecord-turntable 3.0.0.alpha (unreleased) ##
1
+ ## activerecord-turntable 3.0.0.alpha2 ##
2
+
3
+ ### Improvement
4
+
5
+ * Fix to propagate shard conditions to `AssociationRelation` too
6
+
7
+ ## activerecord-turntable 3.0.0.alpha1 ##
8
+
9
+ ### Major Changes
2
10
 
3
11
  * Rails5 compatibility
4
12
  * Minimum ruby requirement version is `2.2.2`
5
13
  * Rails 4.x support has been dropped.
6
14
 
7
-
8
15
  ## activerecord-turntable 2.3.3 ##
9
16
 
10
17
  ### Bugfix
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "activerecord", "5.0.0.1"
6
- gem "activesupport", "5.0.0.1"
5
+ gem "activerecord", "~> 5.0.1"
6
+ gem "activesupport", "~> 5.0.1"
@@ -43,7 +43,7 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency "pry-byebug"
44
44
  spec.add_development_dependency "rack"
45
45
  spec.add_development_dependency "rake"
46
- spec.add_development_dependency "rspec", "~> 3.1.0"
46
+ spec.add_development_dependency "rspec", "~> 3.5.0"
47
47
  spec.add_development_dependency "rspec-collection_matchers"
48
48
  spec.add_development_dependency "rspec-its"
49
49
  spec.add_development_dependency "rubocop"
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "5.0.0.1"
4
- gem "activesupport", "5.0.0.1"
3
+ gem "activerecord", "5.0.1"
4
+ gem "activesupport", "5.0.1"
5
5
 
6
6
  gemspec :path => '../'
@@ -30,7 +30,7 @@ module ActiveRecord::Turntable
30
30
  ActiveRecord::Migration.include(ActiveRecord::Turntable::Migration)
31
31
  ActiveRecord::ConnectionAdapters::ConnectionHandler.prepend(ConnectionHandlerExtension)
32
32
  ActiveRecord::Associations::Preloader::Association.prepend(AssociationPreloader)
33
- ActiveRecord::Associations::Association.include(Association)
33
+ ActiveRecord::Associations::Association.prepend(Association)
34
34
  require "active_record/turntable/active_record_ext/fixtures"
35
35
  require "active_record/turntable/active_record_ext/migration_proxy"
36
36
  require "active_record/turntable/active_record_ext/activerecord_import_ext"
@@ -3,49 +3,24 @@ require "active_record/associations"
3
3
  module ActiveRecord::Turntable
4
4
  module ActiveRecordExt
5
5
  module Association
6
- extend ActiveSupport::Concern
7
6
  include ShardingCondition
8
7
 
9
- included do
10
- ActiveRecord::Associations::SingularAssociation.prepend(SingularAssociationExt)
11
- ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociationExt)
8
+ def self.prepended(mod)
12
9
  ActiveRecord::Associations::Builder::Association::VALID_OPTIONS << :foreign_shard_key
13
10
  end
14
11
 
15
- # @note Inject to add sharding condition for singular association
16
- module SingularAssociationExt
17
- private
18
- def get_records
19
- # OPTIMIZE: statement caching
20
- if should_use_shard_key?
21
- return turntable_scope(scope).limit(1).records
22
- end
12
+ protected
23
13
 
24
- super
25
- end
26
- end
27
-
28
- # @note Inject to add sharding condition for collection association
29
- module CollectionAssociationExt
30
- private
31
- def get_records
32
- # OPTIMIZE: statement caching
33
- if should_use_shard_key?
34
- return turntable_scope(scope).to_a
35
- end
14
+ # @note Override to pass shard key conditions
15
+ def target_scope
16
+ return super unless should_use_shard_key?
36
17
 
37
- super
38
- end
18
+ scope = klass.where(
19
+ klass.turntable_shard_key =>
20
+ owner.send(foreign_shard_key)
21
+ )
22
+ super.merge!(scope)
39
23
  end
40
-
41
- private
42
-
43
- def turntable_scope(scope, bind = nil)
44
- if should_use_shard_key?
45
- scope = scope.where(klass.turntable_shard_key => owner.send(foreign_shard_key))
46
- end
47
- scope
48
- end
49
24
  end
50
25
  end
51
26
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Turntable
3
- VERSION = "3.0.0.alpha1".freeze
3
+ VERSION = "3.0.0.alpha2".freeze
4
4
  end
5
5
  end
@@ -47,11 +47,20 @@ describe ActiveRecord::Turntable::ActiveRecordExt::Association do
47
47
  ActiveRecord::Base.turntable_config.instance_variable_get(:@config)[:raise_on_not_specified_shard_query] = true
48
48
  end
49
49
  let(:cards_user) { CardsUser.where(user: user).first }
50
+ let(:cards_users_history) { cards_users_histories.find { |history| history.user_id == user.id } }
50
51
 
51
52
  context "associated objects has same turntable_key" do
52
- subject { cards_user.cards_users_histories.to_a }
53
- it { expect { subject }.to_not raise_error }
54
- it { is_expected.to include(*cards_users_histories.select { |history| history.cards_user_id == cards_user.id }) }
53
+ context "AssociationRelation#to_a" do
54
+ subject { cards_user.cards_users_histories.to_a }
55
+ it { expect { subject }.to_not raise_error }
56
+ it { is_expected.to include(*cards_users_histories.select { |history| history.cards_user_id == cards_user.id }) }
57
+ end
58
+
59
+ context "AssociationRelation#where" do
60
+ subject { cards_user.cards_users_histories.where(id: cards_users_history.id).to_a }
61
+ it { expect { subject }.to_not raise_error }
62
+ it { is_expected.to include(cards_users_history) }
63
+ end
55
64
  end
56
65
 
57
66
  context "associated objects has different turntable_key" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha1
4
+ version: 3.0.0.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-13 00:00:00.000000000 Z
12
+ date: 2017-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -281,14 +281,14 @@ dependencies:
281
281
  requirements:
282
282
  - - "~>"
283
283
  - !ruby/object:Gem::Version
284
- version: 3.1.0
284
+ version: 3.5.0
285
285
  type: :development
286
286
  prerelease: false
287
287
  version_requirements: !ruby/object:Gem::Requirement
288
288
  requirements:
289
289
  - - "~>"
290
290
  - !ruby/object:Gem::Version
291
- version: 3.1.0
291
+ version: 3.5.0
292
292
  - !ruby/object:Gem::Dependency
293
293
  name: rspec-collection_matchers
294
294
  requirement: !ruby/object:Gem::Requirement
@@ -526,7 +526,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
526
526
  version: 1.3.1
527
527
  requirements: []
528
528
  rubyforge_project: activerecord-turntable
529
- rubygems_version: 2.5.1
529
+ rubygems_version: 2.5.2
530
530
  signing_key:
531
531
  specification_version: 4
532
532
  summary: ActiveRecord sharding extension