activerecord-delay_touching 0.0.3 → 0.0.4

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: fb3ab2ee2253bda6f6205c8f7c29f36a916b232d
4
- data.tar.gz: 252006c75ba9b36df90da8cfe805cd58716d278b
3
+ metadata.gz: 81d58f8a4a53021f8034c2da68790d7648b2b4f3
4
+ data.tar.gz: 2d975e4e5c14ee8baecaaf762aaa8a8ebb003bef
5
5
  SHA512:
6
- metadata.gz: e0582f5ab6cecfbbe5ab2e28411154b5b5d7ddf8eb851dd3fe68e3a712bd17915e4931c59edaca46bd15e88e262dadb0d6689c743c8a507340f4274fc2fe8ef6
7
- data.tar.gz: ea148565acd6d3d2138b748e44589b828df5d2168f8a71c8b2f17216af0d3ac1b1ea9db51bce193a03ee22afee4a1b15d0103f95f8da57f8361702b421408b0b
6
+ metadata.gz: 46209cc3478f9f81e932644e79364bb2ff012d536cabc2e3927cca61c74a641b0b9fc94e6522574c2c0c21281e1a0fda4df0be6db40c0f58b001d73c7ead5008
7
+ data.tar.gz: 89654bba87280ab7976c0d464d43f4a9e0760643ce614532c12910b4e9b9602b38635815251bde5877bbd24a2c95742ca13ffac0b55bb7461a1786c0e5c077a7
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Activerecord::DelayTouching
2
2
 
3
+ > **Note:** this version supports ActiveRecord 3.2 through 4.1 only. For ActiveRecord 4.2+, please see the Master branch.
4
+
3
5
  Batch up your ActiveRecord "touch" operations for better performance.
4
6
 
5
7
  When you want to invalidate a cache in Rails, you use `touch: true`. But when
@@ -13,7 +15,7 @@ round-trips as possible. Instead of N touches you get 1 touch.
13
15
 
14
16
  Add this line to your application's Gemfile:
15
17
 
16
- gem 'activerecord-delay_touching'
18
+ gem 'activerecord-delay_touching', '~> 0.0.3'
17
19
 
18
20
  And then execute:
19
21
 
@@ -21,7 +23,7 @@ And then execute:
21
23
 
22
24
  Or install it yourself:
23
25
 
24
- $ gem install activerecord-delay_touching
26
+ $ gem install activerecord-delay_touching -v 0.0.3
25
27
 
26
28
  ## Usage
27
29
 
@@ -86,6 +86,7 @@ module ActiveRecord
86
86
  column = column.to_s
87
87
  changes[column] = current_time
88
88
  records.each do |record|
89
+ next if record.destroyed?
89
90
  record.instance_eval do
90
91
  write_attribute column, current_time
91
92
  @changed_attributes.except!(*changes.keys)
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module DelayTouching
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -151,6 +151,28 @@ describe Activerecord::DelayTouching do
151
151
  end
152
152
  end
153
153
 
154
+ context 'dependent deletes' do
155
+
156
+ let(:post) { Post.create! }
157
+ let(:user) { User.create! }
158
+ let(:comment) { Comment.create! }
159
+
160
+ before do
161
+ post.comments << comment
162
+ user.comments << comment
163
+ end
164
+
165
+ it 'does not attempt to touch deleted records' do
166
+ expect do
167
+ ActiveRecord::Base.delay_touching do
168
+ post.destroy
169
+ end
170
+ end.not_to raise_error
171
+ expect(post.destroyed?).to eq true
172
+ end
173
+
174
+ end
175
+
154
176
  def expect_updates(tables)
155
177
  expected_sql = tables.map do |entry|
156
178
  if entry.kind_of?(Hash)
@@ -5,3 +5,16 @@ end
5
5
  class Pet < ActiveRecord::Base
6
6
  belongs_to :person, touch: true, inverse_of: :pets
7
7
  end
8
+
9
+ class Post < ActiveRecord::Base
10
+ has_many :comments, dependent: :destroy
11
+ end
12
+
13
+ class User < ActiveRecord::Base
14
+ has_many :comments, dependent: :destroy
15
+ end
16
+
17
+ class Comment < ActiveRecord::Base
18
+ belongs_to :post, touch: true
19
+ belongs_to :user, touch: true
20
+ end
@@ -16,4 +16,18 @@ ActiveRecord::Schema.define do
16
16
  t.timestamps
17
17
  end
18
18
 
19
+ create_table :posts, force: true do |t|
20
+ t.timestamps null: false
21
+ end
22
+
23
+ create_table :users, force: true do |t|
24
+ t.timestamps null: false
25
+ end
26
+
27
+ create_table :comments, force: true do |t|
28
+ t.integer :post_id
29
+ t.integer :user_id
30
+ t.timestamps null: false
31
+ end
32
+
19
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-delay_touching
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Morearty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.4.6
189
+ rubygems_version: 2.4.8
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Batch up your ActiveRecord "touch" operations for better performance.