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
7d3b4cdb
Commit
7d3b4cdb
authored
15 years ago
by
Ryan Bates
Browse files
Options
Downloads
Patches
Plain Diff
Adding clear_aliased_actions to Ability which removes previously defined actions including defaults
parent
f99d5060
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
CHANGELOG.rdoc
+2
-0
2 additions, 0 deletions
CHANGELOG.rdoc
lib/cancan/ability.rb
+8
-2
8 additions, 2 deletions
lib/cancan/ability.rb
spec/cancan/ability_spec.rb
+8
-8
8 additions, 8 deletions
spec/cancan/ability_spec.rb
with
18 additions
and
10 deletions
CHANGELOG.rdoc
+
2
−
0
View file @
7d3b4cdb
* Adding clear_aliased_actions to Ability which removes previously defined actions including defaults - see issue #20
* Append aliased actions (don't overwrite them) - see issue #20
* Append aliased actions (don't overwrite them) - see issue #20
* Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18
* Adding custom message argument to unauthorized! method (thanks tjwallace) - see issue #18
...
...
This diff is collapsed.
Click to expand it.
lib/cancan/ability.rb
+
8
−
2
View file @
7d3b4cdb
...
@@ -160,12 +160,18 @@ module CanCan
...
@@ -160,12 +160,18 @@ module CanCan
aliased_actions
[
target
]
+=
args
aliased_actions
[
target
]
+=
args
end
end
private
# Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
def
aliased_actions
def
aliased_actions
@aliased_actions
||=
default_alias_actions
@aliased_actions
||=
default_alias_actions
end
end
# Removes previously aliased actions including the defaults.
def
clear_aliased_actions
@aliased_actions
=
{}
end
private
def
default_alias_actions
def
default_alias_actions
{
{
:read
=>
[
:index
,
:show
],
:read
=>
[
:index
,
:show
],
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/ability_spec.rb
+
8
−
8
View file @
7d3b4cdb
...
@@ -49,9 +49,7 @@ describe CanCan::Ability do
...
@@ -49,9 +49,7 @@ describe CanCan::Ability do
it
"should alias update or destroy actions to modify action"
do
it
"should alias update or destroy actions to modify action"
do
@ability
.
alias_action
:update
,
:destroy
,
:to
=>
:modify
@ability
.
alias_action
:update
,
:destroy
,
:to
=>
:modify
@ability
.
can
:modify
,
:all
do
|
object_class
,
object
|
@ability
.
can
(
:modify
,
:all
)
{
:modify_called
}
:modify_called
end
@ability
.
can?
(
:update
,
123
).
should
==
:modify_called
@ability
.
can?
(
:update
,
123
).
should
==
:modify_called
@ability
.
can?
(
:destroy
,
123
).
should
==
:modify_called
@ability
.
can?
(
:destroy
,
123
).
should
==
:modify_called
end
end
...
@@ -126,10 +124,12 @@ describe CanCan::Ability do
...
@@ -126,10 +124,12 @@ describe CanCan::Ability do
it
"should append aliased actions"
do
it
"should append aliased actions"
do
@ability
.
alias_action
:update
,
:to
=>
:modify
@ability
.
alias_action
:update
,
:to
=>
:modify
@ability
.
alias_action
:destroy
,
:to
=>
:modify
@ability
.
alias_action
:destroy
,
:to
=>
:modify
@ability
.
can
:modify
,
:all
do
|
object_class
,
object
|
@ability
.
aliased_actions
[
:modify
].
should
==
[
:update
,
:destroy
]
:modify_called
end
end
@ability
.
can?
(
:update
,
123
).
should
==
:modify_called
it
"should clear aliased actions"
do
@ability
.
can?
(
:destroy
,
123
).
should
==
:modify_called
@ability
.
alias_action
:update
,
:to
=>
:modify
@ability
.
clear_aliased_actions
@ability
.
aliased_actions
[
:modify
].
should
be_nil
end
end
end
end
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