-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathsubscriptions_spec.rb
More file actions
40 lines (32 loc) · 1.28 KB
/
subscriptions_spec.rb
File metadata and controls
40 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'spec_helper'
require 'yt/collections/subscriptions'
describe Yt::Collections::Subscriptions do
subject(:collection) { Yt::Collections::Subscriptions.new parent: Yt::Channel.new(id: 'any-id') }
let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
before { expect(collection).to behave }
describe '#insert' do
context 'given a new subscription' do
let(:subscription) { Yt::Subscription.new }
let(:behave) { receive(:do_insert).and_return subscription }
it { expect(collection.insert).to eq subscription }
end
context 'given a duplicate subscription' do
let(:reason) { 'subscriptionDuplicate' }
let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }
it { expect{collection.insert}.to fail.with 'subscriptionDuplicate' }
it { expect{collection.insert ignore_errors: true}.not_to fail }
end
end
describe '#etag' do
let(:etag) { 'etag123' }
let(:behave) { receive(:fetch_etag).and_call_original }
before do
expect_any_instance_of(Yt::Request).to receive(:run).once do
double(body: {'etag'=> etag, 'items'=> [], 'pageInfo'=> {'totalResults'=>0}})
end
end
it 'returns the etag from the list response' do
expect(collection.etag).to eq etag
end
end
end