-
-
Save igorb/5911282 to your computer and use it in GitHub Desktop.
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
def login_as(user) | |
raise "Was expecting a User. Got a #{user.class} instead. Exiting." if user.class != User | |
@controller.request.env['warden'] = mock( | |
Warden, | |
:authenticate => user, | |
:authenticate! => user, | |
:authenticated? => true, | |
:authenticate? => true | |
) | |
user.last_sign_in_at = Time.now | |
user.save! | |
end | |
def logout | |
@controller.stub(:current_user) { nil } | |
end | |
def stub_user_for_helper | |
# TODO: this is probably NOT the right way to do this - but couldn't find Devise::TestHelpers to do this | |
# would be nice to clean this up - make it just part of the context instead of needing to be | |
# explicitly called in the :before block. | |
helper.stub(:current_user) {nil} | |
helper.stub(:user_signed_in?) {false} | |
end | |
RSpec.configure do |config| | |
config.include Devise::TestHelpers, :type => :controller | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment