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
4339ac65
Commit
4339ac65
authored
14 years ago
by
Ryan Bates
Browse files
Options
Downloads
Patches
Plain Diff
improve support for rspec scaffolding (thanks voxik) - closes #176
parent
5e1e6e18
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cancan/controller_resource.rb
+5
-7
5 additions, 7 deletions
lib/cancan/controller_resource.rb
spec/cancan/controller_resource_spec.rb
+1
-1
1 addition, 1 deletion
spec/cancan/controller_resource_spec.rb
with
6 additions
and
8 deletions
lib/cancan/controller_resource.rb
+
5
−
7
View file @
4339ac65
...
...
@@ -61,20 +61,18 @@ module CanCan
end
def
build_resource
if
@options
[
:singleton
]
&&
resource_base
.
respond_to?
(
"build_
#{
name
}
"
)
resource
=
resource_base
.
send
(
"build_
#{
name
}
"
)
else
resource
=
resource_base
.
send
(
"new"
)
end
method_name
=
@options
[
:singleton
]
&&
resource_base
.
respond_to?
(
"build_
#{
name
}
"
)
?
"build_
#{
name
}
"
:
"new"
resource
=
resource_base
.
send
(
method_name
,
@params
[
name
]
||
{})
initial_attributes
.
each
do
|
name
,
value
|
resource
.
send
(
"
#{
name
}
="
,
value
)
end
resource
.
attributes
=
@params
[
name
]
if
@params
[
name
]
resource
end
def
initial_attributes
current_ability
.
attributes_for
(
@params
[
:action
].
to_sym
,
resource_class
)
current_ability
.
attributes_for
(
@params
[
:action
].
to_sym
,
resource_class
).
delete_if
do
|
key
,
value
|
@params
[
name
]
&&
@params
[
name
].
include?
(
key
)
end
end
def
find_resource
...
...
This diff is collapsed.
Click to expand it.
spec/cancan/controller_resource_spec.rb
+
1
−
1
View file @
4339ac65
...
...
@@ -245,7 +245,7 @@ describe CanCan::ControllerResource do
@params
.
merge!
(
:action
=>
"create"
,
:project
=>
{
:name
=>
"foobar"
})
category
=
Object
.
new
@controller
.
instance_variable_set
(
:@category
,
category
)
stub
(
category
).
build_project
{
Project
.
new
}
stub
(
category
).
build_project
{
|
attributes
|
Project
.
new
(
attributes
)
}
resource
=
CanCan
::
ControllerResource
.
new
(
@controller
,
:through
=>
:category
,
:singleton
=>
true
)
resource
.
load_resource
@controller
.
instance_variable_get
(
:@project
).
name
.
should
==
"foobar"
...
...
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