rpush 4.2.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +248 -163
  3. data/README.md +103 -17
  4. data/lib/generators/templates/add_gcm.rb +4 -4
  5. data/lib/generators/templates/add_rpush.rb +4 -4
  6. data/lib/generators/templates/rpush.rb +4 -0
  7. data/lib/generators/templates/rpush_3_3_1_updates.rb +2 -2
  8. data/lib/rpush/cli.rb +1 -1
  9. data/lib/rpush/client/active_model.rb +4 -1
  10. data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
  11. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
  12. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  13. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  14. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  15. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
  16. data/lib/rpush/client/active_model/gcm/notification.rb +2 -2
  17. data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
  18. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
  19. data/lib/rpush/client/active_model/webpush/app.rb +41 -0
  20. data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
  21. data/lib/rpush/client/active_record.rb +4 -0
  22. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  23. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  24. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  25. data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
  26. data/lib/rpush/client/active_record/webpush/app.rb +11 -0
  27. data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
  28. data/lib/rpush/client/redis.rb +3 -0
  29. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  30. data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
  31. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  32. data/lib/rpush/client/redis/webpush/app.rb +15 -0
  33. data/lib/rpush/client/redis/webpush/notification.rb +15 -0
  34. data/lib/rpush/configuration.rb +3 -2
  35. data/lib/rpush/daemon.rb +4 -1
  36. data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
  37. data/lib/rpush/daemon/apns2/delivery.rb +13 -2
  38. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  39. data/lib/rpush/daemon/app_runner.rb +1 -1
  40. data/lib/rpush/daemon/batch.rb +12 -5
  41. data/lib/rpush/daemon/delivery.rb +1 -2
  42. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  43. data/lib/rpush/daemon/webpush.rb +10 -0
  44. data/lib/rpush/daemon/webpush/delivery.rb +114 -0
  45. data/lib/rpush/logger.rb +1 -0
  46. data/lib/rpush/version.rb +2 -2
  47. data/spec/functional/apns2_spec.rb +97 -2
  48. data/spec/functional/gcm_priority_spec.rb +40 -0
  49. data/spec/functional/webpush_spec.rb +30 -0
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/support/simplecov_helper.rb +1 -1
  52. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  53. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  54. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  55. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  56. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  57. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  58. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  59. data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
  60. data/spec/unit/client/active_record/app_spec.rb +1 -26
  61. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  62. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  63. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  64. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  65. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  66. data/spec/unit/client/active_record/shared/app.rb +14 -0
  67. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  68. data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
  69. data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
  70. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  71. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  72. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  73. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  74. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  75. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  76. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  77. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  78. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  79. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  80. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  81. data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
  82. data/spec/unit/client/redis/app_spec.rb +5 -0
  83. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  84. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  85. data/spec/unit/client/redis/notification_spec.rb +5 -0
  86. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  87. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  88. data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
  89. data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
  90. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  91. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  92. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  93. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  94. data/spec/unit/client/shared/adm/app.rb +51 -0
  95. data/spec/unit/client/shared/adm/notification.rb +39 -0
  96. data/spec/unit/client/shared/apns/app.rb +29 -0
  97. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  98. data/spec/unit/client/shared/apns/notification.rb +262 -0
  99. data/spec/unit/client/shared/app.rb +17 -0
  100. data/spec/unit/client/shared/gcm/app.rb +4 -0
  101. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  102. data/spec/unit/client/shared/notification.rb +10 -0
  103. data/spec/unit/client/shared/pushy/app.rb +17 -0
  104. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  105. data/spec/unit/client/shared/webpush/app.rb +33 -0
  106. data/spec/unit/client/shared/webpush/notification.rb +83 -0
  107. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  108. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  109. data/spec/unit/client/shared/wpns/app.rb +4 -0
  110. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  111. data/spec/unit/daemon/batch_spec.rb +50 -2
  112. data/spec/unit/daemon/delivery_spec.rb +10 -0
  113. data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
  114. data/spec/unit/daemon/shared/store.rb +312 -0
  115. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  116. data/spec/unit/daemon/store/active_record_spec.rb +2 -290
  117. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  118. data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
  119. data/spec/unit_spec_helper.rb +3 -0
  120. metadata +135 -12
  121. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -0,0 +1,4 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::ActiveRecord::Apns2::App do
4
+ end if active_record?
@@ -0,0 +1,65 @@
1
+ require "unit_spec_helper"
2
+
3
+ describe Rpush::Client::ActiveRecord::Apns2::Notification do
4
+ subject(:notification) { described_class.new }
5
+
6
+ it_behaves_like 'Rpush::Client::Apns::Notification'
7
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
8
+
9
+ it "should validate the length of the binary conversion of the notification" do
10
+ notification = described_class.new
11
+ notification.app = Rpush::Apns2::App.create(name: 'test', environment: 'development')
12
+ notification.device_token = "a" * 108
13
+ notification.alert = ""
14
+
15
+ notification.alert << "a" until notification.payload.bytesize == 4096
16
+ expect(notification.valid?).to be_truthy
17
+ expect(notification.errors[:base]).to be_empty
18
+
19
+ notification.alert << "a"
20
+ expect(notification.valid?).to be_falsey
21
+ expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
22
+ end
23
+
24
+ describe "multi_json usage" do
25
+ describe "alert" do
26
+ subject(:notification) { described_class.new(alert: { a: 1 }, alert_is_json: true) }
27
+
28
+ it "should call MultiJson.load when multi_json version is 1.3.0" do
29
+ allow(Gem).to receive(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.3.0'))
30
+ expect(MultiJson).to receive(:load).with(any_args)
31
+ notification.alert
32
+ end
33
+
34
+ it "should call MultiJson.decode when multi_json version is 1.2.9" do
35
+ allow(Gem).to receive(:loaded_specs).and_return('multi_json' => Gem::Specification.new('multi_json', '1.2.9'))
36
+ expect(MultiJson).to receive(:decode).with(any_args)
37
+ notification.alert
38
+ end
39
+ end
40
+ end
41
+
42
+ it "should default the sound to nil" do
43
+ expect(notification.sound).to be_nil
44
+ end
45
+
46
+ it 'does not overwrite the mutable-content flag when setting attributes for the device' do
47
+ notification.mutable_content = true
48
+ notification.data = { 'hi' => 'mom' }
49
+ expect(notification.as_json['aps']['mutable-content']).to eq 1
50
+ expect(notification.as_json['hi']).to eq 'mom'
51
+ end
52
+
53
+ it 'does not overwrite the content-available flag when setting attributes for the device' do
54
+ notification.content_available = true
55
+ notification.data = { 'hi' => 'mom' }
56
+ expect(notification.as_json['aps']['content-available']).to eq 1
57
+ expect(notification.as_json['hi']).to eq 'mom'
58
+ end
59
+
60
+ it 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
61
+ allow(notification).to receive_messages(has_attribute?: false)
62
+ notification.alert = "{\"one\":2}"
63
+ expect(notification.alert).to eq('one' => 2)
64
+ end
65
+ end if active_record?
@@ -0,0 +1,28 @@
1
+ require "unit_spec_helper"
2
+
3
+ describe Rpush::Client::ActiveRecord::Apnsp8::Notification do
4
+ subject(:notification) { described_class.new }
5
+
6
+ it_behaves_like 'Rpush::Client::Apns::Notification'
7
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
8
+
9
+ it "should validate the length of the binary conversion of the notification", :aggregate_failures do
10
+ notification = described_class.new
11
+ notification.app = Rpush::Apnsp8::App.create(apn_key: "1",
12
+ apn_key_id: "2",
13
+ name: 'test',
14
+ environment: 'development',
15
+ team_id: "3",
16
+ bundle_id: "4")
17
+ notification.device_token = "a" * 108
18
+ notification.alert = ""
19
+
20
+ notification.alert << "a" until notification.payload.bytesize == 4096
21
+ expect(notification.valid?).to be_truthy
22
+ expect(notification.errors[:base]).to be_empty
23
+
24
+ notification.alert << "a"
25
+ expect(notification.valid?).to be_falsey
26
+ expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
27
+ end
28
+ end if active_record?
@@ -1,30 +1,5 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::App do
4
- it 'validates the uniqueness of name within type and environment' do
5
- Rpush::Client::ActiveRecord::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
6
- app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'production', certificate: TEST_CERT)
7
- expect(app.valid?).to eq(false)
8
- expect(app.errors[:name]).to eq ['has already been taken']
9
-
10
- app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: TEST_CERT)
11
- expect(app.valid?).to eq(true)
12
-
13
- app = Rpush::Client::ActiveRecord::Gcm::App.new(name: 'test', environment: 'production', auth_key: TEST_CERT)
14
- expect(app.valid?).to eq(true)
15
- end
16
-
17
- context 'validating certificates' do
18
- it 'rescues from certificate error' do
19
- app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
20
- expect { app.valid? }.not_to raise_error
21
- expect(app.valid?).to eq(false)
22
- end
23
-
24
- it 'raises other errors' do
25
- app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
26
- allow(OpenSSL::X509::Certificate).to receive(:new).and_raise(NameError, 'simulating no openssl')
27
- expect { app.valid? }.to raise_error(NameError)
28
- end
29
- end
4
+ it_behaves_like 'Rpush::Client::App'
30
5
  end if active_record?
@@ -1,4 +1,6 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Gcm::App do
4
- end
4
+ it_behaves_like 'Rpush::Client::Gcm::App'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::App'
6
+ end if active_record?
@@ -1,96 +1,14 @@
1
1
  require 'unit_spec_helper'
2
- require 'unit/notification_shared.rb'
3
2
 
4
3
  describe Rpush::Client::ActiveRecord::Gcm::Notification do
5
- it_should_behave_like 'an Notification subclass'
4
+ it_behaves_like 'Rpush::Client::Gcm::Notification'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
6
6
 
7
- let(:app) { Rpush::Client::ActiveRecord::Gcm::App.create!(name: 'test', auth_key: 'abc') }
8
- let(:notification_class) { Rpush::Client::ActiveRecord::Gcm::Notification }
9
- let(:notification) { notification_class.new }
7
+ subject(:notification) { described_class.new }
8
+ let(:app) { Rpush::Gcm::App.create!(name: 'test', auth_key: 'abc') }
10
9
 
11
- it "has a 'data' payload limit of 4096 bytes" do
12
- notification.data = { key: "a" * 4096 }
13
- expect(notification.valid?).to be_falsey
14
- expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 4096 bytes."]
15
- end
16
-
17
- it 'limits the number of registration ids to 1000' do
18
- notification.registration_ids = ['a'] * (1000 + 1)
19
- expect(notification.valid?).to be_falsey
20
- expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 1000."]
21
- end
22
-
23
- it 'validates expiry is present if collapse_key is set' do
24
- notification.collapse_key = 'test'
25
- notification.expiry = nil
26
- expect(notification.valid?).to be_falsey
27
- expect(notification.errors[:expiry]).to eq ['must be set when using a collapse_key']
28
- end
29
-
30
- it 'includes time_to_live in the payload' do
31
- notification.expiry = 100
32
- expect(notification.as_json['time_to_live']).to eq 100
33
- end
34
-
35
- it 'includes content_available in the payload' do
36
- notification.content_available = true
37
- expect(notification.as_json['content_available']).to eq true
38
- end
39
-
40
- it 'includes mutable_content in the payload' do
41
- notification.mutable_content = true
42
- expect(notification.as_json['mutable_content']).to eq true
43
- end
44
-
45
- it 'sets the priority to high when set to high' do
46
- notification.priority = 'high'
47
- expect(notification.as_json['priority']).to eq 'high'
48
- end
49
-
50
- it 'sets the priority to normal when set to normal' do
51
- notification.priority = 'normal'
52
- expect(notification.as_json['priority']).to eq 'normal'
53
- end
54
-
55
- it 'validates the priority is either "normal" or "high"' do
56
- notification.priority = 'invalid'
57
- expect(notification.errors[:priority]).to eq ['must be one of either "normal" or "high"']
58
- end
59
-
60
- it 'excludes the priority if it is not defined' do
61
- expect(notification.as_json).not_to have_key 'priority'
62
- end
63
-
64
- it 'includes the notification payload if defined' do
65
- notification.notification = { key: 'any key is allowed' }
66
- expect(notification.as_json).to have_key 'notification'
67
- end
68
-
69
- it 'excludes the notification payload if undefined' do
70
- expect(notification.as_json).not_to have_key 'notification'
71
- end
72
-
73
- it 'includes the dry_run payload if defined' do
74
- notification.dry_run = true
10
+ it 'accepts non-booleans as a truthy value' do
11
+ notification.dry_run = 'Not a boolean'
75
12
  expect(notification.as_json['dry_run']).to eq true
76
13
  end
77
-
78
- it 'excludes the dry_run payload if undefined' do
79
- expect(notification.as_json).not_to have_key 'dry_run'
80
- end
81
-
82
- # In Rails 4.2 this value casts to `false` and thus will not be included in
83
- # the payload. This changed to match Ruby's semantics, and will casts to
84
- # `true` in Rails 5 and above.
85
- if ActiveRecord.version <= Gem::Version.new('5')
86
- it 'accepts non-booleans as a falsey value' do
87
- notification.dry_run = 'Not a boolean'
88
- expect(notification.as_json).not_to have_key 'dry_run'
89
- end
90
- else
91
- it 'accepts non-booleans as a truthy value' do
92
- notification.dry_run = 'Not a boolean'
93
- expect(notification.as_json['dry_run']).to eq true
94
- end
95
- end
96
14
  end if active_record?
@@ -1,20 +1,12 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Notification do
4
- let(:notification) { Rpush::Client::ActiveRecord::Notification.new }
4
+ it_behaves_like 'Rpush::Client::Notification'
5
5
 
6
- it 'allows assignment of many registration IDs' do
7
- notification.registration_ids = %w(a b)
8
- expect(notification.registration_ids).to eq %w(a b)
9
- end
10
-
11
- it 'allows assignment of a single registration ID' do
12
- notification.registration_ids = 'a'
13
- expect(notification.registration_ids).to eq ['a']
14
- end
6
+ subject(:notification) { described_class.new }
15
7
 
16
8
  it 'saves its parent App if required' do
17
- notification.app = Rpush::Client::ActiveRecord::App.new(name: "aname")
9
+ notification.app = Rpush::App.new(name: "aname")
18
10
  expect(notification.app).to be_valid
19
11
  expect(notification).to be_valid
20
12
  end
@@ -1,17 +1,6 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Pushy::App do
4
- describe 'validates' do
5
- subject { described_class.new }
6
-
7
- it 'validates presence of name' do
8
- is_expected.not_to be_valid
9
- expect(subject.errors[:name]).to eq ["can't be blank"]
10
- end
11
-
12
- it 'validates presence of api_key' do
13
- is_expected.not_to be_valid
14
- expect(subject.errors[:api_key]).to eq ["can't be blank"]
15
- end
16
- end
4
+ it_behaves_like 'Rpush::Client::Pushy::App'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::App'
17
6
  end if active_record?
@@ -1,59 +1,6 @@
1
1
  require 'unit_spec_helper'
2
- require 'unit/notification_shared.rb'
3
2
 
4
3
  describe Rpush::Client::ActiveRecord::Pushy::Notification do
5
- let(:notification_class) { described_class }
6
- subject(:notification) { notification_class.new }
7
-
8
- it_behaves_like 'an Notification subclass'
9
-
10
- describe 'validates' do
11
- let(:app) { Rpush::Client::ActiveRecord::Pushy::App.create!(name: 'MyApp', api_key: 'my_api_key') }
12
-
13
- describe 'data' do
14
- subject { described_class.new(app: app, registration_ids: ['id']) }
15
- it 'validates presence' do
16
- is_expected.not_to be_valid
17
- expect(subject.errors[:data]).to eq ["can't be blank"]
18
- end
19
-
20
- it "has a 'data' payload limit of 4096 bytes" do
21
- subject.data = { message: 'a' * 4096 }
22
- is_expected.not_to be_valid
23
- expected_errors = ["Notification payload data cannot be larger than 4096 bytes."]
24
- expect(subject.errors[:base]).to eq expected_errors
25
- end
26
- end
27
-
28
- describe 'registration_ids' do
29
- subject { described_class.new(app: app, data: { message: 'test' }) }
30
- it 'validates presence' do
31
- is_expected.not_to be_valid
32
- expect(subject.errors[:registration_ids]).to eq ["can't be blank"]
33
- end
34
-
35
- it 'limits the number of registration ids to 1000' do
36
- subject.registration_ids = ['a'] * (1000 + 1)
37
- is_expected.not_to be_valid
38
- expected_errors = ["Number of registration_ids cannot be larger than 1000."]
39
- expect(subject.errors[:base]).to eq expected_errors
40
- end
41
- end
42
-
43
- describe 'time_to_live' do
44
- subject { described_class.new(app: app, data: { message: 'test' }, registration_ids: ['id']) }
45
-
46
- it 'should be > 0' do
47
- subject.time_to_live = -1
48
- is_expected.not_to be_valid
49
- expect(subject.errors[:time_to_live]).to eq ['must be greater than 0']
50
- end
51
-
52
- it 'should be <= 1.year.seconds' do
53
- subject.time_to_live = 2.years.seconds.to_i
54
- is_expected.not_to be_valid
55
- expect(subject.errors[:time_to_live]).to eq ['The maximum value is 1 year']
56
- end
57
- end
58
- end
4
+ it_behaves_like 'Rpush::Client::Pushy::Notification'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
59
6
  end if active_record?
