counter_culture 2.1.2 → 2.1.3

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
  SHA256:
3
- metadata.gz: c7959919b657fa78f0411dfbab1d943126a56299845d675153cbc22b14dd379f
4
- data.tar.gz: 478dd534275fa4b591c27dfee2430cd3ca0b51230ef1761ac65b29d9e457cb71
3
+ metadata.gz: 0beff678fd83c3d1dd16c6f9d2b3104bc5b7fd4e3f53fe916071df4c3a7fd0d5
4
+ data.tar.gz: df317d7031cc176137898bf0cc7fe9e8b74d469752b4497b404f9e799a5efae7
5
5
  SHA512:
6
- metadata.gz: 82971d075ad62b51f70648e7fb00dc8b3be73bbe5243d7aea5bf341f0f4d9a33c2b34ec6e205c196069f6eb32d3e1dea85f9f7197278c9f769d426d095aa85dc
7
- data.tar.gz: fec145c1cf38738c96c0a6e78bb67ca596813acb97fa16e7ee1e5265db3ddc567e6484ad812f35917f2d310e9a9f4a5bece98fd4f5fc4018e6e28d31a970ded7
6
+ metadata.gz: ae81d2fa63abcac9f46af293eb22be9b618345a3a9c8c4be337fab683f15506573c4b392d2c32258b58217684e5f7efad6c1562b484c23ae8fbd76b10282d2fc
7
+ data.tar.gz: 7e916af1fef3cdb9a445332e6f172d421d5a104a4e086c848375109fb3303e55916a02068f2501ae2feb3a657f3335561a5273b87b3ce159031c14ad34cd5d26
@@ -32,6 +32,9 @@ matrix:
32
32
  env: 'RAILS_VERSION="~> 4.0.0"'
33
33
  - rvm: "2.5.1"
34
34
  env: 'RAILS_VERSION="~> 4.1.0"'
35
+ before_install:
36
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
37
+ - gem install bundler -v '< 2'
35
38
  install:
36
39
  - bundle update
37
40
  script: TRAVIS=true bundle exec rake spec
@@ -1,3 +1,8 @@
1
+ ## 2.1.3 (January 19, 2019)
2
+
3
+ Bugfixes:
4
+ - Don't update running total on soft-deleted records (#244)
5
+
1
6
  ## 2.1.2 (December 7, 2018)
2
7
 
3
8
  Bugfixes:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.1.3
@@ -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 2.1.2 ruby lib
5
+ # stub: counter_culture 2.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "counter_culture".freeze
9
- s.version = "2.1.2"
9
+ s.version = "2.1.3"
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 = "2018-12-07"
14
+ s.date = "2019-01-19"
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 = [
@@ -20,15 +20,7 @@ module CounterCulture
20
20
  # initialize callbacks only once
21
21
  after_create :_update_counts_after_create
22
22
 
23
- before_destroy :_update_counts_after_destroy, if: -> (model) do
24
- if model.respond_to?(:paranoia_destroyed?)
25
- !model.paranoia_destroyed?
26
- elsif defined?(Discard::Model) && model.class.include?(Discard::Model)
27
- !model.discarded?
28
- else
29
- true
30
- end
31
- end
23
+ before_destroy :_update_counts_after_destroy, unless: :destroyed_for_counter_culture?
32
24
 
33
25
  if respond_to?(:before_real_destroy) &&
34
26
  new.respond_to?(:paranoia_destroyed?)
@@ -36,7 +28,7 @@ module CounterCulture
36
28
  if: -> (model) { !model.paranoia_destroyed? }
37
29
  end
38
30
 
39
- after_update :_update_counts_after_update
31
+ after_update :_update_counts_after_update, unless: :destroyed_for_counter_culture?
40
32
 
41
33
  if respond_to?(:before_restore)
42
34
  before_restore :_update_counts_after_create,
@@ -133,5 +125,16 @@ module CounterCulture
133
125
  end
134
126
  end
135
127
 
128
+ # check if record is soft-deleted
129
+ def destroyed_for_counter_culture?
130
+ if respond_to?(:paranoia_destroyed?)
131
+ paranoia_destroyed?
132
+ elsif defined?(Discard::Model) && self.class.include?(Discard::Model)
133
+ discarded?
134
+ else
135
+ false
136
+ end
137
+ end
138
+
136
139
  end
137
140
  end
@@ -1813,6 +1813,39 @@ describe "CounterCulture" do
1813
1813
  expect(company.reload.soft_delete_discards_count).to eq(0)
1814
1814
  end
1815
1815
  end
1816
+
1817
+ describe "dynamic column names with totaling instead of counting" do
1818
+ describe 'when updating discarded records' do
1819
+ it 'does not update sum' do
1820
+ skip("Unsupported in this version of Rails") if Rails.version < "4.2.0"
1821
+
1822
+ company = Company.create!
1823
+ sd = SoftDeleteDiscard.create!(company_id: company.id, value: 5)
1824
+
1825
+ expect(company.reload.soft_delete_discard_values_sum).to eq(5)
1826
+
1827
+ sd.discard
1828
+ expect(company.reload.soft_delete_discard_values_sum).to eq(0)
1829
+
1830
+ sd.update value: 10
1831
+ expect(company.reload.soft_delete_discard_values_sum).to eq(0)
1832
+ end
1833
+ end
1834
+
1835
+ describe 'when updating undiscarded records' do
1836
+ it 'updates sum' do
1837
+ skip("Unsupported in this version of Rails") if Rails.version < "4.2.0"
1838
+
1839
+ company = Company.create!
1840
+ sd = SoftDeleteDiscard.create!(company_id: company.id, value: 5)
1841
+
1842
+ expect(company.reload.soft_delete_discard_values_sum).to eq(5)
1843
+
1844
+ sd.update value: 10
1845
+ expect(company.reload.soft_delete_discard_values_sum).to eq(10)
1846
+ end
1847
+ end
1848
+ end
1816
1849
  end
1817
1850
 
1818
1851
  describe "when using paranoia for soft deletes" do
@@ -1898,6 +1931,39 @@ describe "CounterCulture" do
1898
1931
  expect(company.reload.soft_delete_paranoia_count).to eq(0)
1899
1932
  end
1900
1933
  end
1934
+
1935
+ describe "dynamic column names with totaling instead of counting" do
1936
+ describe 'when updating soft deleted records' do
1937
+ it 'does not update sum' do
1938
+ skip("Unsupported in this version of Rails") if Rails.version < "4.2.0"
1939
+
1940
+ company = Company.create!
1941
+ sd = SoftDeleteParanoia.create!(company_id: company.id, value: 5)
1942
+
1943
+ expect(company.reload.soft_delete_paranoia_values_sum).to eq(5)
1944
+
1945
+ sd.destroy
1946
+ expect(company.reload.soft_delete_paranoia_values_sum).to eq(0)
1947
+
1948
+ sd.update value: 10
1949
+ expect(company.reload.soft_delete_paranoia_values_sum).to eq(0)
1950
+ end
1951
+ end
1952
+
1953
+ describe 'when updating undestroyed records' do
1954
+ it 'updates sum' do
1955
+ skip("Unsupported in this version of Rails") if Rails.version < "4.2.0"
1956
+
1957
+ company = Company.create!
1958
+ sd = SoftDeleteParanoia.create!(company_id: company.id, value: 5)
1959
+
1960
+ expect(company.reload.soft_delete_paranoia_values_sum).to eq(5)
1961
+
1962
+ sd.update value: 10
1963
+ expect(company.reload.soft_delete_paranoia_values_sum).to eq(10)
1964
+ end
1965
+ end
1966
+ end
1901
1967
  end
1902
1968
 
1903
1969
  describe "with polymorphic_associations" do
@@ -3,4 +3,5 @@ class SoftDeleteDiscard < ActiveRecord::Base
3
3
 
4
4
  belongs_to :company
5
5
  counter_culture :company
6
+ counter_culture :company, column_name: 'soft_delete_discard_values_sum', delta_column: 'value'
6
7
  end
@@ -3,4 +3,5 @@ class SoftDeleteParanoia < ActiveRecord::Base
3
3
 
4
4
  belongs_to :company
5
5
  counter_culture :company
6
+ counter_culture :company, column_name: 'soft_delete_paranoia_values_sum', delta_column: 'value'
6
7
  end
@@ -25,7 +25,9 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
25
25
  t.integer "parent_id"
26
26
  t.integer "children_count", :default => 0, :null => false
27
27
  t.integer "soft_delete_paranoia_count", :default => 0, :null => false
28
+ t.integer "soft_delete_paranoia_values_sum", :default => 0, :null => false
28
29
  t.integer "soft_delete_discards_count", :default => 0, :null => false
30
+ t.integer "soft_delete_discard_values_sum", :default => 0, :null => false
29
31
  t.datetime "created_at"
30
32
  t.datetime "updated_at"
31
33
  end
@@ -179,11 +181,13 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
179
181
 
180
182
  create_table "soft_delete_paranoia", :force => true do |t|
181
183
  t.integer "company_id", :null => false
184
+ t.integer "value", :default => 0
182
185
  t.timestamp "deleted_at"
183
186
  end
184
187
 
185
188
  create_table "soft_delete_discards", :force => true do |t|
186
189
  t.integer "company_id", :null => false
190
+ t.integer "value", :default => 0
187
191
  t.timestamp "discarded_at"
188
192
  end
189
193
 
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: 2.1.2
4
+ version: 2.1.3
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: 2018-12-07 00:00:00.000000000 Z
11
+ date: 2019-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: after_commit_action