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
e4f3afda
Commit
e4f3afda
authored
Sep 25, 2014
by
Shreyas Agarwal
Committed by
John Hawthorn
Jan 18, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added regression testing to the bug for #168
parent
f185ce8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
test/paranoia_test.rb
+20
-0
No files found.
test/paranoia_test.rb
View file @
e4f3afda
...
@@ -21,6 +21,7 @@ def setup!
...
@@ -21,6 +21,7 @@ def setup!
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_anthor_class_name_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_anthor_class_name_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_foreign_key_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, has_one_foreign_key_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_model_with_foreign_key_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME, has_one_foreign_key_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE not_paranoid_model_with_belongs (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, paranoid_model_with_has_one_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32))'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32))'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE callback_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE callback_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)'
...
@@ -456,9 +457,12 @@ class ParanoiaTest < test_framework
...
@@ -456,9 +457,12 @@ class ParanoiaTest < test_framework
belongsTo
=
ParanoidModelWithBelong
.
create
belongsTo
=
ParanoidModelWithBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
notParanoidModel
=
NotParanoidModelWithBelong
.
create
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
not_paranoid_model_with_belong
=
notParanoidModel
hasOne
.
save!
hasOne
.
save!
hasOne
.
destroy
hasOne
.
destroy
...
@@ -471,6 +475,7 @@ class ParanoiaTest < test_framework
...
@@ -471,6 +475,7 @@ class ParanoiaTest < test_framework
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
notParanoidModel
.
destroyed?
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
...
@@ -482,9 +487,12 @@ class ParanoiaTest < test_framework
...
@@ -482,9 +487,12 @@ class ParanoiaTest < test_framework
belongsTo
=
ParanoidModelWithBelong
.
create
belongsTo
=
ParanoidModelWithBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
notParanoidModel
=
NotParanoidModelWithBelong
.
create
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
not_paranoid_model_with_belong
=
notParanoidModel
hasOne
.
save!
hasOne
.
save!
hasOne
.
destroy
hasOne
.
destroy
...
@@ -498,6 +506,7 @@ class ParanoiaTest < test_framework
...
@@ -498,6 +506,7 @@ class ParanoiaTest < test_framework
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
notParanoidModel
.
destroyed?
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
...
@@ -509,9 +518,12 @@ class ParanoiaTest < test_framework
...
@@ -509,9 +518,12 @@ class ParanoiaTest < test_framework
belongsTo
=
ParanoidModelWithBelong
.
create
belongsTo
=
ParanoidModelWithBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
anthorClassName
=
ParanoidModelWithAnthorClassNameBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
foreignKey
=
ParanoidModelWithForeignKeyBelong
.
create
notParanoidModel
=
NotParanoidModelWithBelong
.
create
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
paranoid_model_with_belong
=
belongsTo
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
class_name_belong
=
anthorClassName
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
paranoid_model_with_foreign_key_belong
=
foreignKey
hasOne
.
not_paranoid_model_with_belong
=
notParanoidModel
hasOne
.
save!
hasOne
.
save!
hasOne
.
destroy
hasOne
.
destroy
...
@@ -524,6 +536,7 @@ class ParanoiaTest < test_framework
...
@@ -524,6 +536,7 @@ class ParanoiaTest < test_framework
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
hasOne
.
reload
.
deleted_at
.
nil?
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
belongsTo
.
reload
.
deleted_at
.
nil?
,
"
#{
belongsTo
.
deleted_at
}
"
assert_equal
true
,
notParanoidModel
.
destroyed?
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithAnthorClassNameBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be an other record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
assert
ParanoidModelWithForeignKeyBelong
.
with_deleted
.
reload
.
count
!=
0
,
"There should be a foreign_key record"
...
@@ -794,6 +807,7 @@ class ParanoidModelWithHasOne < ParanoidModel
...
@@ -794,6 +807,7 @@ class ParanoidModelWithHasOne < ParanoidModel
has_one
:paranoid_model_with_belong
,
:dependent
=>
:destroy
has_one
:paranoid_model_with_belong
,
:dependent
=>
:destroy
has_one
:class_name_belong
,
:dependent
=>
:destroy
,
:class_name
=>
"ParanoidModelWithAnthorClassNameBelong"
has_one
:class_name_belong
,
:dependent
=>
:destroy
,
:class_name
=>
"ParanoidModelWithAnthorClassNameBelong"
has_one
:paranoid_model_with_foreign_key_belong
,
:dependent
=>
:destroy
,
:foreign_key
=>
"has_one_foreign_key_id"
has_one
:paranoid_model_with_foreign_key_belong
,
:dependent
=>
:destroy
,
:foreign_key
=>
"has_one_foreign_key_id"
has_one
:not_paranoid_model_with_belong
,
:dependent
=>
:destroy
end
end
class
ParanoidModelWithBelong
<
ActiveRecord
::
Base
class
ParanoidModelWithBelong
<
ActiveRecord
::
Base
...
@@ -811,6 +825,10 @@ class ParanoidModelWithForeignKeyBelong < ActiveRecord::Base
...
@@ -811,6 +825,10 @@ class ParanoidModelWithForeignKeyBelong < ActiveRecord::Base
belongs_to
:paranoid_model_with_has_one
belongs_to
:paranoid_model_with_has_one
end
end
class
NotParanoidModelWithBelong
<
ActiveRecord
::
Base
belongs_to
:paranoid_model_with_has_one
end
class
FlaggedModel
<
PlainModel
class
FlaggedModel
<
PlainModel
acts_as_paranoid
:flag_column
=>
:is_deleted
acts_as_paranoid
:flag_column
=>
:is_deleted
end
end
...
@@ -819,6 +837,8 @@ class FlaggedModelWithCustomIndex < PlainModel
...
@@ -819,6 +837,8 @@ class FlaggedModelWithCustomIndex < PlainModel
acts_as_paranoid
:flag_column
=>
:is_deleted
,
:indexed_column
=>
:is_deleted
acts_as_paranoid
:flag_column
=>
:is_deleted
,
:indexed_column
=>
:is_deleted
end
end
class
AsplodeModel
<
ActiveRecord
::
Base
class
AsplodeModel
<
ActiveRecord
::
Base
acts_as_paranoid
acts_as_paranoid
before_destroy
do
|
r
|
before_destroy
do
|
r
|
...
...
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