pling 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -9
- data/README.md +1 -1
- data/lib/pling/apn/gateway.rb +3 -1
- data/lib/pling/message.rb +24 -0
- data/lib/pling/version.rb +1 -1
- data/pling.gemspec +2 -1
- data/spec/pling/adapter/base_spec.rb +2 -2
- data/spec/pling/apn/gateway_spec.rb +36 -2
- data/spec/pling/c2dm/gateway_spec.rb +43 -43
- data/spec/pling/device_spec.rb +2 -2
- data/spec/pling/gateway_spec.rb +7 -7
- data/spec/pling/gcm/gateway_spec.rb +21 -21
- data/spec/pling/message_spec.rb +28 -2
- data/spec/pling_spec.rb +3 -3
- data/spec/spec_helper.rb +8 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fef188f5e7d129c8a2f1b57405aef88b36ba3be
|
4
|
+
data.tar.gz: 67837b1fb7ff04fe817d129b4d031bb88cfdbf42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9093e9bb989269561b1624f021589a9191838eafff1f79c3fa2da0fcc82caf2b3ee0b668bd6d91464de33bba0e204f37c3d3bde8111d66544aba93684a5e4ea
|
7
|
+
data.tar.gz: 355b638ac06e00f23cf6026a285c79c1b62c5a46d9246365f19b6121c4c90d732dea357e8101a2633094e68a07b84c04d5ab4a7dd91472a33b1b15422266f62a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -148,4 +148,4 @@ See a list of all contributors on [GitHub](https://github.com/flinc/pling/contri
|
|
148
148
|
|
149
149
|
## Copyright
|
150
150
|
|
151
|
-
Copyright (c) 2010-2011 [flinc
|
151
|
+
Copyright (c) 2010-2011 [flinc GmbH](https://flinc.org/). See LICENSE for details.
|
data/lib/pling/apn/gateway.rb
CHANGED
@@ -50,10 +50,12 @@ module Pling
|
|
50
50
|
:aps => {
|
51
51
|
:alert => message.body,
|
52
52
|
:badge => message.badge && message.badge.to_i,
|
53
|
-
:sound => message.sound
|
53
|
+
:sound => message.sound,
|
54
54
|
}.delete_if { |_, value| value.nil? }
|
55
55
|
}
|
56
56
|
|
57
|
+
data[:aps]['content-available'] = 1 if message.content_available
|
58
|
+
data[:aps]['category'] = message.category if message.category
|
57
59
|
data.merge!(message.payload) if configuration[:payload] && message.payload
|
58
60
|
|
59
61
|
data = data.to_json
|
data/lib/pling/message.rb
CHANGED
@@ -65,6 +65,30 @@ module Pling
|
|
65
65
|
@payload = payload
|
66
66
|
end
|
67
67
|
|
68
|
+
##
|
69
|
+
# The content_available property - not supported by all gateways
|
70
|
+
#
|
71
|
+
# @overload content_available
|
72
|
+
# @overload content_available=()
|
73
|
+
attr_reader :content_available
|
74
|
+
|
75
|
+
def content_available=(content_available)
|
76
|
+
content_available &&= !!content_available
|
77
|
+
@content_available = content_available
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# The category property - not supported by all gateways
|
82
|
+
#
|
83
|
+
# @overload category
|
84
|
+
# @overload category=()
|
85
|
+
attr_reader :category
|
86
|
+
|
87
|
+
def category=(category)
|
88
|
+
category &&= category.to_s
|
89
|
+
@category = category
|
90
|
+
end
|
91
|
+
|
68
92
|
##
|
69
93
|
# Creates a new Pling::Message instance with the given body
|
70
94
|
#
|
data/lib/pling/version.rb
CHANGED
data/pling.gemspec
CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency "connection_pool", "~> 2.0"
|
23
23
|
s.add_runtime_dependency("jruby-openssl") if RUBY_PLATFORM == 'java'
|
24
24
|
|
25
|
-
s.add_development_dependency "rspec", "~>
|
25
|
+
s.add_development_dependency "rspec", "~> 3.3"
|
26
|
+
s.add_development_dependency "rspec-its", ">= 1.2"
|
26
27
|
s.add_development_dependency "yard", ">= 0.7"
|
27
28
|
s.add_development_dependency "rake", ">= 0.9"
|
28
29
|
end
|
@@ -6,7 +6,7 @@ describe Pling::Adapter::Base do
|
|
6
6
|
|
7
7
|
let(:device) { Pling::Device.new }
|
8
8
|
let(:message) { Pling::Message.new }
|
9
|
-
let(:gateway) {
|
9
|
+
let(:gateway) { double(:gateway_double, :deliver => true) }
|
10
10
|
|
11
11
|
it 'should try to discover a gateway' do
|
12
12
|
Pling::Gateway.should_receive(:discover).with(device).and_return(gateway)
|
@@ -19,4 +19,4 @@ describe Pling::Adapter::Base do
|
|
19
19
|
subject.deliver(message, device)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -37,11 +37,11 @@ describe Pling::APN::Gateway do
|
|
37
37
|
subject { Pling::APN::Gateway.new(valid_configuration) }
|
38
38
|
|
39
39
|
it 'should raise an error if no message is given' do
|
40
|
-
expect { subject.deliver(nil, device) }.to raise_error
|
40
|
+
expect { subject.deliver(nil, device) }.to raise_error(ArgumentError, /do not implement #to_pling_message/)
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should raise an error the device is given' do
|
44
|
-
expect { subject.deliver(message, nil) }.to raise_error
|
44
|
+
expect { subject.deliver(message, nil) }.to raise_error(ArgumentError, /do not implement #to_pling_device/)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should initialize a new APN connection if none is established' do
|
@@ -118,6 +118,40 @@ describe Pling::APN::Gateway do
|
|
118
118
|
subject.deliver(message, device)
|
119
119
|
end
|
120
120
|
|
121
|
+
it 'should include the given content_available flag' do
|
122
|
+
expected_payload = {
|
123
|
+
'aps' => {
|
124
|
+
'alert' => 'Hello from Pling',
|
125
|
+
'content-available' => 1
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
connection.stub(:write) do |packet|
|
130
|
+
JSON.parse(packet[37..-1]).should eq(expected_payload)
|
131
|
+
end
|
132
|
+
|
133
|
+
message.content_available = 1
|
134
|
+
|
135
|
+
subject.deliver(message, device)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should include the given category' do
|
139
|
+
expected_payload = {
|
140
|
+
'aps' => {
|
141
|
+
'alert' => 'Hello from Pling',
|
142
|
+
'category' => 'foobar'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
connection.stub(:write) do |packet|
|
147
|
+
JSON.parse(packet[37..-1]).should eq(expected_payload)
|
148
|
+
end
|
149
|
+
|
150
|
+
message.category = 'foobar'
|
151
|
+
|
152
|
+
subject.deliver(message, device)
|
153
|
+
end
|
154
|
+
|
121
155
|
context 'when configured to include payload' do
|
122
156
|
before do
|
123
157
|
valid_configuration.merge!(:payload => true)
|
@@ -6,27 +6,27 @@ describe Pling::C2DM::Gateway do
|
|
6
6
|
{ :email => 'someone@gmail.com', :password => 'random', :source => 'some-source' }
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:
|
10
|
-
|
9
|
+
let(:authentication_response_double) do
|
10
|
+
double(:authentication_response_double, :success? => true, :status => 200, :body => "SID=SOMESID\nAuth=S0ME-ToKeN123")
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:
|
14
|
-
|
13
|
+
let(:push_response_double) do
|
14
|
+
double(:push_response_double, :success? => true, :status => 200, :body => "")
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:
|
18
|
-
|
19
|
-
|
17
|
+
let(:connection_double) do
|
18
|
+
double(:connection_double).tap do |connection|
|
19
|
+
connection.stub(:post).
|
20
20
|
with('https://www.google.com/accounts/ClientLogin', anything).
|
21
|
-
and_return(
|
21
|
+
and_return(authentication_response_double)
|
22
22
|
|
23
|
-
|
23
|
+
connection.stub(:post).
|
24
24
|
with('https://android.apis.google.com/c2dm/send', anything, anything).
|
25
|
-
and_return(
|
25
|
+
and_return(push_response_double)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
before { Faraday.stub(:new).and_return(
|
29
|
+
before { Faraday.stub(:new).and_return(connection_double) }
|
30
30
|
|
31
31
|
it 'should handle various apn related device types' do
|
32
32
|
Pling::C2DM::Gateway.handled_types.should =~ [:android, :c2dm]
|
@@ -60,9 +60,9 @@ describe Pling::C2DM::Gateway do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should try to authenticate' do
|
63
|
-
|
63
|
+
connection_double.should_receive(:post).
|
64
64
|
with('https://www.google.com/accounts/ClientLogin', valid_authentication_params).
|
65
|
-
and_return(
|
65
|
+
and_return(authentication_response_double)
|
66
66
|
|
67
67
|
Pling::C2DM::Gateway.new(valid_configuration)
|
68
68
|
end
|
@@ -73,13 +73,13 @@ describe Pling::C2DM::Gateway do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'should raise an error if authentication was not successful' do
|
76
|
-
|
76
|
+
authentication_response_double.stub(:status => 403, :success? => false, :body => 'Error=BadAuthentication')
|
77
77
|
|
78
78
|
expect { Pling::C2DM::Gateway.new(valid_configuration) }.to raise_error(Pling::AuthenticationFailed, /Authentication failed: \[403\] Error=BadAuthentication/)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should raise an error if it could not extract a token from the response' do
|
82
|
-
|
82
|
+
authentication_response_double.stub(:body).and_return('SOMERANDOMBODY')
|
83
83
|
|
84
84
|
expect { Pling::C2DM::Gateway.new(valid_configuration) }.to raise_error(Pling::AuthenticationFailed, /Token extraction failed/)
|
85
85
|
end
|
@@ -92,25 +92,25 @@ describe Pling::C2DM::Gateway do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'should use Faraday::Response::Logger when :debug is set to true' do
|
95
|
-
builder =
|
95
|
+
builder = double(:builder_double, :use => true, :adapter => true)
|
96
96
|
builder.should_receive(:use).with(Faraday::Response::Logger)
|
97
|
-
Faraday.stub(:new).and_yield(builder).and_return(
|
97
|
+
Faraday.stub(:new).and_yield(builder).and_return(connection_double)
|
98
98
|
|
99
99
|
Pling::C2DM::Gateway.new(valid_configuration.merge(:debug => true))
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'should use the adapter set with :adapter' do
|
103
|
-
builder =
|
103
|
+
builder = double(:builder_double, :use => true, :adapter => true)
|
104
104
|
builder.should_receive(:adapter).with(:typheus)
|
105
|
-
Faraday.stub(:new).and_yield(builder).and_return(
|
105
|
+
Faraday.stub(:new).and_yield(builder).and_return(connection_double)
|
106
106
|
|
107
107
|
Pling::C2DM::Gateway.new(valid_configuration.merge(:adapter => :typheus))
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'should allow configuring the authentication_url' do
|
111
|
-
|
111
|
+
connection_double.should_receive(:post).
|
112
112
|
with('http://example.com/authentication', anything).
|
113
|
-
and_return(
|
113
|
+
and_return(authentication_response_double)
|
114
114
|
|
115
115
|
Pling::C2DM::Gateway.new(valid_configuration.merge(:authentication_url => 'http://example.com/authentication'))
|
116
116
|
end
|
@@ -138,11 +138,11 @@ describe Pling::C2DM::Gateway do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'should raise an error if no message is given' do
|
141
|
-
expect { subject.deliver(nil, device) }.to raise_error
|
141
|
+
expect { subject.deliver(nil, device) }.to raise_error(ArgumentError, /do not implement #to_pling_message/)
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should raise an error the device is given' do
|
145
|
-
expect { subject.deliver(message, nil) }.to raise_error
|
145
|
+
expect { subject.deliver(message, nil) }.to raise_error(ArgumentError, /do not implement #to_pling_device/)
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'should call #to_pling_message on the given message' do
|
@@ -156,49 +156,49 @@ describe Pling::C2DM::Gateway do
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should try to deliver the given message' do
|
159
|
-
|
159
|
+
connection_double.should_receive(:post).
|
160
160
|
with('https://android.apis.google.com/c2dm/send', valid_push_params, valid_push_headers).
|
161
|
-
and_return(
|
161
|
+
and_return(push_response_double)
|
162
162
|
|
163
163
|
subject.deliver(message, device)
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'should raise a Pling::DeliveryFailed exception if the delivery was not successful' do
|
167
|
-
|
168
|
-
and_return(
|
169
|
-
|
167
|
+
connection_double.should_receive(:post).with('https://android.apis.google.com/c2dm/send', anything, anything).
|
168
|
+
and_return(push_response_double)
|
169
|
+
push_response_double.stub(:status => 401, :success? => false, :body => "Something went wrong")
|
170
170
|
|
171
171
|
expect { subject.deliver(message, device) }.to raise_error Pling::DeliveryFailed, /Something went wrong/
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should raise a Pling::DeliveryFailed exception if the response body contained an error' do
|
175
|
-
|
176
|
-
and_return(
|
177
|
-
|
175
|
+
connection_double.should_receive(:post).with('https://android.apis.google.com/c2dm/send', anything, anything).
|
176
|
+
and_return(push_response_double)
|
177
|
+
push_response_double.stub(:status => 200, :success? => true, :body => "Error=SomeError")
|
178
178
|
|
179
179
|
expect { subject.deliver(message, device) }.to raise_error Pling::DeliveryFailed, /Error=SomeError/
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'should send data.badge if the given message has a badge' do
|
183
|
-
|
183
|
+
connection_double.should_receive(:post).
|
184
184
|
with(anything, hash_including(:'data.badge' => '10'), anything).
|
185
|
-
and_return(
|
185
|
+
and_return(push_response_double)
|
186
186
|
message.badge = 10
|
187
187
|
subject.deliver(message, device)
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should send data.sound if the given message has a sound' do
|
191
|
-
|
191
|
+
connection_double.should_receive(:post).
|
192
192
|
with(anything, hash_including(:'data.sound' => 'pling'), anything).
|
193
|
-
and_return(
|
193
|
+
and_return(push_response_double)
|
194
194
|
message.sound = :pling
|
195
195
|
subject.deliver(message, device)
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'should send data.subject if the given message has a subject' do
|
199
|
-
|
199
|
+
connection_double.should_receive(:post).
|
200
200
|
with(anything, hash_including(:'data.subject' => 'Important!'), anything).
|
201
|
-
and_return(
|
201
|
+
and_return(push_response_double)
|
202
202
|
message.subject = 'Important!'
|
203
203
|
subject.deliver(message, device)
|
204
204
|
end
|
@@ -210,9 +210,9 @@ and_return(push_response_mock)
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it 'should include the given payload' do
|
213
|
-
|
213
|
+
connection_double.should_receive(:post).
|
214
214
|
with(anything, hash_including(:'data.data' => 'available'), anything).
|
215
|
-
and_return(
|
215
|
+
and_return(push_response_double)
|
216
216
|
subject.deliver(message, device)
|
217
217
|
end
|
218
218
|
end
|
@@ -224,9 +224,9 @@ and_return(push_response_mock)
|
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'should include the given payload' do
|
227
|
-
|
227
|
+
connection_double.should_receive(:post).
|
228
228
|
with(anything, hash_not_including(:'data.data' => 'available'), anything).
|
229
|
-
and_return(
|
229
|
+
and_return(push_response_double)
|
230
230
|
subject.deliver(message, device)
|
231
231
|
end
|
232
232
|
end
|
@@ -235,9 +235,9 @@ and_return(push_response_mock)
|
|
235
235
|
:InvalidRegistration, :NotRegistered,
|
236
236
|
:MessageTooBig, :MissingCollapseKey].each do |exception|
|
237
237
|
it "should raise a Pling::C2DM::#{exception} when the response body is ''" do
|
238
|
-
|
238
|
+
push_response_double.stub(:body => "Error=#{exception}")
|
239
239
|
expect { subject.deliver(message, device) }.to raise_error Pling::C2DM.const_get(exception)
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
243
|
-
end
|
243
|
+
end
|
data/spec/pling/device_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Pling::Device do
|
|
4
4
|
|
5
5
|
context 'when created with no arguments' do
|
6
6
|
it 'should not require an argument' do
|
7
|
-
expect { Pling::Device.new }.to_not raise_error
|
7
|
+
expect { Pling::Device.new }.to_not raise_error
|
8
8
|
end
|
9
9
|
|
10
10
|
specify { Pling::Device.new.should_not be_valid }
|
@@ -41,7 +41,7 @@ describe Pling::Device do
|
|
41
41
|
|
42
42
|
describe '#identifier=' do
|
43
43
|
it 'should call #to_s on the given identifier' do
|
44
|
-
subject.identifier =
|
44
|
+
subject.identifier = double(:identifier_double, :to_s => 'XXXX')
|
45
45
|
subject.identifier.should eq('XXXX')
|
46
46
|
end
|
47
47
|
end
|
data/spec/pling/gateway_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe Pling::Gateway do
|
|
24
24
|
describe '.discover' do
|
25
25
|
it 'should do a delayed initialization' do
|
26
26
|
Pling.stub(:gateways).and_return(Pling::DelayedInitializer.new([[gateway_class, { :some => :option }]]))
|
27
|
-
gateway_class.should_receive(:new).with({ :some => :option }).and_return(
|
27
|
+
gateway_class.should_receive(:new).with({ :some => :option }).and_return(double.as_null_object)
|
28
28
|
subject.discover(device)
|
29
29
|
end
|
30
30
|
|
@@ -50,15 +50,15 @@ describe Pling::Gateway do
|
|
50
50
|
describe '#handles?' do
|
51
51
|
it 'should return true if the gateway supports the given device\'s type' do
|
52
52
|
device.type = :android
|
53
|
-
gateway.handles?(device).should
|
53
|
+
gateway.handles?(device).should be true
|
54
54
|
|
55
55
|
device.type = :c2dm
|
56
|
-
gateway.handles?(device).should
|
56
|
+
gateway.handles?(device).should be true
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should return false if the gateway does not support the given device\'s type' do
|
60
60
|
device.type = :random
|
61
|
-
gateway.handles?(device).should
|
61
|
+
gateway.handles?(device).should be false
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -98,9 +98,9 @@ describe Pling::Gateway do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should not raise an Pling::Errors if an on_exception callback is set' do
|
101
|
-
gateway = gateway_class.new(:on_exception => lambda {})
|
101
|
+
gateway = gateway_class.new(:on_exception => lambda {|_| })
|
102
102
|
gateway.stub(:deliver!).and_raise(Pling::Error)
|
103
|
-
expect { gateway.deliver(message, device) }.to_not raise_error
|
103
|
+
expect { gateway.deliver(message, device) }.to_not raise_error
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'should pass the exception to the callback' do
|
@@ -109,4 +109,4 @@ describe Pling::Gateway do
|
|
109
109
|
gateway.deliver(message, device)
|
110
110
|
end
|
111
111
|
end
|
112
|
-
end
|
112
|
+
end
|
@@ -6,15 +6,15 @@ describe Pling::GCM::Gateway do
|
|
6
6
|
{ :key => 'some-key' }
|
7
7
|
end
|
8
8
|
|
9
|
-
let(:
|
10
|
-
|
9
|
+
let(:push_response_double) do
|
10
|
+
double(:response_double, :success? => true, :status => 200, :body => "")
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:connection_mock) do
|
14
|
-
|
15
|
-
|
14
|
+
double(:connection_double).tap do |connection|
|
15
|
+
connection.stub(:post).
|
16
16
|
with('https://android.googleapis.com/gcm/send', anything, anything).
|
17
|
-
and_return(
|
17
|
+
and_return(push_response_double)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -47,7 +47,7 @@ describe Pling::GCM::Gateway do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should use Faraday::Response::Logger when :debug is set to true' do
|
50
|
-
builder =
|
50
|
+
builder = double(:builder_double, :use => true, :adapter => true)
|
51
51
|
builder.should_receive(:use).with(Faraday::Response::Logger)
|
52
52
|
Faraday.stub(:new).and_yield(builder).and_return(connection_mock)
|
53
53
|
|
@@ -55,7 +55,7 @@ describe Pling::GCM::Gateway do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should use the adapter set with :adapter' do
|
58
|
-
builder =
|
58
|
+
builder = double(:builder_double, :use => true, :adapter => true)
|
59
59
|
builder.should_receive(:adapter).with(:typheus)
|
60
60
|
Faraday.stub(:new).and_yield(builder).and_return(connection_mock)
|
61
61
|
|
@@ -83,11 +83,11 @@ describe Pling::GCM::Gateway do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should raise an error if no message is given' do
|
86
|
-
expect { subject.deliver(nil, device) }.to raise_error
|
86
|
+
expect { subject.deliver(nil, device) }.to raise_error(ArgumentError, /do not implement #to_pling_message/)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'should raise an error the device is given' do
|
90
|
-
expect { subject.deliver(message, nil) }.to raise_error
|
90
|
+
expect { subject.deliver(message, nil) }.to raise_error(ArgumentError, /do not implement #to_pling_device/)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should call #to_pling_message on the given message' do
|
@@ -103,21 +103,21 @@ describe Pling::GCM::Gateway do
|
|
103
103
|
it 'should try to deliver the given message' do
|
104
104
|
connection_mock.should_receive(:post).
|
105
105
|
with('https://android.googleapis.com/gcm/send', valid_push_params, valid_push_headers).
|
106
|
-
and_return(
|
106
|
+
and_return(push_response_double)
|
107
107
|
|
108
108
|
subject.deliver(message, device)
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should raise a Pling::DeliveryFailed exception if the delivery was not successful' do
|
112
|
-
connection_mock.should_receive(:post).and_return(
|
113
|
-
|
112
|
+
connection_mock.should_receive(:post).and_return(push_response_double)
|
113
|
+
push_response_double.stub(:status => 401, :success? => false, :body => "Something went wrong")
|
114
114
|
|
115
115
|
expect { subject.deliver(message, device) }.to raise_error Pling::DeliveryFailed, /Something went wrong/
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should raise a Pling::DeliveryFailed exception if the response body contained an error' do
|
119
|
-
connection_mock.should_receive(:post).and_return(
|
120
|
-
|
119
|
+
connection_mock.should_receive(:post).and_return(push_response_double)
|
120
|
+
push_response_double.stub(:status => 200, :success? => true, :body => { 'failure' => 1, 'results' => ['error' => 'SomeError'] })
|
121
121
|
|
122
122
|
expect { subject.deliver(message, device) }.to raise_error Pling::DeliveryFailed, /SomeError/
|
123
123
|
end
|
@@ -125,7 +125,7 @@ describe Pling::GCM::Gateway do
|
|
125
125
|
it 'should send data.badge if the given message has a badge' do
|
126
126
|
connection_mock.should_receive(:post).
|
127
127
|
with(anything, hash_including(:data => hash_including({ :badge => '10' })), anything).
|
128
|
-
and_return(
|
128
|
+
and_return(push_response_double)
|
129
129
|
message.badge = 10
|
130
130
|
subject.deliver(message, device)
|
131
131
|
end
|
@@ -133,7 +133,7 @@ describe Pling::GCM::Gateway do
|
|
133
133
|
it 'should send data.sound if the given message has a sound' do
|
134
134
|
connection_mock.should_receive(:post).
|
135
135
|
with(anything, hash_including(:data => hash_including({ :sound => 'pling' })), anything).
|
136
|
-
and_return(
|
136
|
+
and_return(push_response_double)
|
137
137
|
message.sound = :pling
|
138
138
|
subject.deliver(message, device)
|
139
139
|
end
|
@@ -141,7 +141,7 @@ describe Pling::GCM::Gateway do
|
|
141
141
|
it 'should send data.subject if the given message has a subject' do
|
142
142
|
connection_mock.should_receive(:post).
|
143
143
|
with(anything, hash_including(:data => hash_including({ :subject => 'Important!' })), anything).
|
144
|
-
and_return(
|
144
|
+
and_return(push_response_double)
|
145
145
|
message.subject = 'Important!'
|
146
146
|
subject.deliver(message, device)
|
147
147
|
end
|
@@ -155,7 +155,7 @@ describe Pling::GCM::Gateway do
|
|
155
155
|
it 'should include the given payload' do
|
156
156
|
connection_mock.should_receive(:post).
|
157
157
|
with(anything, hash_including(:data => hash_including({ :data => 'available' })), anything).
|
158
|
-
and_return(
|
158
|
+
and_return(push_response_double)
|
159
159
|
subject.deliver(message, device)
|
160
160
|
end
|
161
161
|
end
|
@@ -169,7 +169,7 @@ describe Pling::GCM::Gateway do
|
|
169
169
|
it 'should include the given payload' do
|
170
170
|
connection_mock.should_receive(:post).
|
171
171
|
with(anything, hash_not_including(:'data.data' => 'available'), anything).
|
172
|
-
and_return(
|
172
|
+
and_return(push_response_double)
|
173
173
|
subject.deliver(message, device)
|
174
174
|
end
|
175
175
|
end
|
@@ -178,9 +178,9 @@ describe Pling::GCM::Gateway do
|
|
178
178
|
:NotRegistered, :MessageTooBig, :InvalidTtl, :Unavailable,
|
179
179
|
:InternalServerError].each do |exception|
|
180
180
|
it "should raise a Pling::GCM::#{exception} when the response body is ''" do
|
181
|
-
|
181
|
+
push_response_double.stub(:body => { 'failure' => 1, 'results' => [{ 'error' => exception }]})
|
182
182
|
expect { subject.deliver(message, device) }.to raise_error Pling::GCM.const_get(exception)
|
183
183
|
end
|
184
184
|
end
|
185
185
|
end
|
186
|
-
end
|
186
|
+
end
|
data/spec/pling/message_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Pling::Message do
|
|
4
4
|
|
5
5
|
context 'when created with no arguments' do
|
6
6
|
it 'should not require an argument' do
|
7
|
-
expect { Pling::Message.new() }.to_not raise_error
|
7
|
+
expect { Pling::Message.new() }.to_not raise_error
|
8
8
|
end
|
9
9
|
|
10
10
|
specify { Pling::Message.new().should_not be_valid }
|
@@ -47,6 +47,32 @@ describe Pling::Message do
|
|
47
47
|
its(:payload) { should eq({ :data => true }) }
|
48
48
|
end
|
49
49
|
|
50
|
+
context 'when created with a hash that contains a :content_available key' do
|
51
|
+
subject { Pling::Message.new(:content_available => true)}
|
52
|
+
its(:content_available) { should eq(true) }
|
53
|
+
|
54
|
+
context 'when the key is not present' do
|
55
|
+
subject { Pling::Message.new }
|
56
|
+
its(:content_available) { should eq(nil) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when created with a hash that contains a :category key' do
|
61
|
+
subject { Pling::Message.new(:category => 'foobar')}
|
62
|
+
its(:category) { should eq('foobar') }
|
63
|
+
|
64
|
+
context 'when the value behind the :category key is not a string' do
|
65
|
+
subject { Pling::Message.new(:category => :foobar)}
|
66
|
+
|
67
|
+
its(:category) { should eq('foobar') }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the key is not present' do
|
71
|
+
subject { Pling::Message.new }
|
72
|
+
its(:category) { should eq(nil) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
50
76
|
context 'when created with an hash of invalid attributes' do
|
51
77
|
it 'should ignore the invalid paramters' do
|
52
78
|
expect { Pling::Message.new({ :random_param => true }) }.to_not raise_error
|
@@ -55,7 +81,7 @@ describe Pling::Message do
|
|
55
81
|
|
56
82
|
describe '#body=' do
|
57
83
|
it 'should call #to_s on the given body' do
|
58
|
-
subject.body =
|
84
|
+
subject.body = double(:body_double, :to_s => 'Hello from Pling')
|
59
85
|
subject.body.should eq('Hello from Pling')
|
60
86
|
end
|
61
87
|
end
|
data/spec/pling_spec.rb
CHANGED
@@ -59,18 +59,18 @@ describe Pling do
|
|
59
59
|
|
60
60
|
let(:message) { Pling::Message.new }
|
61
61
|
let(:device) { Pling::Device.new }
|
62
|
-
let(:adapter) {
|
62
|
+
let(:adapter) { double(:adapter_double, :deliver => true) }
|
63
63
|
|
64
64
|
before do
|
65
65
|
Pling.stub(:adapter).and_return(adapter)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should raise an error if no message is given' do
|
69
|
-
expect { Pling.deliver(nil, device) }.to raise_error
|
69
|
+
expect { Pling.deliver(nil, device) }.to raise_error(ArgumentError, /do not implement #to_pling_message/)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should raise an error the device is given' do
|
73
|
-
expect { Pling.deliver(message, nil) }.to raise_error
|
73
|
+
expect { Pling.deliver(message, nil) }.to raise_error(ArgumentError, /do not implement #to_pling_device/)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'should call #to_pling_message on the given message' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
3
|
|
4
|
+
require 'rspec/its'
|
4
5
|
Bundler.require
|
5
6
|
|
6
7
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
7
8
|
|
8
9
|
RSpec.configure do |config|
|
9
|
-
config.mock_with :rspec
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.syntax = [:should, :expect]
|
12
|
+
end
|
13
|
+
|
14
|
+
config.expect_with :rspec do |expectations|
|
15
|
+
expectations.syntax = [:should, :expect]
|
16
|
+
end
|
10
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-10
|
13
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -74,14 +74,28 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
77
|
+
version: '3.3'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
84
|
+
version: '3.3'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rspec-its
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.2'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1.2'
|
85
99
|
- !ruby/object:Gem::Dependency
|
86
100
|
name: yard
|
87
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -180,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
194
|
version: '0'
|
181
195
|
requirements: []
|
182
196
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.4.
|
197
|
+
rubygems_version: 2.4.5
|
184
198
|
signing_key:
|
185
199
|
specification_version: 4
|
186
200
|
summary: Pling is a notification framework that supports multiple gateways
|