Devise :: TestHelpers docs fuzzy description Devise.mappings [: mapping]

The docs for using Devise TestHelpers indicate the use of strings like ...

@request.env["devise.mapping"] = Devise.mappings[:admin] 

or

 @request.env["devise.mapping"] = Devise.mappings[:user] 

... so that Devise finds out which resource or mapping to use, as the controller checks for .rb route bypass. I do not understand what these comparisons are. I have not created anything special in this regard, and I have no specific mapping. I have the roles of user, administrator, refinery and superuser, a la Rolify, and I use Cancan for its capabilities.

Can you clarify? ... maybe the name of the resource is what we had in mind?

TIA. Matt

+7
source share
1 answer

Since I am waiting for an answer, my research shows that the mapping indicated in the documentation actually refers to the resource to which the application is attached.

The following is speculative on my part, but it seems to work, and it is consistent with my code review. For example, if you have only one resource called User, which you used Devise for authentication, you will need to use only the following settings in your controller settings:

 @request.env["devise.mapping"] = Devise.mappings[:user] 

However, if you have several models that you authenticate to, say, a user and an administrator, you will 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 a better input.

+9
source

All Articles