counter_culture 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84e93f1182982eccea8a717da0a95ebb3e4cfef8
4
- data.tar.gz: 87e88e5de74ddf5c23d7df9ff3273ce3f0b17fdf
3
+ metadata.gz: ffba219862c747eb8b00e3b89d29f6306e32c2c2
4
+ data.tar.gz: 80783eda6b30c56e2d5b203c9ffcd2e92a44056c
5
5
  SHA512:
6
- metadata.gz: 0c7286393c38d78c7d59817dfe5dae1c7c05484d3f8c186f3c56b5f0dcaa8c0da3e922aad3395ea94c08cc638536633dfbdd8c3338edf9fd17927eea029ff024
7
- data.tar.gz: 4872ec4223bc8a7ebdc0ca31852e0e7358121dc32f49c8302f744d451b5e32d3a17fcf972dfa8b9cd8be3c21753c2aea38cfec8b2e2fac86ae47cc5a4b1c4079
6
+ metadata.gz: 89b88c26c5646a04a828d59eefdd872c6da43e54242e6db119303809331f8a04095c99c699a3636056277e725b9f83c7f55a1d32c93358e5bc92bd8908e8e0cb
7
+ data.tar.gz: 1bdba2475e7d09b878b89d5fae4de51f7116aa1326d3ea7eaa3fc3fc9a399683f606b5adf5998ac8f0da7fcc9ae2310299300482d9145c5d2b8cb2cb0349a0e0
@@ -1,3 +1,8 @@
1
+ ## 1.5.1 (April 17, 2017)
2
+
3
+ Bugfixes:
4
+ - Support for `nil` values in polymorphic relationships
5
+
1
6
  ## 1.5.0 (March 21, 2017)
2
7
 
3
8
  New features:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.5.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: counter_culture 1.5.0 ruby lib
5
+ # stub: counter_culture 1.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "counter_culture".freeze
9
- s.version = "1.5.0"
9
+ s.version = "1.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Magnus von Koeller".freeze]
14
- s.date = "2017-03-21"
14
+ s.date = "2017-04-17"
15
15
  s.description = "counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback.".freeze
16
16
  s.email = "magnus@vonkoeller.de".freeze
17
17
  s.extra_rdoc_files = [
@@ -125,7 +125,7 @@ module CounterCulture
125
125
  while !value.nil? && relation.size > 0
126
126
  value = value.send(relation.shift)
127
127
  end
128
- return value.try(relation_primary_key(first_relation, source: obj, was: was).to_sym)
128
+ return value.try(relation_primary_key(first_relation, source: obj, was: was).try(:to_sym))
129
129
  end
130
130
 
131
131
  # gets the reflect object on the given relation
@@ -171,9 +171,9 @@ module CounterCulture
171
171
  type_column = reflect.foreign_type.to_sym
172
172
  # so now turn that into the class that we're looking for here
173
173
  if was
174
- attribute_was(source, type_column).constantize
174
+ attribute_was(source, type_column).try(:constantize)
175
175
  else
176
- source.public_send(type_column).constantize
176
+ source.public_send(type_column).try(:constantize)
177
177
  end
178
178
  else
179
179
  reflect.klass
@@ -227,7 +227,7 @@ module CounterCulture
227
227
  if reflect.options.key?(:polymorphic)
228
228
  raise "can't handle multiple keys with polymorphic associations" unless (relation.is_a?(Symbol) || relation.length == 1)
229
229
  raise "must specify source for polymorphic associations..." unless source
230
- return relation_klass(relation, source: source, was: was).primary_key
230
+ return relation_klass(relation, source: source, was: was).try(:primary_key)
231
231
  end
232
232
  reflect.association_primary_key(klass)
233
233
  end
@@ -45,7 +45,7 @@ module CounterCulture
45
45
 
46
46
  def polymorphic_associated_model_classes
47
47
  foreign_type_field = relation_reflect(relation).foreign_type
48
- model.pluck("DISTINCT #{foreign_type_field}").map(&:constantize)
48
+ model.pluck("DISTINCT #{foreign_type_field}").compact.map(&:constantize)
49
49
  end
50
50
 
51
51
  def associated_model_class
@@ -1643,6 +1643,26 @@ describe "CounterCulture" do
1643
1643
  expect(product1.reload.poly_images_count).to eq(1)
1644
1644
  expect(employee.reload.poly_images_count).to eq(2)
1645
1645
  end
1646
+
1647
+ it "can handle nil values" do
1648
+ img = PolyImage.create(imageable: employee)
1649
+ PolyImage.create(imageable: nil)
1650
+ mess_up_counts
1651
+
1652
+ PolyImage.counter_culture_fix_counts
1653
+
1654
+ expect(employee.reload.poly_images_count).to eq(1)
1655
+
1656
+ img.imageable = nil
1657
+ img.save!
1658
+
1659
+ expect(employee.reload.poly_images_count).to eq(0)
1660
+
1661
+ img.imageable = employee
1662
+ img.save!
1663
+
1664
+ expect(employee.reload.poly_images_count).to eq(1)
1665
+ end
1646
1666
  end
1647
1667
  describe "custom column name" do
1648
1668
  it "increments counter cache on create" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: after_commit_action