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
ceaaecb1
Commit
ceaaecb1
authored
Sep 08, 2014
by
Ryan Bigg
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #157 from poporul/clear_association_cache
Clear association cache
parents
fe706284
5257eec4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
lib/paranoia.rb
+5
-5
test/paranoia_test.rb
+22
-0
No files found.
lib/paranoia.rb
View file @
ceaaecb1
...
@@ -34,11 +34,7 @@ module Paranoia
...
@@ -34,11 +34,7 @@ module Paranoia
alias
:deleted
:only_deleted
alias
:deleted
:only_deleted
def
restore
(
id
,
opts
=
{})
def
restore
(
id
,
opts
=
{})
if
id
.
is_a?
(
Array
)
Array
(
id
).
flatten
.
map
{
|
one_id
|
only_deleted
.
find
(
one_id
).
restore!
(
opts
)
}
id
.
map
{
|
one_id
|
restore
(
one_id
,
opts
)
}
else
only_deleted
.
find
(
id
).
restore!
(
opts
)
end
end
end
end
end
...
@@ -97,6 +93,8 @@ module Paranoia
...
@@ -97,6 +93,8 @@ module Paranoia
restore_associated_records
if
opts
[
:recursive
]
restore_associated_records
if
opts
[
:recursive
]
end
end
end
end
self
end
end
alias
:restore
:restore!
alias
:restore
:restore!
...
@@ -143,6 +141,8 @@ module Paranoia
...
@@ -143,6 +141,8 @@ module Paranoia
end
end
end
end
end
end
clear_association_cache
if
destroyed_associations
.
present?
end
end
end
end
...
...
test/paranoia_test.rb
View file @
ceaaecb1
...
@@ -290,6 +290,13 @@ class ParanoiaTest < test_framework
...
@@ -290,6 +290,13 @@ class ParanoiaTest < test_framework
assert_equal
false
,
model
.
destroyed?
assert_equal
false
,
model
.
destroyed?
end
end
def
test_restore_on_object_return_self
model
=
ParanoidModel
.
create
model
.
destroy
assert_equal
model
.
class
,
model
.
restore
.
class
end
# Regression test for #92
# Regression test for #92
def
test_destroy_twice
def
test_destroy_twice
model
=
ParanoidModel
.
new
model
=
ParanoidModel
.
new
...
@@ -537,6 +544,21 @@ class ParanoiaTest < test_framework
...
@@ -537,6 +544,21 @@ class ParanoiaTest < test_framework
connect!
# Reconnect the main connection
connect!
# Reconnect the main connection
end
end
def
test_restore_clear_association_cache_if_associations_present
parent
=
ParentModel
.
create
3
.
times
{
parent
.
very_related_models
.
create
}
parent
.
destroy
assert_equal
0
,
parent
.
very_related_models
.
count
assert_equal
0
,
parent
.
very_related_models
.
size
parent
.
restore
(
recursive:
true
)
assert_equal
3
,
parent
.
very_related_models
.
count
assert_equal
3
,
parent
.
very_related_models
.
size
end
private
private
def
get_featureful_model
def
get_featureful_model
FeaturefulModel
.
new
(
:name
=>
"not empty"
)
FeaturefulModel
.
new
(
:name
=>
"not empty"
)
...
...
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