Skip to content

Instantly share code, notes, and snippets.

@igorb
Forked from testobsessed/rspec with devise
Created July 2, 2013 17:27
Show Gist options
  • Save igorb/5911282 to your computer and use it in GitHub Desktop.
Save igorb/5911282 to your computer and use it in GitHub Desktop.
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