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
7a5bd3b5
Commit
7a5bd3b5
authored
Jan 22, 2015
by
John Hawthorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix behaviour for new and destroyed records
parent
356b1357
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
lib/paranoia.rb
+4
-7
test/paranoia_test.rb
+26
-0
No files found.
lib/paranoia.rb
View file @
7a5bd3b5
...
...
@@ -98,13 +98,10 @@ module Paranoia
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
def
touch_paranoia_column
(
with_transaction
=
false
)
raise
ActiveRecord
::
ReadOnlyRecord
,
"
#{
self
.
class
}
is marked as readonly"
if
readonly?
return
self
if
really_destroyed?
||
new_record?
# 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
persisted?
touch
(
paranoia_column
)
elsif
!
frozen?
write_attribute
(
paranoia_column
,
current_time_from_proper_timezone
)
end
self
end
...
...
@@ -175,7 +172,7 @@ class ActiveRecord::Base
end
end
end
touch_paranoia_column
if
ActiveRecord
::
VERSION
::
STRING
>=
"4.1"
write_attribute
(
paranoia_column
,
current_time_from_proper_timezone
)
destroy_without_paranoia
end
...
...
test/paranoia_test.rb
View file @
7a5bd3b5
...
...
@@ -307,6 +307,32 @@ class ParanoiaTest < test_framework
end
end
def
test_destroy_on_really_destroyed_record
model
=
ParanoidModel
.
create!
model
.
really_destroy!
assert
model
.
really_destroyed?
assert
model
.
paranoia_destroyed?
model
.
destroy
assert
model
.
really_destroyed?
assert
model
.
paranoia_destroyed?
end
def
test_destroy_on_unsaved_record
# Just to demonstrate the AR behaviour
model
=
NonParanoidModel
.
new
model
.
destroy!
assert
model
.
really_destroyed?
model
.
destroy!
assert
model
.
really_destroyed?
# Mirrors behaviour above
model
=
ParanoidModel
.
new
model
.
destroy!
assert
model
.
paranoia_destroyed?
model
.
destroy!
assert
model
.
paranoia_destroyed?
end
def
test_restore
model
=
ParanoidModel
.
new
model
.
save
...
...
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