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
2355f6d1
Commit
2355f6d1
authored
Dec 09, 2013
by
Alex Koppel
Committed by
Ryan Bigg
Dec 10, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notify observers of paranoid restores
parent
e04bba48
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
lib/paranoia.rb
+7
-0
test/paranoia_test.rb
+30
-0
No files found.
lib/paranoia.rb
View file @
2355f6d1
...
...
@@ -89,6 +89,13 @@ class ActiveRecord::Base
self
.
paranoia_column
=
options
[
:column
]
||
:deleted_at
default_scope
{
where
(
self
.
quoted_table_name
+
".
#{
paranoia_column
}
IS NULL"
)
}
before_restore
{
self
.
class
.
notify_observers
(
:before_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
}
after_restore
{
self
.
class
.
notify_observers
(
:after_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
}
end
def
self
.
paranoid?
;
false
;
end
...
...
test/paranoia_test.rb
View file @
2355f6d1
...
...
@@ -305,6 +305,22 @@ class ParanoiaTest < Test::Unit::TestCase
refute
c
.
destroyed?
end
def
test_observers_notified
a
=
ParanoidModelWithObservers
.
create
a
.
destroy
a
.
restore!
assert
a
.
observers_notified
.
select
{
|
args
|
args
==
[
:before_restore
,
a
]}
assert
a
.
observers_notified
.
select
{
|
args
|
args
==
[
:after_restore
,
a
]}
end
def
test_observers_not_notified_if_not_supported
a
=
ParanoidModelWithObservers
.
create
a
.
destroy
a
.
restore!
# essentially, we're just ensuring that this doesn't crash
end
private
def
get_featureful_model
FeaturefulModel
.
new
(
:name
=>
"not empty"
)
...
...
@@ -378,3 +394,17 @@ end
class
CustomColumnModel
<
ActiveRecord
::
Base
acts_as_paranoid
column: :destroyed_at
end
class
ParanoidModelWithObservers
<
ParanoidModel
def
observers_notified
@observers_notified
||=
[]
end
def
self
.
notify_observer
(
*
args
)
observers_notified
<<
args
end
end
class
ParanoidModelWithoutObservers
<
ParanoidModel
self
.
class
.
send
(
remove_method
:notify_observers
)
if
method_defined?
(
:notify_observers
)
end
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