Created
March 21, 2011 00:17
-
-
Save jonhoman/878820 to your computer and use it in GitHub Desktop.
Hand-rolled Twitter OAuth Stubs
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
describe "GET 'connect'" do | |
before do | |
stub_oauth_request_token! | |
end | |
it "should redirect to twitter authorization url" do | |
get 'connect' | |
session[:request_token].should == 't' | |
session[:request_token_secret].should == 's' | |
response.location.should =~ /api.twitter.com/ | |
end | |
end | |
describe "GET 'callback'" do | |
before do | |
stub_oauth_access_token! | |
end | |
it "should authenticate with twitter" do | |
get :callback, :oauth_verifier => 'some_key', :handle => 'some_handle' | |
response.should be_redirect | |
end | |
end |
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
def stub_oauth_request_token! | |
stub_request(:post, "https://api.twitter.com/oauth/request_token") | |
.to_return(:body => "oauth_token=t&oauth_token_secret=s") | |
end | |
def stub_oauth_access_token! | |
stub_request(:post, "https://api.twitter.com/oauth/access_token") | |
.to_return(:body => "oauth_token=at&oauth_token_secret=as&screen_name=sn") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment