Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cancan
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Github Mirror
coopdevs
cancan
Commits
e3ba6688
Commit
e3ba6688
authored
12 years ago
by
jan
Browse files
Options
Downloads
Patches
Plain Diff
added support for nested join conditions
parent
3f4ee120
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cancan/model_adapters/active_record_adapter.rb
+14
-3
14 additions, 3 deletions
lib/cancan/model_adapters/active_record_adapter.rb
spec/cancan/model_adapters/active_record_adapter_spec.rb
+10
-0
10 additions, 0 deletions
spec/cancan/model_adapters/active_record_adapter_spec.rb
with
24 additions
and
3 deletions
lib/cancan/model_adapters/active_record_adapter.rb
+
14
−
3
View file @
e3ba6688
...
...
@@ -66,11 +66,22 @@ module CanCan
return
conditions
unless
conditions
.
kind_of?
Hash
conditions
.
inject
({})
do
|
result_hash
,
(
name
,
value
)
|
if
value
.
kind_of?
Hash
value
=
value
.
dup
association_class
=
model_class
.
reflect_on_association
(
name
).
class_name
.
constantize
name
=
model_class
.
reflect_on_association
(
name
).
table_name
.
to_sym
value
=
tableized_conditions
(
value
,
association_class
)
nested
=
value
.
inject
({})
do
|
nested
,(
k
,
v
)
|
if
v
.
kind_of?
Hash
value
.
delete
(
k
)
nested
[
k
]
=
v
else
name
=
model_class
.
reflect_on_association
(
name
).
table_name
.
to_sym
result_hash
[
name
]
=
value
end
nested
end
result_hash
.
merge!
(
tableized_conditions
(
nested
,
association_class
))
else
result_hash
[
name
]
=
value
end
result_hash
[
name
]
=
value
result_hash
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/model_adapters/active_record_adapter_spec.rb
+
10
−
0
View file @
e3ba6688
...
...
@@ -207,6 +207,16 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
@ability
.
model_adapter
(
Article
,
:read
).
conditions
.
should
==
"'t'='t'"
end
it
"should return appropriate sql conditions in complex case with nested joins"
do
@ability
.
can
:read
,
Comment
,
:article
=>
{
:category
=>
{
:visible
=>
true
}
}
@ability
.
model_adapter
(
Comment
,
:read
).
conditions
.
should
==
{
Category
.
table_name
.
to_sym
=>
{
:visible
=>
true
}
}
end
it
"should return appropriate sql conditions in complex case with nested joins of different depth"
do
@ability
.
can
:read
,
Comment
,
:article
=>
{
:published
=>
true
,
:category
=>
{
:visible
=>
true
}
}
@ability
.
model_adapter
(
Comment
,
:read
).
conditions
.
should
==
{
Article
.
table_name
.
to_sym
=>
{
:published
=>
true
},
Category
.
table_name
.
to_sym
=>
{
:visible
=>
true
}
}
end
it
"should not forget conditions when calling with SQL string"
do
@ability
.
can
:read
,
Article
,
:published
=>
true
@ability
.
can
:read
,
Article
,
[
'secret=?'
,
false
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment