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
4ff0fdad
Commit
4ff0fdad
authored
Sep 09, 2013
by
Dan Cheail
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Model.restore(ids) function
Modelled on AR::Relation.destroy
parent
95f6a5d6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
lib/paranoia.rb
+8
-0
test/paranoia_test.rb
+27
-0
No files found.
lib/paranoia.rb
View file @
4ff0fdad
...
@@ -13,6 +13,14 @@ module Paranoia
...
@@ -13,6 +13,14 @@ module Paranoia
def
with_deleted
def
with_deleted
all
.
tap
{
|
x
|
x
.
default_scoped
=
false
}
all
.
tap
{
|
x
|
x
.
default_scoped
=
false
}
end
end
def
restore
(
id
)
if
id
.
is_a?
(
Array
)
id
.
map
{
|
one_id
|
restore
(
one_id
)
}
else
only_deleted
.
find
(
id
).
restore!
end
end
end
end
def
destroy
def
destroy
...
...
test/paranoia_test.rb
View file @
4ff0fdad
...
@@ -204,6 +204,33 @@ class ParanoiaTest < Test::Unit::TestCase
...
@@ -204,6 +204,33 @@ class ParanoiaTest < Test::Unit::TestCase
refute
ParanoidModel
.
unscoped
.
exists?
(
model
.
id
)
refute
ParanoidModel
.
unscoped
.
exists?
(
model
.
id
)
end
end
def
test_multiple_restore
a
=
ParanoidModel
.
new
a
.
save
a_id
=
a
.
id
a
.
destroy
b
=
ParanoidModel
.
new
b
.
save
b_id
=
b
.
id
b
.
destroy
c
=
ParanoidModel
.
new
c
.
save
c_id
=
c
.
id
c
.
destroy
ParanoidModel
.
restore
([
a_id
,
c_id
])
a
.
reload
b
.
reload
c
.
reload
refute
a
.
destroyed?
assert
b
.
destroyed?
refute
c
.
destroyed?
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