rpush 2.3.1-java → 2.3.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +36 -28
- data/lib/rpush/configuration.rb +1 -0
- data/lib/rpush/daemon/feeder.rb +16 -12
- data/lib/rpush/daemon/interruptible_sleep.rb +26 -5
- data/lib/rpush/daemon/store/active_record.rb +4 -0
- data/lib/rpush/daemon/store/interface.rb +1 -1
- data/lib/rpush/daemon/store/redis.rb +10 -0
- data/lib/rpush/embed.rb +1 -0
- data/lib/rpush/logger.rb +1 -0
- data/lib/rpush/push.rb +1 -2
- data/lib/rpush/version.rb +1 -1
- data/spec/functional/adm_spec.rb +6 -8
- data/spec/functional/apns_spec.rb +9 -9
- data/spec/functional/embed_spec.rb +3 -3
- data/spec/functional/gcm_spec.rb +6 -8
- data/spec/functional/new_app_spec.rb +5 -20
- data/spec/functional/retry_spec.rb +8 -12
- data/spec/functional/synchronization_spec.rb +1 -1
- data/spec/functional/wpns_spec.rb +7 -7
- data/spec/functional_spec_helper.rb +4 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/apns_feedback_spec.rb +4 -4
- data/spec/unit/client/active_record/adm/app_spec.rb +12 -12
- data/spec/unit/client/active_record/adm/notification_spec.rb +9 -9
- data/spec/unit/client/active_record/apns/app_spec.rb +4 -4
- data/spec/unit/client/active_record/apns/feedback_spec.rb +2 -2
- data/spec/unit/client/active_record/apns/notification_spec.rb +46 -46
- data/spec/unit/client/active_record/app_spec.rb +6 -6
- data/spec/unit/client/active_record/gcm/notification_spec.rb +7 -7
- data/spec/unit/client/active_record/notification_spec.rb +2 -2
- data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -8
- data/spec/unit/configuration_spec.rb +5 -5
- data/spec/unit/daemon/adm/delivery_spec.rb +69 -69
- data/spec/unit/daemon/apns/delivery_spec.rb +13 -13
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +24 -26
- data/spec/unit/daemon/app_runner_spec.rb +29 -29
- data/spec/unit/daemon/batch_spec.rb +30 -30
- data/spec/unit/daemon/delivery_error_spec.rb +2 -2
- data/spec/unit/daemon/delivery_spec.rb +6 -6
- data/spec/unit/daemon/dispatcher/http_spec.rb +5 -5
- data/spec/unit/daemon/dispatcher/tcp_spec.rb +4 -4
- data/spec/unit/daemon/dispatcher_loop_spec.rb +9 -9
- data/spec/unit/daemon/feeder_spec.rb +22 -23
- data/spec/unit/daemon/gcm/delivery_spec.rb +56 -56
- data/spec/unit/daemon/retryable_error_spec.rb +2 -2
- data/spec/unit/daemon/service_config_methods_spec.rb +5 -5
- data/spec/unit/daemon/signal_handler_spec.rb +13 -13
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +13 -13
- data/spec/unit/daemon/store/active_record_spec.rb +49 -49
- data/spec/unit/daemon/tcp_connection_spec.rb +50 -50
- data/spec/unit/daemon/wpns/delivery_spec.rb +36 -36
- data/spec/unit/daemon_spec.rb +33 -30
- data/spec/unit/deprecatable_spec.rb +3 -3
- data/spec/unit/deprecation_spec.rb +2 -2
- data/spec/unit/embed_spec.rb +7 -7
- data/spec/unit/logger_spec.rb +25 -25
- data/spec/unit/notification_shared.rb +7 -7
- data/spec/unit/plugin_spec.rb +1 -1
- data/spec/unit/push_spec.rb +8 -8
- data/spec/unit/reflectable_spec.rb +5 -5
- data/spec/unit/reflection_collection_spec.rb +2 -2
- data/spec/unit/rpush_spec.rb +1 -1
- data/spec/unit_spec_helper.rb +4 -5
- metadata +10 -4
@@ -30,30 +30,15 @@ describe 'New app loading' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def stub_tcp_connection
|
33
|
-
Rpush::Daemon::TcpConnection.
|
34
|
-
Rpush::Daemon::TcpConnection.
|
33
|
+
allow_any_instance_of(Rpush::Daemon::TcpConnection).to receive_messages(connect_socket: [tcp_socket, ssl_socket])
|
34
|
+
allow_any_instance_of(Rpush::Daemon::TcpConnection).to receive_messages(setup_ssl_context: double.as_null_object)
|
35
35
|
stub_const('Rpush::Daemon::TcpConnection::IO', io_double)
|
36
36
|
end
|
37
37
|
|
38
|
-
def wait_for_notification_to_deliver(notification)
|
39
|
-
Timeout.timeout(timeout) do
|
40
|
-
until notification.delivered
|
41
|
-
sleep 0.1
|
42
|
-
notification.reload
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
before do
|
48
|
-
Rpush.config.push_poll = 0
|
49
|
-
Rpush.embed
|
50
|
-
end
|
51
|
-
|
52
38
|
it 'delivers a notification successfully' do
|
53
|
-
sleep 1 # TODO: Need a better way to detect when the Feeder is running.
|
54
39
|
notification = create_notification
|
55
|
-
|
40
|
+
Rpush.push
|
41
|
+
notification.reload
|
42
|
+
expect(notification.delivered).to eq(true)
|
56
43
|
end
|
57
|
-
|
58
|
-
after { Timeout.timeout(timeout) { Rpush.shutdown } }
|
59
44
|
end
|
@@ -22,25 +22,21 @@ describe 'Retries' do
|
|
22
22
|
redis.del(Rpush::Client::Redis::Notification.absolute_pending_namespace)
|
23
23
|
end
|
24
24
|
|
25
|
-
Net::HTTP::Persistent.
|
26
|
-
response.
|
25
|
+
allow(Net::HTTP::Persistent).to receive_messages(new: http)
|
26
|
+
allow(response).to receive_messages(body: JSON.dump(results: [{ message_id: notification.registration_ids.first.to_s }]))
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'delivers a notification due to be retried' do
|
30
30
|
Rpush::Daemon.store.mark_retryable(notification, Time.now - 1.minute)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
notification.reload
|
35
|
-
end.to change(notification, :delivered).to(true)
|
31
|
+
Rpush.push
|
32
|
+
notification.reload
|
33
|
+
expect(notification.delivered).to eq(true)
|
36
34
|
end
|
37
35
|
|
38
36
|
it 'does not deliver a notification not due to be retried' do
|
39
37
|
Rpush::Daemon.store.mark_retryable(notification, Time.now + 1.minute)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
notification.reload
|
44
|
-
end.to_not change(notification, :delivered).to(true)
|
38
|
+
Rpush.push
|
39
|
+
notification.reload
|
40
|
+
expect(notification.delivered).to eq(false)
|
45
41
|
end
|
46
42
|
end
|
@@ -44,7 +44,7 @@ describe 'Synchronization' do
|
|
44
44
|
it 'stops a deleted app' do
|
45
45
|
app.destroy
|
46
46
|
Rpush.sync
|
47
|
-
Rpush::Daemon::AppRunner.app_running?(app).
|
47
|
+
expect(Rpush::Daemon::AppRunner.app_running?(app)).to eq(false)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'restarts an app when the certificate is changed' do
|
@@ -21,11 +21,11 @@ describe 'WPNs' do
|
|
21
21
|
notification_with_alert.alert = "Hello world!"
|
22
22
|
notification_with_alert.save!
|
23
23
|
|
24
|
-
Net::HTTP::Persistent.
|
24
|
+
allow(Net::HTTP::Persistent).to receive_messages(new: http)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'delivers a notification with data successfully' do
|
28
|
-
response.
|
28
|
+
allow(response).to receive_messages(to_hash: { 'x-notificationstatus' => ['Received'] })
|
29
29
|
|
30
30
|
expect do
|
31
31
|
Rpush.push
|
@@ -34,16 +34,16 @@ describe 'WPNs' do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'fails to deliver a notification with data successfully' do
|
37
|
-
response.
|
37
|
+
allow(response).to receive_messages(code: 400)
|
38
38
|
|
39
39
|
expect do
|
40
40
|
Rpush.push
|
41
41
|
notification_with_data.reload
|
42
|
-
end.
|
42
|
+
end.to change(notification_with_data, :failed_at)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'delivers a notification with an alert successfully' do
|
46
|
-
response.
|
46
|
+
allow(response).to receive_messages(to_hash: { 'x-notificationstatus' => ['Received'] })
|
47
47
|
|
48
48
|
expect do
|
49
49
|
Rpush.push
|
@@ -52,12 +52,12 @@ describe 'WPNs' do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'fails to deliver a notification with an alert successfully' do
|
55
|
-
response.
|
55
|
+
allow(response).to receive_messages(code: 400)
|
56
56
|
|
57
57
|
expect do
|
58
58
|
Rpush.push
|
59
59
|
notification_with_alert.reload
|
60
|
-
end.
|
60
|
+
end.to change(notification_with_alert, :failed_at)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'retries notification that fail due to a SocketError' do
|
@@ -3,9 +3,8 @@ require 'spec_helper'
|
|
3
3
|
require 'database_cleaner'
|
4
4
|
DatabaseCleaner.strategy = :truncation
|
5
5
|
|
6
|
-
def functional_example?(
|
7
|
-
|
8
|
-
path =~ /spec\/functional/
|
6
|
+
def functional_example?(metadata)
|
7
|
+
metadata[:file_path] =~ /spec\/functional/
|
9
8
|
end
|
10
9
|
|
11
10
|
RSpec.configure do |config|
|
@@ -14,10 +13,10 @@ RSpec.configure do |config|
|
|
14
13
|
redis.keys('rpush:*').each { |key| redis.del(key) }
|
15
14
|
end
|
16
15
|
|
17
|
-
Rpush.config.logger = ::Logger.new(STDOUT) if functional_example?(
|
16
|
+
Rpush.config.logger = ::Logger.new(STDOUT) if functional_example?(self.class.metadata)
|
18
17
|
end
|
19
18
|
|
20
19
|
config.after(:each) do
|
21
|
-
DatabaseCleaner.clean if functional_example?(
|
20
|
+
DatabaseCleaner.clean if functional_example?(self.class.metadata)
|
22
21
|
end
|
23
22
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,17 +5,17 @@ describe Rpush, 'apns_feedback' do
|
|
5
5
|
let(:receiver) { double(check_for_feedback: nil) }
|
6
6
|
|
7
7
|
before do
|
8
|
-
Rpush::Daemon::Apns::FeedbackReceiver.
|
8
|
+
allow(Rpush::Daemon::Apns::FeedbackReceiver).to receive(:new) { receiver }
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'initializes the daemon' do
|
12
|
-
Rpush::Daemon.
|
12
|
+
expect(Rpush::Daemon).to receive(:common_init)
|
13
13
|
Rpush.apns_feedback
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'checks feedback for each app' do
|
17
|
-
Rpush::Daemon::Apns::FeedbackReceiver.
|
18
|
-
receiver.
|
17
|
+
expect(Rpush::Daemon::Apns::FeedbackReceiver).to receive(:new).with(app).and_return(receiver)
|
18
|
+
expect(receiver).to receive(:check_for_feedback)
|
19
19
|
Rpush.apns_feedback
|
20
20
|
end
|
21
21
|
end
|
@@ -5,31 +5,31 @@ describe Rpush::Client::ActiveRecord::Adm::App do
|
|
5
5
|
let(:existing_app) { Rpush::Client::ActiveRecord::Adm::App.create!(name: 'existing', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
|
6
6
|
|
7
7
|
it 'should be valid if properly instantiated' do
|
8
|
-
subject.
|
8
|
+
expect(subject).to be_valid
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should be invalid if name' do
|
12
12
|
subject.name = nil
|
13
|
-
subject.
|
14
|
-
subject.errors[:name].
|
13
|
+
expect(subject).not_to be_valid
|
14
|
+
expect(subject.errors[:name]).to eq ["can't be blank"]
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be invalid if name is not unique within scope' do
|
18
18
|
subject.name = existing_app.name
|
19
|
-
subject.
|
20
|
-
subject.errors[:name].
|
19
|
+
expect(subject).not_to be_valid
|
20
|
+
expect(subject.errors[:name]).to eq ["has already been taken"]
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should be invalid if missing client_id' do
|
24
24
|
subject.client_id = nil
|
25
|
-
subject.
|
26
|
-
subject.errors[:client_id].
|
25
|
+
expect(subject).not_to be_valid
|
26
|
+
expect(subject.errors[:client_id]).to eq ["can't be blank"]
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should be invalid if missing client_secret' do
|
30
30
|
subject.client_secret = nil
|
31
|
-
subject.
|
32
|
-
subject.errors[:client_secret].
|
31
|
+
expect(subject).not_to be_valid
|
32
|
+
expect(subject.errors[:client_secret]).to eq ["can't be blank"]
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#access_token_expired?' do
|
@@ -42,17 +42,17 @@ describe Rpush::Client::ActiveRecord::Adm::App do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should return true if access_token_expiration is nil' do
|
45
|
-
subject.access_token_expired
|
45
|
+
expect(subject.access_token_expired?).to eq(true)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should return true if expired' do
|
49
49
|
subject.access_token_expiration = Time.now - 5.minutes
|
50
|
-
subject.access_token_expired
|
50
|
+
expect(subject.access_token_expired?).to eq(true)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should return false if not expired' do
|
54
54
|
subject.access_token_expiration = Time.now + 5.minutes
|
55
|
-
subject.access_token_expired
|
55
|
+
expect(subject.access_token_expired?).to eq(false)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -10,14 +10,14 @@ describe Rpush::Client::ActiveRecord::Adm::Notification do
|
|
10
10
|
|
11
11
|
it "has a 'data' payload limit of 6144 bytes" do
|
12
12
|
notification.data = { key: "a" * 6144 }
|
13
|
-
notification.valid
|
14
|
-
notification.errors[:base].
|
13
|
+
expect(notification.valid?).to eq(false)
|
14
|
+
expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 6144 bytes."]
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'limits the number of registration ids to 100' do
|
18
18
|
notification.registration_ids = ['a'] * (100 + 1)
|
19
|
-
notification.valid
|
20
|
-
notification.errors[:base].
|
19
|
+
expect(notification.valid?).to eq(false)
|
20
|
+
expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 100."]
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'validates data can be blank if collapse_key is set' do
|
@@ -25,19 +25,19 @@ describe Rpush::Client::ActiveRecord::Adm::Notification do
|
|
25
25
|
notification.registration_ids = 'a'
|
26
26
|
notification.collapse_key = 'test'
|
27
27
|
notification.data = nil
|
28
|
-
notification.valid
|
29
|
-
notification.errors[:data].
|
28
|
+
expect(notification.valid?).to eq(true)
|
29
|
+
expect(notification.errors[:data]).to be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'validates data is present if collapse_key is not set' do
|
33
33
|
notification.collapse_key = nil
|
34
34
|
notification.data = nil
|
35
|
-
notification.valid
|
36
|
-
notification.errors[:data].
|
35
|
+
expect(notification.valid?).to eq(false)
|
36
|
+
expect(notification.errors[:data]).to eq ['must be set unless collapse_key is specified']
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'includes expiresAfter in the payload' do
|
40
40
|
notification.expiry = 100
|
41
|
-
notification.as_json['expiresAfter'].
|
41
|
+
expect(notification.as_json['expiresAfter']).to eq 100
|
42
42
|
end
|
43
43
|
end
|
@@ -4,26 +4,26 @@ describe Rpush::Client::ActiveRecord::App do
|
|
4
4
|
it 'does not validate an app with an invalid certificate' do
|
5
5
|
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'foo')
|
6
6
|
app.valid?
|
7
|
-
app.errors[:certificate].
|
7
|
+
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'validates a certificate without a password' do
|
11
11
|
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development', certificate: TEST_CERT
|
12
12
|
app.valid?
|
13
|
-
app.errors[:certificate].
|
13
|
+
expect(app.errors[:certificate]).to eq []
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'validates a certificate with a password' do
|
17
17
|
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development',
|
18
18
|
certificate: TEST_CERT_WITH_PASSWORD, password: 'fubar'
|
19
19
|
app.valid?
|
20
|
-
app.errors[:certificate].
|
20
|
+
expect(app.errors[:certificate]).to eq []
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'validates a certificate with an incorrect password' do
|
24
24
|
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development',
|
25
25
|
certificate: TEST_CERT_WITH_PASSWORD, password: 'incorrect'
|
26
26
|
app.valid?
|
27
|
-
app.errors[:certificate].
|
27
|
+
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
|
28
28
|
end
|
29
29
|
end
|
@@ -3,7 +3,7 @@ require 'unit_spec_helper'
|
|
3
3
|
describe Rpush::Client::ActiveRecord::Apns::Feedback do
|
4
4
|
it 'validates the format of the device_token' do
|
5
5
|
notification = Rpush::Client::ActiveRecord::Apns::Feedback.new(device_token: "{$%^&*()}")
|
6
|
-
notification.valid
|
7
|
-
notification.errors[:device_token].include
|
6
|
+
expect(notification.valid?).to be_falsey
|
7
|
+
expect(notification.errors[:device_token]).to include('is invalid')
|
8
8
|
end
|
9
9
|
end
|
@@ -12,85 +12,85 @@ describe Rpush::Client::ActiveRecord::Apns::Notification do
|
|
12
12
|
|
13
13
|
it "should validate the format of the device_token" do
|
14
14
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "{$%^&*()}")
|
15
|
-
notification.valid
|
16
|
-
notification.errors[:device_token].include?("is invalid").
|
15
|
+
expect(notification.valid?).to be_falsey
|
16
|
+
expect(notification.errors[:device_token].include?("is invalid")).to be_truthy
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should validate the length of the binary conversion of the notification" do
|
20
20
|
notification.device_token = "a" * 64
|
21
21
|
notification.alert = "way too long!" * 200
|
22
|
-
notification.valid
|
23
|
-
notification.errors[:base].include?("APN notification cannot be larger than 2048 bytes. Try condensing your alert and device attributes.").
|
22
|
+
expect(notification.valid?).to be_falsey
|
23
|
+
expect(notification.errors[:base].include?("APN notification cannot be larger than 2048 bytes. Try condensing your alert and device attributes.")).to be_truthy
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should default the sound to 'default'" do
|
27
|
-
notification.sound.
|
27
|
+
expect(notification.sound).to eq('default')
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should default the expiry to 1 day" do
|
31
|
-
notification.expiry.
|
31
|
+
expect(notification.expiry).to eq 1.day.to_i
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe Rpush::Client::ActiveRecord::Apns::Notification, "when assigning the device token" do
|
36
36
|
it "should strip spaces from the given string" do
|
37
37
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "o m g")
|
38
|
-
notification.device_token.
|
38
|
+
expect(notification.device_token).to eq "omg"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should strip chevrons from the given string" do
|
42
42
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(device_token: "<omg>")
|
43
|
-
notification.device_token.
|
43
|
+
expect(notification.device_token).to eq "omg"
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
|
48
48
|
it "should include the alert if present" do
|
49
49
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: "hi mom")
|
50
|
-
notification.as_json["aps"]["alert"].
|
50
|
+
expect(notification.as_json["aps"]["alert"]).to eq "hi mom"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should not include the alert key if the alert is not present" do
|
54
54
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: nil)
|
55
|
-
notification.as_json["aps"].key?("alert").
|
55
|
+
expect(notification.as_json["aps"].key?("alert")).to be_falsey
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should encode the alert as JSON if it is a Hash" do
|
59
59
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { 'body' => "hi mom", 'alert-loc-key' => "View" })
|
60
|
-
notification.as_json["aps"]["alert"].
|
60
|
+
expect(notification.as_json["aps"]["alert"]).to eq('body' => "hi mom", 'alert-loc-key' => "View")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should include the badge if present" do
|
64
64
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(badge: 6)
|
65
|
-
notification.as_json["aps"]["badge"].
|
65
|
+
expect(notification.as_json["aps"]["badge"]).to eq 6
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should not include the badge key if the badge is not present" do
|
69
69
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(badge: nil)
|
70
|
-
notification.as_json["aps"].key?("badge").
|
70
|
+
expect(notification.as_json["aps"].key?("badge")).to be_falsey
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should include the sound if present" do
|
74
74
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: "my_sound.aiff")
|
75
|
-
notification.as_json["aps"]["alert"].
|
75
|
+
expect(notification.as_json["aps"]["alert"]).to eq "my_sound.aiff"
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should not include the sound key if the sound is not present" do
|
79
79
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: nil)
|
80
|
-
notification.as_json["aps"].key?("sound").
|
80
|
+
expect(notification.as_json["aps"].key?("sound")).to be_falsey
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should include attributes for the device" do
|
84
84
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
85
85
|
notification.data = { omg: :lol, wtf: :dunno }
|
86
|
-
notification.as_json["omg"].
|
87
|
-
notification.as_json["wtf"].
|
86
|
+
expect(notification.as_json["omg"]).to eq "lol"
|
87
|
+
expect(notification.as_json["wtf"]).to eq "dunno"
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should allow attributes to include a hash" do
|
91
91
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
92
92
|
notification.data = { omg: { ilike: :hashes } }
|
93
|
-
notification.as_json["omg"]["ilike"].
|
93
|
+
expect(notification.as_json["omg"]["ilike"]).to eq "hashes"
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -100,13 +100,13 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'MDM' do
|
|
100
100
|
|
101
101
|
it 'includes the mdm magic in the payload' do
|
102
102
|
notification.mdm = magic
|
103
|
-
notification.as_json.
|
103
|
+
expect(notification.as_json).to eq('mdm' => magic)
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'does not include aps attribute' do
|
107
107
|
notification.alert = "i'm doomed"
|
108
108
|
notification.mdm = magic
|
109
|
-
notification.as_json.key?('aps').
|
109
|
+
expect(notification.as_json.key?('aps')).to be_falsey
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -115,30 +115,30 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'content-available' do
|
|
115
115
|
|
116
116
|
it 'includes content-available in the payload' do
|
117
117
|
notification.content_available = true
|
118
|
-
notification.as_json['aps']['content-available'].
|
118
|
+
expect(notification.as_json['aps']['content-available']).to eq 1
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'does not include content-available in the payload if not set' do
|
122
|
-
notification.as_json['aps'].key?('content-available').
|
122
|
+
expect(notification.as_json['aps'].key?('content-available')).to be_falsey
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'does not include content-available as a non-aps attribute' do
|
126
126
|
notification.content_available = true
|
127
|
-
notification.as_json.key?('content-available').
|
127
|
+
expect(notification.as_json.key?('content-available')).to be_falsey
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'does not overwrite existing attributes for the device' do
|
131
131
|
notification.data = { hi: :mom }
|
132
132
|
notification.content_available = true
|
133
|
-
notification.as_json['aps']['content-available'].
|
134
|
-
notification.as_json['hi'].
|
133
|
+
expect(notification.as_json['aps']['content-available']).to eq 1
|
134
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'does not overwrite the content-available flag when setting attributes for the device' do
|
138
138
|
notification.content_available = true
|
139
139
|
notification.data = { hi: :mom }
|
140
|
-
notification.as_json['aps']['content-available'].
|
141
|
-
notification.as_json['hi'].
|
140
|
+
expect(notification.as_json['aps']['content-available']).to eq 1
|
141
|
+
expect(notification.as_json['hi']).to eq 'mom'
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -147,11 +147,11 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'url-args' do
|
|
147
147
|
|
148
148
|
it 'includes url-args in the payload' do
|
149
149
|
notification.url_args = ['url-arg-1']
|
150
|
-
notification.as_json['aps']['url-args'].
|
150
|
+
expect(notification.as_json['aps']['url-args']).to eq ['url-arg-1']
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'does not include url-args in the payload if not set' do
|
154
|
-
notification.as_json['aps'].key?('url-args').
|
154
|
+
expect(notification.as_json['aps'].key?('url-args')).to be_falsey
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -160,11 +160,11 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'category' do
|
|
160
160
|
|
161
161
|
it 'includes category in the payload' do
|
162
162
|
notification.category = 'INVITE_CATEGORY'
|
163
|
-
notification.as_json['aps']['category'].
|
163
|
+
expect(notification.as_json['aps']['category']).to eq 'INVITE_CATEGORY'
|
164
164
|
end
|
165
165
|
|
166
166
|
it 'does not include category in the payload if not set' do
|
167
|
-
notification.as_json['aps'].key?('category').
|
167
|
+
expect(notification.as_json['aps'].key?('category')).to be_falsey
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -182,8 +182,8 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'to_binary' do
|
|
182
182
|
notification.sound = nil
|
183
183
|
notification.content_available = true
|
184
184
|
bytes = notification.to_binary.bytes.to_a[-4..-1]
|
185
|
-
bytes.first.
|
186
|
-
bytes.last.
|
185
|
+
expect(bytes.first).to eq 5 # priority item ID
|
186
|
+
expect(bytes.last).to eq Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_CONSERVE_POWER
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'uses APNS_PRIORITY_IMMEDIATE if content-available is not the only key' do
|
@@ -192,8 +192,8 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'to_binary' do
|
|
192
192
|
notification.sound = nil
|
193
193
|
notification.content_available = true
|
194
194
|
bytes = notification.to_binary.bytes.to_a[-4..-1]
|
195
|
-
bytes.first.
|
196
|
-
bytes.last.
|
195
|
+
expect(bytes.first).to eq 5 # priority item ID
|
196
|
+
expect(bytes.last).to eq Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_IMMEDIATE
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should correctly convert the notification to binary" do
|
@@ -204,7 +204,7 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, 'to_binary' do
|
|
204
204
|
notification.expiry = 86_400 # 1 day, \x00\x01Q\x80
|
205
205
|
notification.priority = Rpush::Client::ActiveRecord::Apns::Notification::APNS_PRIORITY_IMMEDIATE
|
206
206
|
notification.app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'my_app', environment: 'development', certificate: TEST_CERT)
|
207
|
-
notification.to_binary.
|
207
|
+
expect(notification.to_binary).to eq "\x02\x00\x00\x00\x99\x01\x00 \xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\x02\x00a{\"aps\":{\"alert\":\"Don't panic Mr Mainwaring, don't panic!\",\"badge\":3,\"sound\":\"1.aiff\"},\"hi\":\"mom\"}\x03\x00\x04\x00\x00\x04\xD2\x04\x00\x04\x00\x01Q\x80\x05\x00\x01\n"
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -212,14 +212,14 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "bug #31" do
|
|
212
212
|
it 'does not confuse a JSON looking string as JSON' do
|
213
213
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
214
214
|
notification.alert = "{\"one\":2}"
|
215
|
-
notification.alert.
|
215
|
+
expect(notification.alert).to eq "{\"one\":2}"
|
216
216
|
end
|
217
217
|
|
218
218
|
it 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
|
219
219
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new
|
220
|
-
notification.
|
220
|
+
allow(notification).to receive_messages(:has_attribute? => false)
|
221
221
|
notification.alert = "{\"one\":2}"
|
222
|
-
notification.alert.
|
222
|
+
expect(notification.alert).to eq('one' => 2)
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
@@ -231,9 +231,9 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "bug #35" do
|
|
231
231
|
n.app = Rpush::Client::ActiveRecord::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT)
|
232
232
|
end
|
233
233
|
|
234
|
-
notification.to_binary(for_validation: true).bytesize.
|
235
|
-
notification.payload.bytesize.
|
236
|
-
notification.
|
234
|
+
expect(notification.to_binary(for_validation: true).bytesize).to be > 256
|
235
|
+
expect(notification.payload.bytesize).to be < 256
|
236
|
+
expect(notification).to be_valid
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
@@ -241,15 +241,15 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "multi_json usage" do
|
|
241
241
|
describe Rpush::Client::ActiveRecord::Apns::Notification, "alert" do
|
242
242
|
it "should call MultiJson.load when multi_json version is 1.3.0" do
|
243
243
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { a: 1 }, alert_is_json: true)
|
244
|
-
Gem.
|
245
|
-
MultiJson.
|
244
|
+
allow(Gem).to receive(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.3.0'))
|
245
|
+
expect(MultiJson).to receive(:load).with(any_args)
|
246
246
|
notification.alert
|
247
247
|
end
|
248
248
|
|
249
249
|
it "should call MultiJson.decode when multi_json version is 1.2.9" do
|
250
250
|
notification = Rpush::Client::ActiveRecord::Apns::Notification.new(alert: { a: 1 }, alert_is_json: true)
|
251
|
-
Gem.
|
252
|
-
MultiJson.
|
251
|
+
allow(Gem).to receive(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.2.9'))
|
252
|
+
expect(MultiJson).to receive(:decode).with(any_args)
|
253
253
|
notification.alert
|
254
254
|
end
|
255
255
|
end
|