activerecord-delay_touching 1.0.0 → 1.0.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: bf2e396443031e052664ae33fa9abca71b1a1b45
4
- data.tar.gz: 0009099d96abdb6f58a1590c5f5c7df699d0382e
3
+ metadata.gz: 731f1b62489c8675bb3df76d2d12ffb90ae5cc58
4
+ data.tar.gz: ff36c494301d616c19dd8300d05245eae989e553
5
5
  SHA512:
6
- metadata.gz: bba9504122174575808beec7d1107e603e434535afe421361dd83ad6341867fbdae957e509653349be3a7ebd16c97050d4c12ca900aa22360a547c61a017d2cd
7
- data.tar.gz: 2e822052fb026400b9abd0b9bb25a36220d9eac30acb02267495535b9da99fc3be49e1cd296e6c035ccdd0c97c12c00fe51636d38f3f64664048a4fcb5f6863b
6
+ metadata.gz: 5777ddf6f855fafac79a3866fdd7940986aeb2882f5622ca31930bca8beb86d20213fef6db7957f223828e69aa17f558d4e906218d54087007f2c9408fa8307b
7
+ data.tar.gz: d0733fe1dd22034db87c60a3d46acf5a4034be3c7803c6ee3765a345735ba9c73afa563329158e8b6323837a760a434629900b4b9b50248fa5db9b9eb5509368
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Activerecord::DelayTouching
2
2
 
3
+ > **Note:** this version requires ActiveRecord 4.2 or higher. To use ActiveRecord 3.2 through 4.1, use the branch https://github.com/godaddy/activerecord-delay_touching/tree/pre-activerecord-4.2.
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
@@ -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 = "1.0.0"
3
+ VERSION = "1.0.1"
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: 1.0.0
4
+ version: 1.0.1
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-05-07 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
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.4.6
183
+ rubygems_version: 2.4.8
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Batch up your ActiveRecord "touch" operations for better performance.