Permalink
Browse files

Adding tests for the token method

  • Loading branch information...
1 parent c742400 commit 8c7d59faf3c845fc3e4ad7894095654fb7aa9e23 @paracycle committed Apr 17, 2013
Showing with 25 additions and 1 deletion.
  1. +25 −1 spec/twitter/api/oauth_spec.rb
View
26 spec/twitter/api/oauth_spec.rb
@@ -3,7 +3,31 @@
describe Twitter::API::OAuth do
before do
- @client = Twitter::Client.new
+ @client = Twitter::Client.new :consumer_key => 'CK', :consumer_secret => 'CS'
+ end
+
+ describe "#token" do
+ before do
+ # WebMock treats Basic Auth differently so we have to chack against the full url with credentials.
+ @oauth2_token_url = "https://CK:CS@api.twitter.com/oauth2/token"
+ stub_request(:post, @oauth2_token_url).with(:body => "grant_type=client_credentials").to_return(:body => '{"token_type" : "bearer", "access_token" : "AAAA%2FAAA%3DAAAAAAAA"}', :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "requests the correct resource" do
+ @client.token
+ expect(a_request(:post, @oauth2_token_url).with(:body => {:grant_type => "client_credentials"})).to have_been_made
+ end
+ it "requests with the correct headers" do
+ @client.token
+ expect(a_request(:post, @oauth2_token_url).with(:headers => {
+ :content_type => "application/x-www-form-urlencoded; charset=UTF-8",
+ :accept => "*/*"
+ })).to have_been_made
+ end
+ it "returns the bearer token" do
+ token = @client.token
+ expect(token.access_token).to eq "AAAA%2FAAA%3DAAAAAAAA"
+ expect(token.token_type).to eq "bearer"
+ end
end
describe "#invalidate_token" do

0 comments on commit 8c7d59f

Please sign in to comment.