destroyed_at 1.0.0 → 1.0.1

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: 0891b99ff62c41dcc3c065cb1ac598781707ea66
4
- data.tar.gz: 15b26364c34fa8e7ba0868e995a787dcfa3b9328
3
+ metadata.gz: d7d179e6fcbc606b511c8f487d48cc6bf51b48aa
4
+ data.tar.gz: 3a5163d54f812bee7ccffb46efb59724a806094f
5
5
  SHA512:
6
- metadata.gz: 5bd593a8e0d239de2196877179e935a02f0bf4ef3b1907396b405430011455a3bf4ba9771dbb434ac6498e5ff05aea79ab25d9375f84752831c90cb10e385120
7
- data.tar.gz: 27072734f2bcfcf621ef0fe54748b2d035477f5f7cf228e7fc4533d47b385eca584308bd47601c816ebe39b3d94b88ed1ce52ab6882477fd04b60d5ee34c8c8d
6
+ metadata.gz: f837e70ea9b18712645e0d710c230dde370d300bc2184a88f0a70223c662066c61c3749f2e6e50ee4f5825b8567c6fff2948528d041ac4ac621cf1fad31b1038
7
+ data.tar.gz: b5355d8bf3b48f2f6dbe4ebbbc899b8931c4b8d68d62572d82afaef45f0f81d793b1815f3510669fdf9748f5733bb2701c166c410097f0e0a3849fcaa1239d8a
@@ -1,3 +1,8 @@
1
+ ## 1.0.1
2
+ * Fixes an issue with where the incorrect arguments were being passed
3
+ from inside the `BelongsToAssociation` and `HasOneAssociation`, as
4
+ reported by [anarchocurious](https://github.com/anarchocurious)
5
+
1
6
  ## 1.0.0
2
7
 
3
8
  * Requires equal to or greater than Ruby `2.0` -
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in destroyed_at.gemspec
4
4
  gemspec
5
+ gem 'm', github: 'unmanbearpig/m'
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["michael.dupuis@dockyard.com"]
11
11
  spec.description = %q{Safe destroy for ActiveRecord.}
12
12
  spec.summary = %q{Safe destroy for ActiveRecord.}
13
- spec.homepage = "https://github.com/dockyard/destroyed_at"
13
+ spec.homepage = "https://github.com/dockyard/ruby-destroyed_at"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -22,6 +22,10 @@ module DestroyedAt
22
22
  end
23
23
  end
24
24
 
25
+ def self.has_destroy_at?(object)
26
+ object.class.included_modules.include?(DestroyedAt)
27
+ end
28
+
25
29
  module ClassMethods
26
30
  def destroyed(time = nil)
27
31
  query = where.not(destroyed_at: nil)
@@ -2,7 +2,7 @@ module DestroyedAt
2
2
  module BelongsToAssociation
3
3
  def handle_dependency
4
4
  if load_target && method == :destroy
5
- DestroyedAt.destroy_target_of_association(target, owner)
5
+ DestroyedAt.destroy_target_of_association(owner, target)
6
6
  else
7
7
  super
8
8
  end
@@ -1,8 +1,8 @@
1
1
  module DestroyedAt
2
2
  module HasOneAssociation
3
3
  def delete(method = options[:dependent])
4
- if load_target && method == :destroy
5
- DestroyedAt.destroy_target_of_association(target, owner)
4
+ if DestroyedAt.has_destroy_at?(target) && load_target && method == :destroy
5
+ DestroyedAt.destroy_target_of_association(owner, target)
6
6
  else
7
7
  super
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module DestroyedAt
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -79,7 +79,7 @@ describe 'destroying an activerecord instance' do
79
79
  author.destroy!
80
80
 
81
81
  Author.count.must_equal 0
82
- Avatar.count.must_equal 1
82
+ Avatar.count.must_equal 0
83
83
  end
84
84
  end
85
85
 
@@ -182,3 +182,15 @@ describe 'creating a destroyed record' do
182
182
  post.persisted?.must_equal false
183
183
  end
184
184
  end
185
+
186
+ describe 'non destroyed-at models' do
187
+ it 'can destroy has_on dependants' do
188
+ person = Person.create!
189
+ pet = person.create_pet!
190
+
191
+ person.destroy
192
+
193
+ assert_equal(0, Person.count, 'Person must be zero')
194
+ assert_equal(0, Pet.count, 'Pet must be zero')
195
+ end
196
+ end
@@ -35,12 +35,22 @@ ActiveRecord::Base.connection.execute(%{CREATE TABLE comments (id INTEGER PRIMAR
35
35
  ActiveRecord::Base.connection.execute(%{CREATE TABLE commenters (id INTEGER PRIMARY KEY, destroyed_at DATETIME);})
36
36
  ActiveRecord::Base.connection.execute(%{CREATE TABLE images (id INTEGER PRIMARY KEY, post_id INTEGER);})
37
37
  ActiveRecord::Base.connection.execute(%{CREATE TABLE posts (id INTEGER PRIMARY KEY, author_id INTEGER, destroyed_at DATETIME);})
38
+ ActiveRecord::Base.connection.execute(%{CREATE TABLE people (id INTEGER PRIMARY KEY);})
39
+ ActiveRecord::Base.connection.execute(%{CREATE TABLE pets (id INTEGER PRIMARY KEY, person_id INTEGER);})
38
40
 
39
41
  class Author < ActiveRecord::Base
40
42
  has_many :posts
41
43
  has_one :avatar, dependent: :destroy
42
44
  end
43
45
 
46
+ class Person < ActiveRecord::Base
47
+ has_one :pet, dependent: :destroy
48
+ end
49
+
50
+ class Pet < ActiveRecord::Base
51
+ belongs_to :person
52
+ end
53
+
44
54
  class Avatar < ActiveRecord::Base
45
55
  include DestroyedAt
46
56
  belongs_to :author
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destroyed_at
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
  - Michael Dupuis Jr.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -162,7 +162,7 @@ files:
162
162
  - test/mapper_test.rb
163
163
  - test/scope_test.rb
164
164
  - test/test_helper.rb
165
- homepage: https://github.com/dockyard/destroyed_at
165
+ homepage: https://github.com/dockyard/ruby-destroyed_at
166
166
  licenses:
167
167
  - MIT
168
168
  metadata: {}
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.4.5
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Safe destroy for ActiveRecord.
@@ -191,4 +191,3 @@ test_files:
191
191
  - test/mapper_test.rb
192
192
  - test/scope_test.rb
193
193
  - test/test_helper.rb
194
- has_rdoc: