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 +4 -4
- data/CHANGELOG.md +5 -0
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -3
- data/lib/counter_culture/counter.rb +4 -4
- data/lib/counter_culture/reconciler.rb +1 -1
- data/spec/counter_culture_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffba219862c747eb8b00e3b89d29f6306e32c2c2
|
4
|
+
data.tar.gz: 80783eda6b30c56e2d5b203c9ffcd2e92a44056c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b88c26c5646a04a828d59eefdd872c6da43e54242e6db119303809331f8a04095c99c699a3636056277e725b9f83c7f55a1d32c93358e5bc92bd8908e8e0cb
|
7
|
+
data.tar.gz: 1bdba2475e7d09b878b89d5fae4de51f7116aa1326d3ea7eaa3fc3fc9a399683f606b5adf5998ac8f0da7fcc9ae2310299300482d9145c5d2b8cb2cb0349a0e0
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.1
|
data/counter_culture.gemspec
CHANGED
@@ -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.
|
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.
|
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-
|
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.
|
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-
|
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
|