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
...
@@ -90,10 +90,15 @@ module Paranoia
# insert time to paranoia column.
# insert time to paranoia column.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
def
touch_paranoia_column
(
with_transaction
=
false
)
def
touch_paranoia_column
(
with_transaction
=
false
)
if
with_transaction
# This method is (potentially) called from really_destroy
with_transaction_returning_status
{
touch
(
paranoia_column
)
}
# The object the method is being called on may be frozen
else
# Let's not touch it if it's frozen.
touch
(
paranoia_column
)
unless
self
.
frozen?
if
with_transaction
with_transaction_returning_status
{
touch
(
paranoia_column
)
}
else
touch
(
paranoia_column
)
end
end
end
end
end
...
@@ -122,9 +127,20 @@ end
...
@@ -122,9 +127,20 @@ end
class
ActiveRecord
::
Base
class
ActiveRecord
::
Base
def
self
.
acts_as_paranoid
(
options
=
{})
def
self
.
acts_as_paranoid
(
options
=
{})
alias
:really_destroy!
:destroy
alias
:destroy!
:destroy
alias
:destroy!
:destroy
alias
:delete!
:delete
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
include
Paranoia
class_attribute
:paranoia_column
class_attribute
:paranoia_column
...
...
test/paranoia_test.rb
View file @
4f268326
...
@@ -287,13 +287,20 @@ class ParanoiaTest < test_framework
...
@@ -287,13 +287,20 @@ class ParanoiaTest < test_framework
assert
model
.
instance_variable_get
(
:@restore_callback_called
)
assert
model
.
instance_variable_get
(
:@restore_callback_called
)
end
end
def
test_real_destroy
def
test_real
ly
_destroy
model
=
ParanoidModel
.
new
model
=
ParanoidModel
.
new
model
.
save
model
.
save
model
.
really_destroy!
model
.
really_destroy!
refute
ParanoidModel
.
unscoped
.
exists?
(
model
.
id
)
refute
ParanoidModel
.
unscoped
.
exists?
(
model
.
id
)
end
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"
if
ActiveRecord
::
VERSION
::
STRING
<
"4.1"
def
test_real_destroy
def
test_real_destroy
model
=
ParanoidModel
.
new
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