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
29eb730f
Commit
29eb730f
authored
Jan 03, 2014
by
Ryan Bigg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert behaviour of calling destroy twice deleting records
As per #92
parent
5efb43fe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
lib/paranoia.rb
+5
-9
test/paranoia_test.rb
+2
-1
No files found.
lib/paranoia.rb
View file @
29eb730f
...
@@ -44,12 +44,12 @@ module Paranoia
...
@@ -44,12 +44,12 @@ module Paranoia
end
end
def
destroy
def
destroy
run_callbacks
(
:destroy
)
{
delete_or_soft_delete
(
true
)
}
run_callbacks
(
:destroy
)
{
touch_paranoia_column
(
true
)
}
end
end
def
delete
def
delete
return
if
new_record?
return
if
new_record?
delete_or_soft_delete
touch_paranoia_column
(
false
)
end
end
def
restore!
(
opts
=
{})
def
restore!
(
opts
=
{})
...
@@ -68,11 +68,6 @@ module Paranoia
...
@@ -68,11 +68,6 @@ module Paranoia
alias
:deleted?
:destroyed?
alias
:deleted?
:destroyed?
private
private
# select and exec delete or soft-delete.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions, when soft-delete.
def
delete_or_soft_delete
(
with_transaction
=
false
)
destroyed?
?
destroy!
:
touch_paranoia_column
(
with_transaction
)
end
# touch paranoia column.
# touch paranoia column.
# insert time to paranoia column.
# insert time to paranoia column.
...
@@ -104,8 +99,9 @@ end
...
@@ -104,8 +99,9 @@ end
class
ActiveRecord
::
Base
class
ActiveRecord
::
Base
def
self
.
acts_as_paranoid
(
options
=
{})
def
self
.
acts_as_paranoid
(
options
=
{})
alias
:destroy!
:destroy
alias
:ar_destroy
:destroy
alias
:delete!
:delete
alias
:destroy!
:ar_destroy
alias
:delete!
:delete
include
Paranoia
include
Paranoia
class_attribute
:paranoia_column
class_attribute
:paranoia_column
...
...
test/paranoia_test.rb
View file @
29eb730f
...
@@ -239,13 +239,14 @@ class ParanoiaTest < Test::Unit::TestCase
...
@@ -239,13 +239,14 @@ class ParanoiaTest < Test::Unit::TestCase
assert_equal
false
,
model
.
destroyed?
assert_equal
false
,
model
.
destroyed?
end
end
# Regression test for #92
def
test_destroy_twice
def
test_destroy_twice
model
=
ParanoidModel
.
new
model
=
ParanoidModel
.
new
model
.
save
model
.
save
model
.
destroy
model
.
destroy
model
.
destroy
model
.
destroy
assert_equal
0
,
ParanoidModel
.
unscoped
.
where
(
id:
model
.
id
).
count
assert_equal
1
,
ParanoidModel
.
unscoped
.
where
(
id:
model
.
id
).
count
end
end
def
test_restore_behavior_for_callbacks
def
test_restore_behavior_for_callbacks
...
...
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