-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpush_channel_subscription_spec.rb
86 lines (71 loc) · 3.04 KB
/
push_channel_subscription_spec.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# encoding: utf-8
require 'spec_helper'
require 'shared/model_behaviour'
describe Ably::Models::PushChannelSubscription do
include Ably::Modules::Conversions
subject { Ably::Models::PushChannelSubscription }
%w(channel client_id device_id).each do |string_attribute|
describe "##{string_attribute} and ##{string_attribute}=" do
let(:empty_device_details) do
if string_attribute == 'device_id'
subject.new(channel: 'default', device_id: 'default')
else
subject.new(channel: 'default', client_id: 'default')
end
end
let(:new_val) { random_str }
specify 'setter accepts a string value and getter returns the new value' do
expect(empty_device_details.public_send(string_attribute)).to eql('default')
empty_device_details.public_send("#{string_attribute}=", new_val)
expect(empty_device_details.public_send(string_attribute)).to eql(new_val)
end
specify 'setter accepts nil' do
empty_device_details.public_send("#{string_attribute}=", new_val)
expect(empty_device_details.public_send(string_attribute)).to eql(new_val)
empty_device_details.public_send("#{string_attribute}=", nil)
expect(empty_device_details.public_send(string_attribute)).to be_nil
end
specify 'rejects non string or nil values' do
expect { empty_device_details.public_send("#{string_attribute}=", {}) }.to raise_error(ArgumentError)
end
end
end
context 'camelCase constructor attributes' do
let(:client_id) { random_str }
let(:device_details) { subject.new(channel: 'foo', 'clientId' => client_id ) }
specify 'are rubyfied and exposed as underscore case' do
expect(device_details.client_id).to eql(client_id)
end
specify 'are generated when the object is serialised to JSON' do
expect(JSON.parse(device_details.to_json)["clientId"]).to eql(client_id)
end
end
describe 'conversion method PushChannelSubscription' do
let(:channel) { 'foo' }
let(:device_id) { 'bar' }
it 'accepts a PushChannelSubscription object' do
push_channel_sub = PushChannelSubscription(channel: channel, device_id: device_id)
expect(push_channel_sub.channel).to eql('foo')
expect(push_channel_sub.client_id).to be_nil
expect(push_channel_sub.device_id).to eql('bar')
end
end
describe '#for_client_id constructor' do
context 'with a valid object' do
let(:channel) { 'foo' }
let(:client_id) { 'bob' }
it 'accepts a Hash object' do
push_channel_sub = Ably::Models::PushChannelSubscription.for_client_id(channel, client_id)
expect(push_channel_sub.channel).to eql('foo')
expect(push_channel_sub.client_id).to eql('bob')
expect(push_channel_sub.device_id).to be_nil
end
end
context 'with an invalid valid object' do
let(:subscription) { { channel: 'foo' } }
it 'accepts a Hash object' do
expect { Ably::Models::PushChannelSubscription.for_device(subscription) }.to raise_error(ArgumentError)
end
end
end
end