Created
February 10, 2011 18:22
-
-
Save dpickett/821031 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class TestOmniAuth | |
| attr_reader :app, :env | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| @env = env | |
| if request.path =~ /auth\/facebook\/callback/ | |
| omniauth_hash = { | |
| 'uid' => '1234', | |
| 'provider' => 'facebook', | |
| 'user_info' => { | |
| 'id' => '1234', | |
| 'link' => 'http://facebook.com/foo', | |
| 'email' => '[email protected]', | |
| 'first_name'=> 'Foo', | |
| 'last_name' => 'Bar', | |
| 'website' => 'http://example.com' | |
| } | |
| } | |
| @env['omniauth.auth'] = omniauth_hash | |
| @app.call(env) | |
| elsif request.path =~ /auth\/facebook$/ | |
| r = Rack::Response.new("") | |
| r.redirect "http://www.example.com/auth/facebook/callback" | |
| r.finish | |
| else | |
| @app.call(env) | |
| end | |
| end | |
| def request | |
| @request ||= Rack::Request.new(@env) | |
| end | |
| def full_host | |
| uri = URI.parse(request.url) | |
| uri.path = '' | |
| uri.query = nil | |
| uri.to_s | |
| end | |
| end | |
| Around('@stub_facebook') do |scenario, block| | |
| class OmniAuth::Builder | |
| alias_method :orig_call, :call | |
| def call(env) | |
| TestOmniAuth.new(@app).call(env) | |
| end | |
| end | |
| #for some reason this doesn't work | |
| Rails.application.config.middleware.swap OmniAuth::Builder, TestOmniAuth | |
| result = block.call | |
| class OmniAuth::Builder | |
| alias_method :call, :orig_call | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment