Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Mocking warden in controller specs

View spec_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
module RandomHelpers
def random_number() SecureRandom.random_number(10000); end
def random_id() random_number; end
def random_name() SecureRandom.hex(20); end
end
 
module ControllerHelpers
def user_double(attrs = {})
user_attrs = {
:first_name => random_name,
:last_name => random_name,
:authenticatable_salt => 'x'
}.merge(attrs)
mock_model(User, user_attrs)
end
 
def stub_sign_in_with(user)
request.env['warden'] = double(Warden,
:authenticate => user,
:authenticate! => user,
:authenticate? => true)
sign_in(user)
return user
end
 
def stub_sign_in(attrs = {})
stub_sign_in_with user_double(attrs)
end
end
 
RSpec.configure do |config|
config.include RandomHelpers
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
Something went wrong with that request. Please try again.