Skip to content

Commit

Permalink
Cleanup improved #exchange_code_for_token specs
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyw committed Mar 17, 2014
1 parent 3ae2c79 commit e230ac0
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions spec/octokit/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,38 +217,29 @@
end
end # .subscriptions

describe '.exchange_code_for_token' do
context 'with preconfigured client credentials' do
it 'returns the access_token (w/o client)' do
VCR.turn_off!
post = stub_request(:post, "https://github.com/login/oauth/access_token").
with(:headers => {
:accept => "application/json",
:content_type => "application/json"
}, :body => "{\"code\":\"code\",\"client_id\":null,\"client_secret\":null}").
describe ".exchange_code_for_token" do
context "with application authenticated client" do
it "returns the access_token" do
client = Octokit::Client.new({client_id: '123', client_secret: '345'})
request = stub_post("https://github.com/login/oauth/access_token?client_id=123&client_secret=345").
with(:body => {:code=>"code", :client_id=>"123", :client_secret=>"345"}.to_json).
to_return(json_response("web_flow_token.json"))
response = Octokit.exchange_code_for_token('code')
expect(response.access_token).to eq 'this_be_ye_token/use_it_wisely'
assert_requested post
VCR.turn_on!
response = client.exchange_code_for_token("code")
expect(response.access_token).to eq "this_be_ye_token/use_it_wisely"
assert_requested request
end
end
end # with application authenticated client

context 'with passed client credentials' do
context 'with credentials passed as parameters by unauthed client' do
it 'returns the access_token' do
VCR.turn_off!
client = Octokit::Client.new
post = stub_request(:post, "https://github.com/login/oauth/access_token").
with(:headers => {
:accept => "application/json",
:content_type => "application/json"
}, :body => "{\"code\":\"code\",\"client_id\":\"id_here\",\"client_secret\":\"secret_here\"}").
with(:body => {:code=>"code", :client_id=>"id", :client_secret=>"secret"}.to_json).
to_return(json_response("web_flow_token.json"))
response = Octokit.exchange_code_for_token('code', 'id_here', 'secret_here')
response = client.exchange_code_for_token('code', 'id', 'secret')
expect(response.access_token).to eq 'this_be_ye_token/use_it_wisely'
assert_requested post
VCR.turn_on!
end
end
end # .access_token

end # with credentials passed as parameters
end # .exchange_code_for_token
end

0 comments on commit e230ac0

Please sign in to comment.