spec/lelylan/client/subscription_spec.rb in lelylan-rb-0.0.3 vs spec/lelylan/client/subscription_spec.rb in lelylan-rb-0.0.4
- old
+ new
@@ -11,11 +11,11 @@
end
describe '#subscription' do
before do
- stub_get('/subscriptions/1').to_return(body: fixture('subscription.json'))
+ stub_request(:get, 'http://id:secret@api.lelylan.com/subscriptions/1').to_return(body: fixture('subscription.json'))
end
let!(:subscription) do
lelylan.subscription('1')
end
@@ -23,19 +23,19 @@
it 'returns the subscription' do
subscription.id.should_not be_nil
end
it 'sends the request' do
- a_get('/subscriptions/1').with(headers: { Authorization: basic }).should have_been_made
+ a_request(:get, 'http://id:secret@api.lelylan.com/subscriptions/1').should have_been_made
end
end
describe '#subscriptions' do
before do
- stub_get('/subscriptions').to_return(body: fixture('subscriptions.json'))
+ stub_request(:get, 'http://id:secret@api.lelylan.com/subscriptions').to_return(body: fixture('subscriptions.json'))
end
let!(:subscriptions) do
lelylan.subscriptions
end
@@ -43,74 +43,74 @@
it 'returns a list of subscriptions' do
subscriptions.should have(1).item
end
it 'sends the request' do
- a_get('/subscriptions').with(headers: { Authorization: basic }).should have_been_made
+ a_request(:get, 'http://id:secret@api.lelylan.com/subscriptions').should have_been_made
end
context 'with params' do
before do
- stub_get('/subscriptions').with(query: { per: '25' }).to_return(body: fixture('subscription.json'))
+ stub_request(:get, 'http://id:secret@api.lelylan.com/subscriptions').with(query: { per: '25' }).to_return(body: fixture('subscription.json'))
end
before do
lelylan.subscriptions(per: 25)
end
it 'sends the params' do
- a_get('/subscriptions').with(headers: { Authorization: basic }).with(query: { per: '25' }).should have_been_made
+ a_request(:get, 'http://id:secret@api.lelylan.com/subscriptions').with(query: { per: '25' }).should have_been_made
end
end
end
describe '#create_subscription' do
before do
- stub_post('/subscriptions').with(headers: { Authorization: basic }).with(body: { name: 'Bedroom' }).to_return(body: fixture('subscription.json'))
+ stub_request(:post, 'http://id:secret@api.lelylan.com/subscriptions').with(body: { event: 'property-update' }).to_return(body: fixture('subscription.json'))
end
let!(:subscription) do
- lelylan.create_subscription(name: 'Bedroom')
+ lelylan.create_subscription(event: 'property-update')
end
it 'returns the subscription' do
subscription.id.should_not be_nil
end
it 'sends the request' do
- a_post('/subscriptions').with(headers: { Authorization: basic }).with(body: { name: 'Bedroom' }).should have_been_made
+ a_request(:post, 'http://id:secret@api.lelylan.com/subscriptions').with(body: { event: 'property-update' }).should have_been_made
end
end
describe '#update_subscription' do
before do
- stub_put('/subscriptions/1').with(body: { name: 'Bedroom' }).to_return(body: fixture('subscription.json'))
+ stub_request(:put, 'http://id:secret@api.lelylan.com/subscriptions/1').with(body: { event: 'delete' }).to_return(body: fixture('subscription.json'))
end
let!(:subscription) do
- lelylan.update_subscription('1', name: 'Bedroom')
+ lelylan.update_subscription('1', event: 'delete')
end
it 'returns the subscription' do
subscription.id.should_not be_nil
end
it 'sends the request' do
- a_put('/subscriptions/1').with(headers: { Authorization: basic }).with(body: { name: 'Bedroom' }).should have_been_made
+ a_request(:put, 'http://id:secret@api.lelylan.com/subscriptions/1').with(body: { event: 'delete' }).should have_been_made
end
end
describe '#delete_subscription' do
before do
- stub_delete('/subscriptions/1').to_return(body: fixture('subscription.json'))
+ stub_request(:delete, 'http://id:secret@api.lelylan.com/subscriptions/1').to_return(body: fixture('subscription.json'))
end
let!(:subscription) do
lelylan.delete_subscription('1')
end
@@ -118,23 +118,24 @@
it 'returns the subscription' do
subscription.id.should_not be_nil
end
it 'sends the request' do
- a_delete('/subscriptions/1').with(headers: { Authorization: basic }).should have_been_made
+ a_request(:delete, 'http://id:secret@api.lelylan.com/subscriptions/1').should have_been_made
end
end
+
describe 'when a client param misses' do
let(:client) do
Lelylan::Client.new client_id: 'id'
end
describe '#subscription' do
before do
- stub_get('/subscriptions/1').to_return(body: fixture('subscription.json'))
+ stub_request(:get, 'http://id:secret@api.lelylan.com/subscriptions/1').to_return(body: fixture('subscription.json'))
end
it 'raises a Lelylan::Error' do
expect{ client.subscription('1') }.to raise_error(Lelylan::Error, /you need both client id and client secret/)
end