@@ -0,0 +1,14 @@
1
+ shared_examples_for 'Rpush::Client::ActiveRecord::App' do
2
+ it 'validates the uniqueness of name within type and environment' do
3
+ Rpush::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
4
+ app = Rpush::Apns::App.new(name: 'test', environment: 'production', certificate: TEST_CERT)
5
+ expect(app.valid?).to eq(false)
6
+ expect(app.errors[:name]).to eq ['has already been taken']
7
+
8
+ app = Rpush::Apns::App.new(name: 'test', environment: 'development', certificate: TEST_CERT)
9
+ expect(app.valid?).to eq(true)
10
+
11
+ app = Rpush::Gcm::App.new(name: 'test', environment: 'production', auth_key: TEST_CERT)
12
+ expect(app.valid?).to eq(true)
13
+ end
14
+ end
@@ -1,16 +1,21 @@
1
- shared_examples_for 'an Notification subclass' do
1
+ shared_examples_for 'Rpush::Client::ActiveRecord::Notification' do
2
+ let(:notification) { described_class.new }
3
+
4
+ it 'allows assignment of a single registration ID' do
5
+ notification.registration_ids = 'a'
6
+ expect(notification.registration_ids).to eq ['a']
7
+ end
8
+
2
9
  describe 'when assigning data for the device' do
3
10
  before { allow(Rpush::Deprecation).to receive(:warn) }
4
11
 
5
12
  it 'calls MultiJson.dump when multi_json responds to :dump' do
6
- notification = notification_class.new
7
13
  allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(true)
8
14
  expect(MultiJson).to receive(:dump).with(any_args)
9
15
  notification.data = { pirates: 1 }
10
16
  end
11
17
 
12
18
  it 'calls MultiJson.encode when multi_json does not respond to :dump' do
13
- notification = notification_class.new
14
19
  allow(MultiJson).to receive(:respond_to?).with(:dump).and_return(false)
15
20
  expect(MultiJson).to receive(:encode).with(any_args)
16
21
  notification.data = { ninjas: 1 }
@@ -23,12 +28,12 @@ shared_examples_for 'an Notification subclass' do
23
28
  end
24
29
 
25
30
  it 'encodes the given Hash as JSON' do
26
- notification.data = { hi: 'mom'}
31
+ notification.data = { hi: 'mom' }
27
32
  expect(notification.read_attribute(:data)).to eq('{"hi":"mom"}')
28
33
  end
29
34
 
30
35
  it 'decodes the JSON when using the reader method' do
31
- notification.data = { hi: 'mom'}
36
+ notification.data = { hi: 'mom' }
32
37
  expect(notification.data).to eq('hi' => 'mom')
33
38
  end
34
39
  end
@@ -41,12 +46,12 @@ shared_examples_for 'an Notification subclass' do
41
46
  end
42
47
 
43
48
  it 'encodes the given Hash as JSON' do
44
- notification.notification = { hi: 'dad'}
49
+ notification.notification = { hi: 'dad' }
45
50
  expect(notification.read_attribute(:notification)).to eq('{"hi":"dad"}')
46
51
  end
47
52
 
48
53
  it 'decodes the JSON when using the reader method' do
49
- notification.notification = { hi: 'dad'}
54
+ notification.notification = { hi: 'dad' }
50
55
  expect(notification.notification).to eq('hi' => 'dad')
51
56
  end
52
57
  end
@@ -0,0 +1,6 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::ActiveRecord::Webpush::App do
4
+ it_behaves_like 'Rpush::Client::Webpush::App'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::App'
6
+ end if active_record?
@@ -0,0 +1,6 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::ActiveRecord::Webpush::Notification do
4
+ it_behaves_like 'Rpush::Client::Webpush::Notification'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
6
+ end if active_record?
@@ -1,15 +1,5 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Wns::BadgeNotification do
4
- let(:notification) do
5
- notif = Rpush::Client::ActiveRecord::Wns::BadgeNotification.new
6
- notif.app = Rpush::Client::ActiveRecord::Wns::App.new(name: "aname")
7
- notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
8
- notif.badge = 42
9
- notif
10
- end
11
-
12
- it 'should allow a notification without data' do
13
- expect(notification.valid?).to be(true)
14
- end
4
+ it_behaves_like 'Rpush::Client::Wns::BadgeNotification'
15
5
  end if active_record?