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
4f268326
Commit
4f268326
authored
Apr 08, 2014
by
Ryan Bigg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
really_destroy! will now really destroy dependent = :destroy associated records
Fixes #117
parent
e2ef9604
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
lib/paranoia.rb
+21
-5
test/paranoia_test.rb
+8
-1
No files found.
lib/paranoia.rb
View file @
4f268326
...
...
@@ -90,10 +90,15 @@ module Paranoia
# insert time to paranoia column.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
def
touch_paranoia_column
(
with_transaction
=
false
)
if
with_transaction
with_transaction_returning_status
{
touch
(
paranoia_column
)
}
else
touch
(
paranoia_column
)
# This method is (potentially) called from really_destroy
# The object the method is being called on may be frozen
# Let's not touch it if it's frozen.
unless
self
.
frozen?
if
with_transaction
with_transaction_returning_status
{
touch
(
paranoia_column
)
}
else
touch
(
paranoia_column
)
end
end
end
...
...
@@ -122,9 +127,20 @@ end
class
ActiveRecord
::
Base
def
self
.
acts_as_paranoid
(
options
=
{})
alias
:really_destroy!
:destroy
alias
:destroy!
:destroy
alias
:delete!
:delete
def
really_destroy!
dependent_reflections
=
self
.
reflections
.
select
do
|
name
,
reflection
|
reflection
.
options
[
:dependent
]
==
:destroy
end
if
dependent_reflections
.
any?
dependent_reflections
.
each
do
|
name
,
_
|
self
.
send
(
name
).
each
(
&
:really_destroy!
)
end
end
destroy!
end
include
Paranoia
class_attribute
:paranoia_column
...
...
test/paranoia_test.rb
View file @
4f268326
...
...
@@ -287,13 +287,20 @@ class ParanoiaTest < test_framework
assert
model
.
instance_variable_get
(
:@restore_callback_called
)
end
def
test_real_destroy
def
test_real
ly
_destroy
model
=
ParanoidModel
.
new
model
.
save
model
.
really_destroy!
refute
ParanoidModel
.
unscoped
.
exists?
(
model
.
id
)
end
def
test_real_destroy_dependent_destroy
parent
=
ParentModel
.
create
child
=
parent
.
very_related_models
.
create
parent
.
really_destroy!
refute
RelatedModel
.
unscoped
.
exists?
(
child
.
id
)
end
if
ActiveRecord
::
VERSION
::
STRING
<
"4.1"
def
test_real_destroy
model
=
ParanoidModel
.
new
...
...
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