zombie_record 1.1.2 → 1.2.0

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: 5fcd4f52b9d5d55985cfbdbe559120d7893df768
4
- data.tar.gz: d2349915fe48d65dcd8c67e1a7ff4582023fbe5f
3
+ metadata.gz: 5e85b5f05f1f16bf87dd233fffc48ce5de64b287
4
+ data.tar.gz: 9fd0bbbceb85da7aa8059ddec935ae64d396ae71
5
5
  SHA512:
6
- metadata.gz: b8248ef72aee0d1b52a52559463f31f764a47438892636d60205aa9ac2ac81f747f0cd698074daed3374579d7ee4cc810ff4377e3933937cbd9a158310bc04ad
7
- data.tar.gz: f3dbf5c2833aedb5996ee75ca47a58e2cdef2f2097e849c2999fc808bd0d0e51039d1863e68a2e34ffc9c686764720da97ab589fa76aa664c6f952e4243114e5
6
+ metadata.gz: a3410a21df7c423829dc0256d411196aa6ac6a9db75d7ed85eaef31bfa32cec609a1bccca047d83873e9d11efc53884cc6cb3f1f882165335f2598cd5696a14a
7
+ data.tar.gz: ef0ecdbc21fc042297e195a999efb8fe27cc10513f89761ee60b3af0ae77d4326b9e7dc71d32b2ea07c0568742e8ffd8087421c8bfcb6fdc6daed56270acc526
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ###### Unreleased
2
2
 
3
+ ###### v1.2.0
4
+
5
+ * Fix counter_cache behavior in Rails 4.2.
6
+
3
7
  ###### v1.1.2
4
8
 
5
9
  * Fewer queries when soft deleting.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- zombie_record (1.1.2)
4
+ zombie_record (1.2.0)
5
5
  activerecord (~> 4.0)
6
6
  mysql2
7
7
 
@@ -35,7 +35,7 @@ GEM
35
35
  i18n (0.6.11)
36
36
  minitest (4.7.5)
37
37
  multi_json (1.10.1)
38
- mysql2 (0.3.17)
38
+ mysql2 (0.3.19)
39
39
  rake (10.3.2)
40
40
  rspec (2.14.1)
41
41
  rspec-core (~> 2.14.0)
@@ -63,3 +63,6 @@ DEPENDENCIES
63
63
  timecop (~> 0.7.0)
64
64
  wwtd (>= 0.5.3)
65
65
  zombie_record!
66
+
67
+ BUNDLED WITH
68
+ 1.10.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- zombie_record (1.1.2)
4
+ zombie_record (1.2.0)
5
5
  activerecord (~> 4.0)
6
6
  mysql2
7
7
 
@@ -33,7 +33,7 @@ GEM
33
33
  i18n (0.6.11)
34
34
  json (1.8.1)
35
35
  minitest (5.4.3)
36
- mysql2 (0.3.17)
36
+ mysql2 (0.3.19)
37
37
  rake (10.3.2)
38
38
  rspec (2.14.1)
39
39
  rspec-core (~> 2.14.0)
@@ -62,3 +62,6 @@ DEPENDENCIES
62
62
  timecop (~> 0.7.0)
63
63
  wwtd (>= 0.5.3)
64
64
  zombie_record!
65
+
66
+ BUNDLED WITH
67
+ 1.10.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- zombie_record (1.1.2)
4
+ zombie_record (1.2.0)
5
5
  activerecord (~> 4.0)
6
6
  mysql2
7
7
 
@@ -33,7 +33,7 @@ GEM
33
33
  i18n (0.7.0)
34
34
  json (1.8.1)
35
35
  minitest (5.5.0)
36
- mysql2 (0.3.17)
36
+ mysql2 (0.3.19)
37
37
  rake (10.4.2)
38
38
  rspec (2.14.1)
39
39
  rspec-core (~> 2.14.0)
@@ -62,3 +62,6 @@ DEPENDENCIES
62
62
  timecop (~> 0.7.0)
63
63
  wwtd (>= 0.5.3)
64
64
  zombie_record!
65
+
66
+ BUNDLED WITH
67
+ 1.10.6
@@ -51,18 +51,6 @@ module ZombieRecord
51
51
 
52
52
  private
53
53
 
54
- # Override Rails' #destroy_row for soft-delete functionality
55
- def destroy_row
56
- time = current_time_from_proper_timezone
57
-
58
- update_params = { deleted_at: time }
59
- if self.class.column_names.include?("updated_at")
60
- update_params[:updated_at] = time
61
- end
62
-
63
- update_columns(update_params)
64
- end
65
-
66
54
  def restore_associated_records!
67
55
  self.class.reflect_on_all_associations.each do |association|
68
56
  # Only restore associations that are automatically destroyed alongside
@@ -1,3 +1,3 @@
1
1
  module ZombieRecord
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/zombie_record.rb CHANGED
@@ -5,3 +5,25 @@ module ZombieRecord
5
5
  end
6
6
 
7
7
  require 'zombie_record/restorable'
8
+
9
+ module ActiveRecord
10
+ module Persistence
11
+ alias_method :zombie_record_alias_destroy_row, :destroy_row
12
+
13
+ # Maybe override Rails' #destroy_row for soft-delete functionality
14
+ def destroy_row
15
+ if self.class.include?(ZombieRecord::Restorable)
16
+ time = current_time_from_proper_timezone
17
+
18
+ update_params = { deleted_at: time }
19
+ if self.class.column_names.include?("updated_at")
20
+ update_params[:updated_at] = time
21
+ end
22
+
23
+ update_columns(update_params) ? 1 : 0
24
+ else
25
+ zombie_record_alias_destroy_row
26
+ end
27
+ end
28
+ end
29
+ end
@@ -91,6 +91,17 @@ describe ZombieRecord::Restorable do
91
91
  bookmark = Timecop.travel(2.days.ago) { Bookmark.create! }
92
92
  expect { bookmark.destroy }.to_not raise_exception
93
93
  end
94
+
95
+ it "updates the counter cache" do
96
+ book = Book.create!
97
+ bookmark = book.bookmarks.create!
98
+
99
+ expect(book.reload.bookmarks_count).to eq(1)
100
+
101
+ bookmark.destroy!
102
+
103
+ expect(book.reload.bookmarks_count).to eq(0)
104
+ end
94
105
  end
95
106
 
96
107
  describe "#restore!" do
data/spec/spec_helper.rb CHANGED
@@ -27,7 +27,7 @@ end
27
27
  class Bookmark < ActiveRecord::Base
28
28
  include ZombieRecord::Restorable
29
29
 
30
- belongs_to :book
30
+ belongs_to :book, counter_cache: true
31
31
  end
32
32
 
33
33
  class Note < ActiveRecord::Base
@@ -85,6 +85,7 @@ RSpec.configure do |config|
85
85
  create_table :books do |t|
86
86
  t.integer :author_id
87
87
  t.integer :library_id
88
+ t.integer :bookmarks_count
88
89
  t.timestamps null: false
89
90
  t.string :title
90
91
  t.timestamp :deleted_at
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-23 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord