Skip to content

Instantly share code, notes, and snippets.

@rodrigoflores
Created December 9, 2010 17:53
Show Gist options
  • Save rodrigoflores/735058 to your computer and use it in GitHub Desktop.
Save rodrigoflores/735058 to your computer and use it in GitHub Desktop.
#Omniauth initializer
module OmniAuth
module Strategy #:nodoc:
def initialize(app, name, *args)
@app = app
@name = name.to_sym
@options = args.last.is_a?(Hash) ? args.pop : {}
yield self if block_given?
end
end
end
module OmniAuth
mattr_accessor :facebook_strategy
@@facebook_strategy = nil
end
# config/environment.rb
middleware.use Facebook, "FOO", "BAR" do |strategy|
OmniAuth.facebook_strategy = strategy
end
# integration test
FACEBOOK_INFO = {
:id => '12345',
:link => 'http://facebook.com/josevalim',
:email => 'user@example.com',
:first_name => 'Jose',
:last_name => 'Valim',
:website => 'http://blog.plataformatec.com.br'
}
ACCESS_TOKEN = {
:access_token => "plataformatec"
}
stubs = Faraday::Adapter::Test::Stubs.new do |b|
b.post('/oauth/access_token') { [200, {}, ACCESS_TOKEN.to_json] }
b.get('/me?access_token=plataformatec') { [200, {}, FACEBOOK_INFO.to_json] }
end
OmniAuth.facebook_strategy.client.connection.build do |b|
b.adapter :test, stubs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment