-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the request spec helper method, #login_user.
- Loading branch information
1 parent
cef2ae2
commit 6782e3f
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Sorcery | ||
module TestHelpers | ||
module Rails | ||
module Request | ||
# Accepts arguments for user to login, the password, route to use and HTTP method | ||
# Defaults - @user, 'secret', 'user_sessions_url' and http_method: POST | ||
def login_user(user = nil, password = 'secret', route = nil, http_method = :post) | ||
user ||= @user | ||
route ||= user_sessions_url | ||
|
||
username_attr = user.sorcery_config.username_attribute_names.first | ||
username = user.send(username_attr) | ||
password_attr = user.sorcery_config.password_attribute_name | ||
|
||
self.send(http_method, route, params: { "#{username_attr}": username, "#{password_attr}": password }) | ||
end | ||
end | ||
end | ||
end | ||
end |