ryanb/cancan — Issue #573: Use action_name instead of params[:action] -- specs
Author: passcod
Created: 2012-03-07 22:44:55+00:00
State: open

As per [the ActionController guide §3.3](http://guides.rubyonrails.org/action_controller_overview.html#routing-parameters), one should use the `action_name` and `controller_name` instead of retrieving them from the `params` hash like [lib/cancan/controller_resource.rb](https://github.com/ryanb/cancan/blob/master/lib/cancan/controller_resource.rb) does. However, when making that change on passcod/cancan@d6ee004019 and running the tests I found that most of them failed because `action_name` was not defined.

Digging deeper, I found that in [spec/cancan/controller_resource_spec.rb](https://github.com/passcod/cancan/blob/master/spec/cancan/controller_resource_spec.rb) the `@controller` is defined thus:

```ruby
# controller_resource_spec.rb, line 6
@controller_class = Class.new
@controller = @controller_class.new
```

How is *that* helpful to test functionality which exists in an ActionController? Surely I am missing something... wouldn't it be better to use an ActionController (sub-)class for testing -- thus making the `action_name` method available?

The underlying reason for the change is when using [param_protected](https://github.com/cjbottaro/param_protected), one needs to white-list `params[:action]` and `params[:controller]` at the ApplicationController level in order to make CanCan work. This is something I feel uncomfortable with.