spec/lelylan/oauth2_spec.rb in lelylan-rb-0.0.1 vs spec/lelylan/oauth2_spec.rb in lelylan-rb-0.0.2
- old
+ new
@@ -1,54 +1,48 @@
require 'helper'
describe OAuth2 do
- let(:client_id) { '36963b6bd9dc1127553b57f55ea54d4cecf97e386bcecc5f9198e8dd0ed235f9' }
- let(:client_secret) { '8e6343a084320b6b11cdd3349642718c11af1af9b9f64ed4976018bdf20d0082' }
- let(:redirect_uri) { 'http://app.dev/callback' }
- let(:site_uri) { 'http://app.dev' }
- let(:application) { OAuth2::Client.new client_id, client_secret, site: site_uri }
+ let(:application) { OAuth2::Client.new 'client-id', 'client-secret', site: 'http://oauth2.dev' }
let(:json_token) { MultiJson.load fixture('oauth2/token.json').read }
let(:token) { OAuth2::AccessToken.from_hash application, json_token }
+ let(:lelylan) { Lelylan::Client.new token: token }
+ let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
+ let(:redirect_uri) { 'http://app.dev/callback' }
- let(:client) { Lelylan::Client.new token: token }
- let(:path) { '/types/4dcb9e23d033a9088900000a' }
- let(:uri) { "http://api.lelylan.com/#{path}" }
- let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
-
context 'with not expired token' do
- before { stub_get(path).with(headers: headers).to_return(body: fixture('type.json')) }
- before { client.type uri }
+ before { stub_get('/devices/1').with(headers: headers).to_return(body: fixture('device.json')) }
+ before { lelylan.device('1') }
it 'adds the oauth2 token in the header' do
- a_get(path).with(headers: headers).should have_been_made
+ a_get('/devices/1').with(headers: headers).should have_been_made
end
end
context 'with expired token' do
- let(:refresh_uri) { "#{site_uri}/oauth/token" }
- let(:refresh_token) { MultiJson.load fixture('oauth2/refresh.json').read }
+ let(:refresh_uri) { 'http://oauth2.dev/oauth/token' }
let(:refresh_headers) { { 'Content-Type' => 'application/json' } }
+ let(:refresh_token) { MultiJson.load fixture('oauth2/refresh.json').read }
let(:headers) { { 'Authorization' => "Bearer #{refresh_token['access_token']}" } }
let(:refresh_body) {{
- client_id: client_id,
- client_secret: client_secret,
+ client_id: 'client-id',
+ client_secret: 'client-secret',
grant_type: 'refresh_token',
refresh_token: token.refresh_token
}}
before { stub_post(refresh_uri).with(body: refresh_body).to_return(headers: refresh_headers, body: refresh_token) }
- before { stub_get(path).with(headers: headers).to_return(body: fixture('type.json')) }
+ before { stub_get('/devices/1').with(headers: headers).to_return(body: fixture('device.json')) }
before { token.instance_variable_set '@expires_at', 0 }
it 'expires token' do
token.expired?.should == true
end
it 'refreshes token' do
- expect{ client.type uri }.to change{ client.token.token }
+ expect{ lelylan.device('1') }.to change{ lelylan.token.token }
end
end
end