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
bd338372
Commit
bd338372
authored
Feb 08, 2016
by
Kurtis Rainbolt-Greene
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #270 from unimatrixZxero/delete_all_fix
Ensure delete_all and destroy_all are paranoid
parents
31b5db1e
ce7670ce
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
lib/paranoia.rb
+4
-0
test/paranoia_test.rb
+58
-0
No files found.
lib/paranoia.rb
View file @
bd338372
...
...
@@ -247,6 +247,10 @@ class ActiveRecord::Base
def
self
.
paranoid?
;
false
;
end
def
paranoid?
;
self
.
class
.
paranoid?
;
end
def
self
.
delete_all
(
conditions
=
nil
)
super
and
return
unless
paranoid?
where
(
conditions
).
update_all
(
self
.
new
.
send
:paranoia_destroy_attributes
)
end
private
def
paranoia_column
...
...
test/paranoia_test.rb
View file @
bd338372
...
...
@@ -918,6 +918,64 @@ class ParanoiaTest < test_framework
related
.
valid?
end
def
test_delete_all
model
=
ParanoidModel
count
=
3
models
=
count
.
times
.
map
{
model
.
new
}
assert_equal
0
,
model
.
count
models
.
each
(
&
:save!
)
assert_equal
count
,
model
.
count
model
.
delete_all
assert_equal
0
,
model
.
count
assert_equal
count
,
model
.
with_deleted
.
count
assert
model
.
with_deleted
.
all?
(
&
:deleted?
)
end
def
test_delete_all_for_non_paranoid_model
model
=
PlainModel
count
=
3
models
=
count
.
times
.
map
{
model
.
new
}
assert_equal
0
,
model
.
count
models
.
each
(
&
:save!
)
assert_equal
count
,
model
.
count
model
.
delete_all
assert_equal
0
,
model
.
count
assert_equal
0
,
model
.
unscoped
.
count
end
def
test_destroy_all
model
=
ParanoidModel
count
=
3
models
=
count
.
times
.
map
{
model
.
new
}
assert_equal
0
,
model
.
count
models
.
each
(
&
:save!
)
assert_equal
count
,
model
.
count
model
.
destroy_all
assert_equal
0
,
model
.
count
assert_equal
3
,
model
.
unscoped
.
count
end
def
test_destroy_all_for_non_paranoid_model
model
=
PlainModel
count
=
3
models
=
count
.
times
.
map
{
model
.
new
}
assert_equal
0
,
model
.
count
models
.
each
(
&
:save!
)
assert_equal
count
,
model
.
count
model
.
destroy_all
assert_equal
0
,
model
.
count
assert_equal
0
,
model
.
unscoped
.
count
end
# TODO: find a fix for Rails 4.1
if
ActiveRecord
::
VERSION
::
STRING
!~
/\A4\.1/
def
test_counter_cache_column_update_on_really_destroy
...
...
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