24 行
810 B
Ruby
24 行
810 B
Ruby
module AuthHelper
|
|
def cookie_headers(user)
|
|
env = Rails.application.env_config.merge(Rack::MockRequest.env_for('/'))
|
|
endpoint = lambda do |request_env|
|
|
ActionDispatch::Request.new(request_env).session[:inheritance_code] = user.inheritance_code
|
|
[200, {}, []]
|
|
end
|
|
store = ActionDispatch::Session::CookieStore.new(
|
|
endpoint, Rails.application.config.session_options)
|
|
headers = ActionDispatch::Cookies.new(store).call(env)[1]
|
|
{ 'Cookie' => Array(headers['set-cookie']).map { _1.split(';').first }.join('; ') }
|
|
end
|
|
|
|
def sign_in_as(user)
|
|
allow_any_instance_of(ApplicationController)
|
|
.to receive(:current_user).and_return(user)
|
|
end
|
|
|
|
def sign_out
|
|
allow_any_instance_of(ApplicationController)
|
|
.to receive(:current_user).and_return(nil)
|
|
end
|
|
end
|