Module: Sorcery::TestHelpers::Rails::Request
- Defined in:
- lib/sorcery/test_helpers/rails/request.rb
Instance Method Summary collapse
-
#login_user(user = nil, password = 'secret', route = nil, http_method = :post) ⇒ Object
Accepts arguments for user to login, the password, route to use and HTTP method Defaults - @user, ‘secret’, ‘user_sessions_url’ and http_method: POST.
Instance Method Details
#login_user(user = nil, password = 'secret', route = nil, http_method = :post) ⇒ Object
Accepts arguments for user to login, the password, route to use and HTTP method Defaults - @user, ‘secret’, ‘user_sessions_url’ and http_method: POST
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sorcery/test_helpers/rails/request.rb', line 7 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 send(http_method, route, params: { "#{username_attr}": username, "#{password_attr}": password }) end |