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
f173454b
Commit
f173454b
authored
Jul 01, 2015
by
Marcus Ilgner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix uniqueness validator for non-paranoid associations
parent
7098750c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletions
+27
-1
lib/paranoia.rb
+5
-1
test/paranoia_test.rb
+22
-0
No files found.
lib/paranoia.rb
View file @
f173454b
...
...
@@ -250,7 +250,11 @@ module ActiveRecord
protected
def
build_relation_with_paranoia
(
klass
,
table
,
attribute
,
value
)
relation
=
build_relation_without_paranoia
(
klass
,
table
,
attribute
,
value
)
relation
.
and
(
klass
.
arel_table
[
klass
.
paranoia_column
].
eq
(
nil
))
if
klass
.
respond_to?
(
:paranoia_column
)
relation
.
and
(
klass
.
arel_table
[
klass
.
paranoia_column
].
eq
(
nil
))
else
relation
end
end
alias_method_chain
:build_relation
,
:paranoia
end
...
...
test/paranoia_test.rb
View file @
f173454b
...
...
@@ -37,6 +37,7 @@ def setup!
'polymorphic_models'
=>
'parent_id INTEGER, parent_type STRING, deleted_at DATETIME'
,
'namespaced_paranoid_has_ones'
=>
'deleted_at DATETIME, paranoid_belongs_tos_id INTEGER'
,
'namespaced_paranoid_belongs_tos'
=>
'deleted_at DATETIME, paranoid_has_one_id INTEGER'
,
'unparanoid_unique_models'
=>
'name VARCHAR(32), paranoid_with_unparanoids_id INTEGER'
}.
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
}
)"
end
...
...
@@ -821,6 +822,13 @@ class ParanoiaTest < test_framework
# assert related_model.instance_variable_get(:@after_commit_on_destroy_callback_called)
end
def
test_uniqueness_for_unparanoid_associated
parent_model
=
ParanoidWithUnparanoids
.
create
related
=
parent_model
.
unparanoid_unique_models
.
create
# will raise exception if model is not checked for paranoia
related
.
valid?
end
# TODO: find a fix for Rails 4.1
if
ActiveRecord
::
VERSION
::
STRING
!~
/\A4\.1/
def
test_counter_cache_column_update_on_really_destroy
...
...
@@ -862,6 +870,16 @@ class ParanoidModel < ActiveRecord::Base
acts_as_paranoid
end
class
ParanoidWithUnparanoids
<
ActiveRecord
::
Base
self
.
table_name
=
'plain_models'
has_many
:unparanoid_unique_models
end
class
UnparanoidUniqueModel
<
ActiveRecord
::
Base
belongs_to
:paranoid_with_unparanoids
validates
:name
,
:uniqueness
=>
true
end
class
FailCallbackModel
<
ActiveRecord
::
Base
belongs_to
:parent_model
acts_as_paranoid
...
...
@@ -874,6 +892,10 @@ class FeaturefulModel < ActiveRecord::Base
validates
:name
,
:presence
=>
true
,
:uniqueness
=>
true
end
class
NonParanoidChildModel
<
ActiveRecord
::
Base
validates
:name
,
:presence
=>
true
,
:uniqueness
=>
true
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