Last active
August 29, 2015 14:21
-
-
Save Slike9/181794bd6ba5b7b3eda8 to your computer and use it in GitHub Desktop.
warden controller test helper
This file contains hidden or 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
require 'warden/test/helpers' | |
# Usage: | |
# rspec: | |
# config.include Helpers::Controllers::Auth, type: :controller | |
# | |
module Helpers | |
module Controllers | |
module Auth | |
extend ActiveSupport::Concern | |
included do | |
before do | |
warden_manager = Warden::Manager.new(nil) | |
warden_proxy = Warden::Proxy.new(request.env, warden_manager) | |
request.env['warden'] = warden_proxy | |
end | |
end | |
def sign_in(user=nil) | |
user ||= build :user | |
request.env['warden'].set_user(user) | |
end | |
def current_user | |
controller.current_user | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment