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
951d70e0
Commit
951d70e0
authored
14 years ago
by
Ryan Bates
Browse files
Options
Downloads
Patches
Plain Diff
adding :prepend option to load_and_authorize_resource - closes #290
parent
3a07d627
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/cancan/controller_additions.rb
+6
-0
6 additions, 0 deletions
lib/cancan/controller_additions.rb
lib/cancan/controller_resource.rb
+2
-1
2 additions, 1 deletion
lib/cancan/controller_resource.rb
spec/cancan/controller_additions_spec.rb
+5
-0
5 additions, 0 deletions
spec/cancan/controller_additions_spec.rb
with
13 additions
and
1 deletion
lib/cancan/controller_additions.rb
+
6
−
0
View file @
951d70e0
...
...
@@ -109,6 +109,9 @@ module CanCan
#
# load_resource :new => :build
#
# [:+prepend+]
# Passing +true+ will use prepend_before_filter instead of a normal before_filter.
#
def
load_resource
(
*
args
)
cancan_resource_class
.
add_before_filter
(
self
,
:load_resource
,
*
args
)
end
...
...
@@ -162,6 +165,9 @@ module CanCan
# [:+through+]
# Authorize conditions on this parent resource when instance isn't available.
#
# [:+prepend+]
# Passing +true+ will use prepend_before_filter instead of a normal before_filter.
#
def
authorize_resource
(
*
args
)
cancan_resource_class
.
add_before_filter
(
self
,
:authorize_resource
,
*
args
)
end
...
...
This diff is collapsed.
Click to expand it.
lib/cancan/controller_resource.rb
+
2
−
1
View file @
951d70e0
...
...
@@ -5,7 +5,8 @@ module CanCan
def
self
.
add_before_filter
(
controller_class
,
method
,
*
args
)
options
=
args
.
extract_options!
resource_name
=
args
.
first
controller_class
.
before_filter
(
options
.
slice
(
:only
,
:except
))
do
|
controller
|
before_filter_method
=
options
.
delete
(
:prepend
)
?
:prepend_before_filter
:
:before_filter
controller_class
.
send
(
before_filter_method
,
options
.
slice
(
:only
,
:except
))
do
|
controller
|
controller
.
class
.
cancan_resource_class
.
new
(
controller
,
resource_name
,
options
.
except
(
:only
,
:except
)).
send
(
method
)
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/controller_additions_spec.rb
+
5
−
0
View file @
951d70e0
...
...
@@ -42,6 +42,11 @@ describe CanCan::ControllerAdditions do
@controller_class
.
load_and_authorize_resource
:project
,
:foo
=>
:bar
end
it
"load_and_authorize_resource with :prepend should prepend the before filter"
do
mock
(
@controller_class
).
prepend_before_filter
({})
@controller_class
.
load_and_authorize_resource
:foo
=>
:bar
,
:prepend
=>
true
end
it
"authorize_resource should setup a before filter which passes call to ControllerResource"
do
stub
(
CanCan
::
ControllerResource
).
new
(
@controller
,
nil
,
:foo
=>
:bar
).
mock!
.
authorize_resource
mock
(
@controller_class
).
before_filter
(
:except
=>
:show
)
{
|
options
,
block
|
block
.
call
(
@controller
)
}
...
...
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