class DerailedBenchmarks::AuthHelpers::Devise
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
Attributes
user[W]
Public Instance Methods
call(env)
click to toggle source
Logs the user in, then call the parent app
# File lib/derailed_benchmarks/auth_helpers/devise.rb, line 34 def call(env) login_as(user) app.call(env) end
setup()
click to toggle source
Include devise test helpers and turn on test mode We need to do this on the class level
# 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
user()
click to toggle source
# 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