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
6881e750
Commit
6881e750
authored
Nov 13, 2014
by
Braden Anderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
raise error for acts_as_paranoid on models without primary keys
see
https://github.com/radar/paranoia/issues/169
parent
ba0e7b92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
lib/paranoia.rb
+1
-0
test/paranoia_test.rb
+10
-0
No files found.
lib/paranoia.rb
View file @
6881e750
...
...
@@ -154,6 +154,7 @@ end
class
ActiveRecord
::
Base
def
self
.
acts_as_paranoid
(
options
=
{})
raise
"primary key required for "
+
self
.
name
unless
self
.
primary_key
alias
:destroy!
:destroy
alias
:delete!
:delete
def
really_destroy!
...
...
test/paranoia_test.rb
View file @
6881e750
...
...
@@ -28,6 +28,7 @@ def connect!
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE custom_column_models (id INTEGER NOT NULL PRIMARY KEY, destroyed_at DATETIME)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE custom_sentinel_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME NOT NULL)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE non_paranoid_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER)'
ActiveRecord
::
Base
.
connection
.
execute
'CREATE TABLE idless_models (deleted_at DATETIME)'
end
class
WithDifferentConnection
<
ActiveRecord
::
Base
...
...
@@ -620,6 +621,12 @@ class ParanoiaTest < test_framework
assert_equal
3
,
parent
.
very_related_models
.
size
end
def
test_model_without_primary_key
assert_raises
(
RuntimeError
)
do
IdlessModel
.
class_eval
{
acts_as_paranoid
}
end
end
private
def
get_featureful_model
FeaturefulModel
.
new
(
:name
=>
"not empty"
)
...
...
@@ -758,3 +765,6 @@ class AsplodeModel < ActiveRecord::Base
raise
StandardError
,
'ASPLODE!'
end
end
class
IdlessModel
<
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