In the docs for using the Devise TestHelpers it states to use lines such as...
@request.env["devise.mapping"] = Devise.mappings[:admin]
or
@request.env["devise.mapping"] = Devise.mappings[:user]
...to let Devise know which resource or mapping to use since the controller tests bypass routes.rb. I am not clear on what these mappings are. I have not set up anything special in this regard, and I do not have a specific mapping in mind. I have User, Admin, Refinery, and Superuser roles, a la Rolify, and I am using Cancan for its abilities.
Can you clarify? ...perhaps the resource name is what us meant?
TIA. -Matt
Since waiting for an answer, my research seems to indicate that the mapping indicated in the documentation is actually referring to the resource against which Devise is attached.
Following is speculative on my part, but it appears to work, and it agrees with my scan of the code. For example, if you have only one resource called User you have used Devise for authenticating, you would only need to use the following in your controller spec setup:
@request.env["devise.mapping"] = Devise.mappings[:user]
However, if you have multiple models you are authenticating against, say User and Admin, you would need to use the following, respectively.
@request.env["devise.mapping"] = Devise.mappings[:user]
and
@request.env["devise.mapping"] = Devise.mappings[:admin]
Please feel free to update this question/answer if you have better input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With