Class: DerailedBenchmarks::AuthHelpers::Devise
- Inherits:
-
DerailedBenchmarks::AuthHelper
- Object
- DerailedBenchmarks::AuthHelper
- DerailedBenchmarks::AuthHelpers::Devise
- Defined in:
- lib/derailed_benchmarks/auth_helpers/devise.rb
Overview
Devise helper for authenticating requests Setup adds necessarry test methods, user provides a sample user. The authenticate method is called on every request when authentication is enabled
Instance Attribute Summary collapse
Attributes inherited from DerailedBenchmarks::AuthHelper
Instance Method Summary collapse
-
#call(env) ⇒ Object
Logs the user in, then call the parent app.
-
#setup ⇒ Object
Include devise test helpers and turn on test mode We need to do this on the class level.
Methods inherited from DerailedBenchmarks::AuthHelper
Instance Attribute Details
#user ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/derailed_benchmarks/auth_helpers/devise.rb', line 23 def user if @user @user = @user.call if @user.is_a?(Proc) @user else password = SecureRandom.hex @user = User.first_or_create!(email: "#{SecureRandom.hex}@example.com", password: password, password_confirmation: password) end end |
Instance Method Details
#call(env) ⇒ Object
Logs the user in, then call the parent app
34 35 36 37 |
# File 'lib/derailed_benchmarks/auth_helpers/devise.rb', line 34 def call(env) login_as(user) app.call(env) end |
#setup ⇒ Object
Include devise test helpers and turn on test mode We need to do this on the class level
13 14 15 16 17 18 19 20 21 |
# File 'lib/derailed_benchmarks/auth_helpers/devise.rb', line 13 def setup # self.class.instance_eval do require 'devise' require 'warden' extend ::Warden::Test::Helpers extend ::Devise::TestHelpers Warden.test_mode! # end end |