destroyed_at 0.4.0 → 1.0.0
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 +4 -4
- data/CHANGELOG.md +16 -8
- data/destroyed_at.gemspec +1 -1
- data/lib/destroyed_at.rb +9 -1
- data/lib/destroyed_at/belongs_to_association.rb +4 -6
- data/lib/destroyed_at/has_one_association.rb +4 -6
- data/lib/destroyed_at/mapper.rb +1 -1
- data/lib/destroyed_at/routes.rb +1 -1
- data/lib/destroyed_at/version.rb +1 -1
- data/test/destroyed_at_test.rb +9 -0
- data/test/mapper_test.rb +13 -0
- data/test/test_helper.rb +7 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0891b99ff62c41dcc3c065cb1ac598781707ea66
|
4
|
+
data.tar.gz: 15b26364c34fa8e7ba0868e995a787dcfa3b9328
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd593a8e0d239de2196877179e935a02f0bf4ef3b1907396b405430011455a3bf4ba9771dbb434ac6498e5ff05aea79ab25d9375f84752831c90cb10e385120
|
7
|
+
data.tar.gz: 27072734f2bcfcf621ef0fe54748b2d035477f5f7cf228e7fc4533d47b385eca584308bd47601c816ebe39b3d94b88ed1ce52ab6882477fd04b60d5ee34c8c8d
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
+
## 1.0.0
|
2
|
+
|
3
|
+
* Requires equal to or greater than Ruby `2.0` -
|
4
|
+
[ryanwood](https://github.com/ryanwood)
|
5
|
+
* Updates `reflections` to `_reflections` -
|
6
|
+
[mukimov](https://github.com/mukimov)
|
7
|
+
* Fixes an exception which was was raised when attempting to destroy a
|
8
|
+
target record whose parent did not mix in DestroyedAt.
|
9
|
+
|
1
10
|
## 0.4.0
|
2
11
|
|
3
12
|
* Updates for Rails 4.1
|
4
13
|
* Removes `.with_default_scope` which has been deprecated.
|
5
14
|
* Enables retrieval of destroyed objects by time via `.destroyed`
|
6
|
-
method, which now takes an optional time attribute. -
|
7
|
-
McClain
|
15
|
+
method, which now takes an optional time attribute. - [linstula](https://github.com/linstula) & [danmcclain](https://github.com/danmcclain)
|
8
16
|
* Removes `m` as a development dependency, since it is not compatible
|
9
17
|
with `minitest 5`.
|
10
18
|
|
@@ -12,13 +20,13 @@ McClain
|
|
12
20
|
**Stable for Rails 4.0**
|
13
21
|
|
14
22
|
* [Bug] Fixed route not raising when resource constant does not exist -
|
15
|
-
|
23
|
+
[bcardarella](https://github.com/bcardarella)
|
16
24
|
|
17
25
|
## 0.3.0
|
18
26
|
|
19
|
-
* Fix issue with has_many destroy against regular models -
|
20
|
-
Cardarella
|
27
|
+
* Fix issue with has_many destroy against regular models - [bcardarella](https://github.com/bcardarella)
|
21
28
|
* Relation.destoyed removes the destoyed scope and adds a scope
|
22
|
-
for records that have been destoyed -
|
23
|
-
|
24
|
-
|
29
|
+
for records that have been destoyed -
|
30
|
+
[danmcclain](https://github.com/danmcclain)
|
31
|
+
* Added /restore route for restorable resources - [bcardarella](https://github.com/bcardarella) &
|
32
|
+
[rsocci](https://github.com/rsocci)
|
data/destroyed_at.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = '
|
20
|
+
spec.required_ruby_version = '~> 2.0'
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activerecord", '~> 4.1'
|
23
23
|
spec.add_runtime_dependency 'actionpack', '~> 4.1'
|
data/lib/destroyed_at.rb
CHANGED
@@ -14,6 +14,14 @@ module DestroyedAt
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.destroy_target_of_association(owner, target)
|
18
|
+
if target.respond_to?(:destroyed_at) && owner.respond_to?(:destroyed_at)
|
19
|
+
target.destroy(owner.destroyed_at)
|
20
|
+
elsif target.respond_to?(:destroyed_at)
|
21
|
+
target.destroy
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
module ClassMethods
|
18
26
|
def destroyed(time = nil)
|
19
27
|
query = where.not(destroyed_at: nil)
|
@@ -67,7 +75,7 @@ module DestroyedAt
|
|
67
75
|
end
|
68
76
|
|
69
77
|
def _restore_associations
|
70
|
-
|
78
|
+
_reflections.select { |key, value| value.options[:dependent] == :destroy }.keys.each do |key|
|
71
79
|
assoc = association(key)
|
72
80
|
reload_association = false
|
73
81
|
if assoc.options[:through] && assoc.options[:dependent] == :destroy
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module DestroyedAt
|
2
2
|
module BelongsToAssociation
|
3
3
|
def handle_dependency
|
4
|
-
if load_target
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
super
|
9
|
-
end
|
4
|
+
if load_target && method == :destroy
|
5
|
+
DestroyedAt.destroy_target_of_association(target, owner)
|
6
|
+
else
|
7
|
+
super
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module DestroyedAt
|
2
2
|
module HasOneAssociation
|
3
3
|
def delete(method = options[:dependent])
|
4
|
-
if load_target
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
super
|
9
|
-
end
|
4
|
+
if load_target && method == :destroy
|
5
|
+
DestroyedAt.destroy_target_of_association(target, owner)
|
6
|
+
else
|
7
|
+
super
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
data/lib/destroyed_at/mapper.rb
CHANGED
@@ -14,7 +14,7 @@ ActionDispatch::Routing::Mapper.send(:prepend, DestroyedAt::Routes)
|
|
14
14
|
module DestroyedAt::Resource
|
15
15
|
def default_actions
|
16
16
|
actions = super
|
17
|
-
class_name = self.
|
17
|
+
class_name = self.singular.camelcase
|
18
18
|
|
19
19
|
if Module.const_defined?(class_name) && class_name.constantize.included_modules.include?(DestroyedAt)
|
20
20
|
actions << :restore
|
data/lib/destroyed_at/routes.rb
CHANGED
@@ -13,7 +13,7 @@ module DestroyedAt::Mapper
|
|
13
13
|
module Resource
|
14
14
|
def default_actions
|
15
15
|
actions = super
|
16
|
-
if self.
|
16
|
+
if self.singular.camelcase.constantize.included_modules.include?(DestroyedAt)
|
17
17
|
actions << :restore
|
18
18
|
end
|
19
19
|
|
data/lib/destroyed_at/version.rb
CHANGED
data/test/destroyed_at_test.rb
CHANGED
@@ -72,6 +72,15 @@ describe 'destroying an activerecord instance' do
|
|
72
72
|
post.destroy
|
73
73
|
Categorization.unscoped.count.must_equal 0
|
74
74
|
end
|
75
|
+
|
76
|
+
it 'destroys child when parent does not mixin DestroyedAt' do
|
77
|
+
avatar = Avatar.create
|
78
|
+
author = Author.create(avatar: avatar)
|
79
|
+
author.destroy!
|
80
|
+
|
81
|
+
Author.count.must_equal 0
|
82
|
+
Avatar.count.must_equal 1
|
83
|
+
end
|
75
84
|
end
|
76
85
|
|
77
86
|
describe 'restoring an activerecord instance' do
|
data/test/mapper_test.rb
CHANGED
@@ -71,6 +71,19 @@ class MapperTest < ActiveSupport::TestCase
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
test 'does not raise if `:as` option is used in routes' do
|
75
|
+
draw do
|
76
|
+
resources :cars, as: :automobiles
|
77
|
+
end
|
78
|
+
|
79
|
+
begin
|
80
|
+
@set.recognize_path('/cars', method: :get)
|
81
|
+
assert true, 'path recognized'
|
82
|
+
rescue ActionController::RoutingError
|
83
|
+
assert false, 'this should not be reached'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
74
87
|
private
|
75
88
|
|
76
89
|
def draw(&block)
|
data/test/test_helper.rb
CHANGED
@@ -28,6 +28,7 @@ ActiveRecord::Base.establish_connection(
|
|
28
28
|
DatabaseCleaner.strategy = :truncation
|
29
29
|
|
30
30
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE authors (id INTEGER PRIMARY KEY);})
|
31
|
+
ActiveRecord::Base.connection.execute(%{CREATE TABLE avatars (id INTEGER PRIMARY KEY, author_id INTEGER, destroyed_at DATETIME);})
|
31
32
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE categories (id INTEGER PRIMARY KEY);})
|
32
33
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE categorizations (id INTEGER PRIMARY KEY, category_id INTEGER, post_id INTEGER);})
|
33
34
|
ActiveRecord::Base.connection.execute(%{CREATE TABLE comments (id INTEGER PRIMARY KEY, commenter_id INTEGER, post_id INTEGER, destroyed_at DATETIME);})
|
@@ -37,6 +38,12 @@ ActiveRecord::Base.connection.execute(%{CREATE TABLE posts (id INTEGER PRIMARY K
|
|
37
38
|
|
38
39
|
class Author < ActiveRecord::Base
|
39
40
|
has_many :posts
|
41
|
+
has_one :avatar, dependent: :destroy
|
42
|
+
end
|
43
|
+
|
44
|
+
class Avatar < ActiveRecord::Base
|
45
|
+
include DestroyedAt
|
46
|
+
belongs_to :author
|
40
47
|
end
|
41
48
|
|
42
49
|
class Category < ActiveRecord::Base
|
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: 0.
|
4
|
+
version: 1.0.0
|
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
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -172,9 +172,9 @@ require_paths:
|
|
172
172
|
- lib
|
173
173
|
required_ruby_version: !ruby/object:Gem::Requirement
|
174
174
|
requirements:
|
175
|
-
- - "
|
175
|
+
- - "~>"
|
176
176
|
- !ruby/object:Gem::Version
|
177
|
-
version: '2.
|
177
|
+
version: '2.0'
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
requirements:
|
180
180
|
- - ">="
|
@@ -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.
|
185
|
+
rubygems_version: 2.2.2
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Safe destroy for ActiveRecord.
|