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
d6163b5d
Commit
d6163b5d
authored
May 12, 2011
by
donv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* Added query to ask a class or instance if it is paranoid
* Added test setup
parent
9879f78f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
Rakefile
+7
-0
lib/paranoia.rb
+11
-0
test/paranoia_test.rb
+40
-0
No files found.
Rakefile
View file @
d6163b5d
require
'bundler'
require
'bundler'
Bundler
::
GemHelper
.
install_tasks
Bundler
::
GemHelper
.
install_tasks
task
:test
do
Dir
[
'test/*_test.rb'
].
each
do
|
testfile
|
load
testfile
end
end
\ No newline at end of file
lib/paranoia.rb
View file @
d6163b5d
module
Paranoia
module
Paranoia
def
self
.
included
(
klazz
)
klazz
.
extend
Query
end
module
Query
def
paranoid?
;
true
;
end
end
def
destroy
def
destroy
_run_destroy_callbacks
_run_destroy_callbacks
self
[
:deleted_at
]
||=
Time
.
now
self
[
:deleted_at
]
||=
Time
.
now
...
@@ -17,4 +25,7 @@ class ActiveRecord::Base
...
@@ -17,4 +25,7 @@ class ActiveRecord::Base
self
.
send
(
:include
,
Paranoia
)
self
.
send
(
:include
,
Paranoia
)
default_scope
:conditions
=>
{
:deleted_at
=>
nil
}
default_scope
:conditions
=>
{
:deleted_at
=>
nil
}
end
end
def
self
.
paranoid?
;
false
;
end
def
paranoid?
;
self
.
class
.
paranoid?
;
end
end
end
test/paranoia_test.rb
0 → 100644
View file @
d6163b5d
require
'test/unit'
require
'active_record'
require
'lib/paranoia'
DB_FILE
=
'tmp/test_db'
FileUtils
.
mkdir_p
File
.
dirname
(
DB_FILE
)
FileUtils
.
rm_f
DB_FILE
ActiveRecord
::
Base
.
establish_connection
:adapter
=>
'sqlite3'
,
:database
=>
DB_FILE
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY)'
class
ParanoiaTest
<
Test
::
Unit
::
TestCase
def
test_plain_model_class_is_not_paranoid
assert_equal
false
,
PlainModel
.
paranoid?
end
def
test_paranoid_model_class_is_paranoid
assert_equal
true
,
ParanoidModel
.
paranoid?
end
def
test_plain_models_are_not_paranoid
assert_equal
false
,
PlainModel
.
new
.
paranoid?
end
def
test_paranoid_models_are_paranoid
assert_equal
true
,
ParanoidModel
.
new
.
paranoid?
end
end
# Helper classes
class
ParanoidModel
<
ActiveRecord
::
Base
acts_as_paranoid
end
class
PlainModel
<
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