destroyed_at 1.0.1 → 1.0.2

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: d7d179e6fcbc606b511c8f487d48cc6bf51b48aa
4
- data.tar.gz: 3a5163d54f812bee7ccffb46efb59724a806094f
3
+ metadata.gz: 04939466ff647a0d0017648e6c952b9223b192d1
4
+ data.tar.gz: f4063081197fd1557dfee1128da533be633eef54
5
5
  SHA512:
6
- metadata.gz: f837e70ea9b18712645e0d710c230dde370d300bc2184a88f0a70223c662066c61c3749f2e6e50ee4f5825b8567c6fff2948528d041ac4ac621cf1fad31b1038
7
- data.tar.gz: b5355d8bf3b48f2f6dbe4ebbbc899b8931c4b8d68d62572d82afaef45f0f81d793b1815f3510669fdf9748f5733bb2701c166c410097f0e0a3849fcaa1239d8a
6
+ metadata.gz: 0aa141594c6795094f7090832560cd0e51ed8f77444a29161ee8e9df911c9637f06490c0e4a746fcfbdf9a754aa8a2a1431a8277bc49ce6e264304dce179cf86
7
+ data.tar.gz: 9f03d073154ff339e9c56f920eef9580198ec3d3a45f577aec105bd6eea5e6cedd337f8d896d13ae26b5f8f4579ee982a42adee34383f83d444c87ad746e41d1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.0.2
2
+ * Fixes an issue in which
3
+ `DestroyedAt::BelongsToAssociation#handle_dependency` was not deriving
4
+ the action from the `options` hash, but was using `method` and raising
5
+ an error for the wrong number of arguments. Thanks to
6
+ [harmdewit](https://github.com/harmdewit) for catching this!
7
+
1
8
  ## 1.0.1
2
9
  * Fixes an issue with where the incorrect arguments were being passed
3
10
  from inside the `BelongsToAssociation` and `HasOneAssociation`, as
@@ -1,7 +1,7 @@
1
1
  module DestroyedAt
2
2
  module BelongsToAssociation
3
3
  def handle_dependency
4
- if load_target && method == :destroy
4
+ if load_target && options[:dependent] == :destroy
5
5
  DestroyedAt.destroy_target_of_association(owner, target)
6
6
  else
7
7
  super
@@ -1,3 +1,3 @@
1
1
  module DestroyedAt
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -186,7 +186,7 @@ end
186
186
  describe 'non destroyed-at models' do
187
187
  it 'can destroy has_on dependants' do
188
188
  person = Person.create!
189
- pet = person.create_pet!
189
+ person.create_pet!
190
190
 
191
191
  person.destroy
192
192
 
@@ -194,3 +194,15 @@ describe 'non destroyed-at models' do
194
194
  assert_equal(0, Pet.count, 'Pet must be zero')
195
195
  end
196
196
  end
197
+
198
+ describe 'destroying a child that destroys its parent on destroy' do
199
+ it 'does not destroy a parent record without DestroyedAt' do
200
+ parent = Person.create!
201
+ child = DestructiveChild.create!(person: parent)
202
+
203
+ child.destroy
204
+
205
+ assert_equal(1, Person.count, 'Person must be one')
206
+ assert_equal(0, DestructiveChild.count, 'DestructiveChild must be zero')
207
+ end
208
+ end
data/test/test_helper.rb CHANGED
@@ -33,6 +33,7 @@ ActiveRecord::Base.connection.execute(%{CREATE TABLE categories (id INTEGER PRIM
33
33
  ActiveRecord::Base.connection.execute(%{CREATE TABLE categorizations (id INTEGER PRIMARY KEY, category_id INTEGER, post_id INTEGER);})
34
34
  ActiveRecord::Base.connection.execute(%{CREATE TABLE comments (id INTEGER PRIMARY KEY, commenter_id INTEGER, post_id INTEGER, destroyed_at DATETIME);})
35
35
  ActiveRecord::Base.connection.execute(%{CREATE TABLE commenters (id INTEGER PRIMARY KEY, destroyed_at DATETIME);})
36
+ ActiveRecord::Base.connection.execute(%{CREATE TABLE destructive_children (id INTEGER PRIMARY KEY, person_id INTEGER, destroyed_at DATETIME);})
36
37
  ActiveRecord::Base.connection.execute(%{CREATE TABLE images (id INTEGER PRIMARY KEY, post_id INTEGER);})
37
38
  ActiveRecord::Base.connection.execute(%{CREATE TABLE posts (id INTEGER PRIMARY KEY, author_id INTEGER, destroyed_at DATETIME);})
38
39
  ActiveRecord::Base.connection.execute(%{CREATE TABLE people (id INTEGER PRIMARY KEY);})
@@ -44,6 +45,7 @@ class Author < ActiveRecord::Base
44
45
  end
45
46
 
46
47
  class Person < ActiveRecord::Base
48
+ has_many :destructive_children
47
49
  has_one :pet, dependent: :destroy
48
50
  end
49
51
 
@@ -78,6 +80,10 @@ class Commenter < ActiveRecord::Base
78
80
  has_many :posts, through: :comments
79
81
  end
80
82
 
83
+ class DestructiveChild < ActiveRecord::Base
84
+ belongs_to :person, dependent: :destroy
85
+ end
86
+
81
87
  class Post < ActiveRecord::Base
82
88
  include DestroyedAt
83
89
 
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.1
4
+ version: 1.0.2
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: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".ruby-version"
147
148
  - ".travis.yml"
148
149
  - CHANGELOG.md
149
150
  - CONTRIBUTING.md
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.4.5
186
+ rubygems_version: 2.2.3
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Safe destroy for ActiveRecord.