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
4551c3b2
Commit
4551c3b2
authored
Feb 20, 2017
by
Andrzej Piątyszek
Committed by
GitHub
Feb 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'core' into core
parents
44885780
ba48f196
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
3 deletions
+81
-3
CHANGELOG.md
+22
-0
lib/paranoia.rb
+3
-2
lib/paranoia/version.rb
+1
-1
test/paranoia_test.rb
+55
-0
No files found.
CHANGELOG.md
View file @
4551c3b2
# paranoia Changelog
## 2.2.2 (Unreleased)
## 2.2.1 (2017-02-15)
*
[
#371
](
https://github.com/rubysherpas/paranoia/pull/371
)
Use ActiveSupport.on_load to correctly re-open ActiveRecord::Base
_Fixes
[
#335
](
https://github.com/rubysherpas/paranoia/issues/335
)
and
[
#381
](
https://github.com/rubysherpas/paranoia/issues/381
)
._
[
Iaan Krynauw (@iaankrynauw)
](
https://github.com/iaankrynauw
)
*
[
#377
](
https://github.com/rubysherpas/paranoia/pull/377
)
Touch record on paranoia-destroy.
_Fixes
[
#296
](
https://github.com/rubysherpas/paranoia/issues/296
)
._
[
René (@rbr)
](
https://github.com/rbr
)
*
[
#379
](
https://github.com/rubysherpas/paranoia/pull/379
)
Fixes a problem of ambiguous table names when using only_deleted method.
_Fixes
[
#26
](
https://github.com/rubysherpas/paranoia/issues/26
)
and
[
#27
](
https://github.com/rubysherpas/paranoia/pull/27
)
._
[
Thomas Romera (@Erowlin)
](
https://github.com/Erowlin
)
## 2.2.0 (2016-10-21)
*
Ruby 2.0 or greater is required
...
...
lib/paranoia.rb
View file @
4551c3b2
...
...
@@ -35,8 +35,9 @@ module Paranoia
# some deleted rows will hold a null value in the paranoia column
# these will not match != sentinel value because "NULL != value" is
# NULL under the sql standard
quoted_paranoia_column
=
connection
.
quote_column_name
(
paranoia_column
)
with_deleted
.
where
(
"
#{
quoted_paranoia_column
}
IS NULL OR
#{
quoted_paranoia_column
}
!= ?"
,
paranoia_sentinel_value
)
# Scoping with the table_name is mandatory to avoid ambiguous errors when joining tables.
scoped_quoted_paranoia_column
=
"
#{
self
.
table_name
}
.
#{
connection
.
quote_column_name
(
paranoia_column
)
}
"
with_deleted
.
where
(
"
#{
scoped_quoted_paranoia_column
}
IS NULL OR
#{
scoped_quoted_paranoia_column
}
!= ?"
,
paranoia_sentinel_value
)
end
alias_method
:deleted
,
:only_deleted
...
...
lib/paranoia/version.rb
View file @
4551c3b2
module
Paranoia
VERSION
=
"2.2.0"
VERSION
=
'2.2.1'
.
freeze
end
test/paranoia_test.rb
View file @
4551c3b2
...
...
@@ -40,6 +40,8 @@ def setup!
'unparanoid_unique_models'
=>
'name VARCHAR(32), paranoid_with_unparanoids_id INTEGER'
,
'active_column_models'
=>
'deleted_at DATETIME, active BOOLEAN'
,
'active_column_model_with_uniqueness_validations'
=>
'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN'
,
'paranoid_model_with_belongs_to_active_column_model_with_has_many_relationships'
=>
'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN, active_column_model_with_has_many_relationship_id INTEGER'
,
'active_column_model_with_has_many_relationships'
=>
'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN'
,
'without_default_scope_models'
=>
'deleted_at DATETIME'
}.
each
do
|
table_name
,
columns_as_sql_string
|
ActiveRecord
::
Base
.
connection
.
execute
"CREATE TABLE
#{
table_name
}
(id INTEGER NOT NULL PRIMARY KEY,
#{
columns_as_sql_string
}
)"
...
...
@@ -182,8 +184,11 @@ class ParanoiaTest < test_framework
p2
=
ParanoidModel
.
create
(
:parent_model
=>
parent2
)
p1
.
destroy
p2
.
destroy
assert_equal
0
,
parent1
.
paranoid_models
.
count
assert_equal
1
,
parent1
.
paranoid_models
.
only_deleted
.
count
assert_equal
2
,
ParanoidModel
.
only_deleted
.
joins
(
:parent_model
).
count
assert_equal
1
,
parent1
.
paranoid_models
.
deleted
.
count
assert_equal
0
,
parent1
.
paranoid_models
.
without_deleted
.
count
p3
=
ParanoidModel
.
create
(
:parent_model
=>
parent1
)
...
...
@@ -192,6 +197,17 @@ class ParanoiaTest < test_framework
assert_equal
[
p1
,
p3
],
parent1
.
paranoid_models
.
with_deleted
end
def
test_only_deleted_with_joins
c1
=
ActiveColumnModelWithHasManyRelationship
.
create
(
name:
'Jacky'
)
c2
=
ActiveColumnModelWithHasManyRelationship
.
create
(
name:
'Thomas'
)
p1
=
ParanoidModelWithBelongsToActiveColumnModelWithHasManyRelationship
.
create
(
name:
'Hello'
,
active_column_model_with_has_many_relationship:
c1
)
c1
.
destroy
assert_equal
1
,
ActiveColumnModelWithHasManyRelationship
.
count
assert_equal
1
,
ActiveColumnModelWithHasManyRelationship
.
only_deleted
.
count
assert_equal
1
,
ActiveColumnModelWithHasManyRelationship
.
only_deleted
.
joins
(
:paranoid_model_with_belongs_to_active_column_model_with_has_many_relationships
).
count
end
def
test_destroy_behavior_for_custom_column_models
model
=
CustomColumnModel
.
new
assert_equal
0
,
model
.
class
.
count
...
...
@@ -1144,6 +1160,45 @@ class ActiveColumnModelWithUniquenessValidation < ActiveRecord::Base
end
end
class
ActiveColumnModelWithHasManyRelationship
<
ActiveRecord
::
Base
has_many
:paranoid_model_with_belongs_to_active_column_model_with_has_many_relationships
acts_as_paranoid
column: :active
,
sentinel_value:
true
def
paranoia_restore_attributes
{
deleted_at:
nil
,
active:
true
}
end
def
paranoia_destroy_attributes
{
deleted_at:
current_time_from_proper_timezone
,
active:
nil
}
end
end
class
ParanoidModelWithBelongsToActiveColumnModelWithHasManyRelationship
<
ActiveRecord
::
Base
belongs_to
:active_column_model_with_has_many_relationship
acts_as_paranoid
column: :active
,
sentinel_value:
true
def
paranoia_restore_attributes
{
deleted_at:
nil
,
active:
true
}
end
def
paranoia_destroy_attributes
{
deleted_at:
current_time_from_proper_timezone
,
active:
nil
}
end
end
class
NonParanoidModel
<
ActiveRecord
::
Base
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