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
c9728e18
Commit
c9728e18
authored
Feb 03, 2017
by
Ben A. Morgan
Committed by
GitHub
Feb 03, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #377 from rbr/touch_on_destroy
Touch record on paranoia-destroy. Fixes #296
parents
6972b229
2bc73cb4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
lib/paranoia.rb
+6
-3
test/paranoia_test.rb
+7
-0
No files found.
lib/paranoia.rb
View file @
c9728e18
...
@@ -110,7 +110,6 @@ module Paranoia
...
@@ -110,7 +110,6 @@ module Paranoia
if
(
noop_if_frozen
&&
!
@attributes
.
frozen?
)
||
!
noop_if_frozen
if
(
noop_if_frozen
&&
!
@attributes
.
frozen?
)
||
!
noop_if_frozen
write_attribute
paranoia_column
,
paranoia_sentinel_value
write_attribute
paranoia_column
,
paranoia_sentinel_value
update_columns
(
paranoia_restore_attributes
)
update_columns
(
paranoia_restore_attributes
)
touch
end
end
restore_associated_records
if
opts
[
:recursive
]
restore_associated_records
if
opts
[
:recursive
]
end
end
...
@@ -154,13 +153,17 @@ module Paranoia
...
@@ -154,13 +153,17 @@ module Paranoia
def
paranoia_restore_attributes
def
paranoia_restore_attributes
{
{
paranoia_column
=>
paranoia_sentinel_value
paranoia_column
=>
paranoia_sentinel_value
}
}
.
merge
(
timestamp_attributes_with_current_time
)
end
end
def
paranoia_destroy_attributes
def
paranoia_destroy_attributes
{
{
paranoia_column
=>
current_time_from_proper_timezone
paranoia_column
=>
current_time_from_proper_timezone
}
}.
merge
(
timestamp_attributes_with_current_time
)
end
def
timestamp_attributes_with_current_time
timestamp_attributes_for_update_in_model
.
each_with_object
({})
{
|
attr
,
hash
|
hash
[
attr
]
=
current_time_from_proper_timezone
}
end
end
# restore associated records that have been soft deleted when
# restore associated records that have been soft deleted when
...
...
test/paranoia_test.rb
View file @
c9728e18
...
@@ -774,6 +774,13 @@ class ParanoiaTest < test_framework
...
@@ -774,6 +774,13 @@ class ParanoiaTest < test_framework
refute
b
.
valid?
refute
b
.
valid?
end
end
def
test_updated_at_modification_on_destroy
paranoid_model
=
ParanoidModelWithTimestamp
.
create
(
:parent_model
=>
ParentModel
.
create
,
:updated_at
=>
1
.
day
.
ago
)
assert
paranoid_model
.
updated_at
<
10
.
minutes
.
ago
paranoid_model
.
destroy
assert
paranoid_model
.
updated_at
>
10
.
minutes
.
ago
end
def
test_updated_at_modification_on_restore
def
test_updated_at_modification_on_restore
parent1
=
ParentModel
.
create
parent1
=
ParentModel
.
create
pt1
=
ParanoidModelWithTimestamp
.
create
(
:parent_model
=>
parent1
)
pt1
=
ParanoidModelWithTimestamp
.
create
(
:parent_model
=>
parent1
)
...
...
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