Created
January 5, 2015 03:36
-
-
Save jimmylorunning/26cfa271d9c6fa4831d1 to your computer and use it in GitHub Desktop.
stubbing devise authentication
This file contains 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
module ControllerHelpers | |
def sign_in(user = double('user')) | |
if user.nil? | |
allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user}) | |
allow(controller).to receive(:current_user).and_return(nil) | |
else | |
allow(request.env['warden']).to receive(:authenticate!).and_return(user) | |
allow(controller).to receive(:current_user).and_return(user) | |
end | |
end | |
end | |
RSpec.configure do |config| | |
config.include Devise::TestHelpers, :type => :controller | |
config.include ControllerHelpers, :type => :controller | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment