-
-
Save gigorok/5763545 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
# In config/initializers/local_override.rb: | |
require 'devise/strategies/authenticatable' | |
module Devise | |
module Strategies | |
class LocalOverride < Authenticatable | |
def valid? | |
true | |
end | |
def authenticate! | |
if params[:user] | |
user = User.find_by_email(params[:user][:email]) | |
if user && user.encrypted_password == params[:user][:password] | |
success!(user) | |
else | |
fail | |
end | |
else | |
fail | |
end | |
end | |
end | |
end | |
end | |
Warden::Strategies.add(:local_override, Devise::Strategies::LocalOverride) | |
# In config/initializers/devise.rb | |
config.warden do |manager| | |
manager.default_strategies(:scope => :user).unshift :local_override | |
end | |
# In spec/path_to_test_spec.rb | |
# I do this in before block or right before test executes | |
@request = mock(:request) | |
@strategy = Devise::Strategies::AndroidAuthenticatable.new(nil) | |
@request.should_receive(:headers).and_return({#hash of the headers you are testing}) | |
@strategy.should_receive(:params).at_least(:once).and_return({#hash of the params}) | |
@strategy.should_receive(:request).and_return(@request) | |
# Break these up as needed to test failing and successful | |
# strategies for your application | |
lambda { | |
@strategy.should be_valid | |
@strategy.authenticate!.should eql :success | |
}.should_not raise_error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment