Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paranoia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paranoia
Commits
099e18dd
Commit
099e18dd
authored
Aug 18, 2014
by
Ryan Bigg
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #151 from astronz/really-destroy-has-one
really_destroy! and has_one associations
parents
d0e603e9
acd39d7b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
lib/paranoia.rb
+8
-4
test/paranoia_test.rb
+15
-0
No files found.
lib/paranoia.rb
View file @
099e18dd
...
@@ -154,10 +154,14 @@ class ActiveRecord::Base
...
@@ -154,10 +154,14 @@ class ActiveRecord::Base
if
dependent_reflections
.
any?
if
dependent_reflections
.
any?
dependent_reflections
.
each
do
|
name
,
_
|
dependent_reflections
.
each
do
|
name
,
_
|
associated_records
=
self
.
send
(
name
)
associated_records
=
self
.
send
(
name
)
# Paranoid models will have this method, non-paranoid models will not
# has_one association can return nil
associated_records
=
associated_records
.
with_deleted
if
associated_records
.
respond_to?
(
:with_deleted
)
if
associated_records
&&
associated_records
.
respond_to?
(
:with_deleted
)
associated_records
.
each
(
&
:really_destroy!
)
# Paranoid models will have this method, non-paranoid models will not
self
.
send
(
name
).
reload
associated_records
.
with_deleted
.
each
(
&
:really_destroy!
)
self
.
send
(
name
).
reload
elsif
associated_records
&&
!
associated_records
.
respond_to?
(
:each
)
# single record
associated_records
.
really_destroy!
end
end
end
end
end
touch_paranoia_column
if
ActiveRecord
::
VERSION
::
STRING
>=
"4.1"
touch_paranoia_column
if
ActiveRecord
::
VERSION
::
STRING
>=
"4.1"
...
...
test/paranoia_test.rb
View file @
099e18dd
...
@@ -435,6 +435,21 @@ class ParanoiaTest < test_framework
...
@@ -435,6 +435,21 @@ class ParanoiaTest < test_framework
assert
hasOne
.
reload
.
deleted_at
.
nil?
assert
hasOne
.
reload
.
deleted_at
.
nil?
end
end
# covers #131
def
test_has_one_really_destroy_with_nil
model
=
ParanoidModelWithHasOne
.
create
model
.
really_destroy!
refute
ParanoidModelWithBelong
.
unscoped
.
exists?
(
model
.
id
)
end
def
test_has_one_really_destroy_with_record
model
=
ParanoidModelWithHasOne
.
create
{
|
record
|
record
.
build_paranoid_model_with_belong
}
model
.
really_destroy!
refute
ParanoidModelWithBelong
.
unscoped
.
exists?
(
model
.
id
)
end
def
test_observers_notified
def
test_observers_notified
a
=
ParanoidModelWithObservers
.
create
a
=
ParanoidModelWithObservers
.
create
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment