rpush 5.0.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/lib/rpush/cli.rb +1 -1
  4. data/lib/rpush/client/active_model.rb +1 -1
  5. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  6. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  7. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  8. data/lib/rpush/client/active_record.rb +1 -0
  9. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  10. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  11. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  12. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  13. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  14. data/lib/rpush/daemon/apns2/delivery.rb +6 -1
  15. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  16. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  17. data/lib/rpush/version.rb +1 -1
  18. data/spec/functional/apns2_spec.rb +36 -0
  19. data/spec/support/simplecov_helper.rb +1 -1
  20. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  21. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  22. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  23. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  24. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  25. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  26. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  27. data/spec/unit/client/active_record/app_spec.rb +1 -26
  28. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  29. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  30. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  31. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  32. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  33. data/spec/unit/client/active_record/shared/app.rb +14 -0
  34. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  35. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  36. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  37. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  38. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  39. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  40. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  41. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  42. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  43. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  44. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  45. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  46. data/spec/unit/client/redis/app_spec.rb +5 -0
  47. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  48. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  49. data/spec/unit/client/redis/notification_spec.rb +5 -0
  50. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  51. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  52. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  53. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  54. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  55. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  56. data/spec/unit/client/shared/adm/app.rb +51 -0
  57. data/spec/unit/client/shared/adm/notification.rb +39 -0
  58. data/spec/unit/client/shared/apns/app.rb +29 -0
  59. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  60. data/spec/unit/client/shared/apns/notification.rb +262 -0
  61. data/spec/unit/client/shared/app.rb +17 -0
  62. data/spec/unit/client/shared/gcm/app.rb +4 -0
  63. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  64. data/spec/unit/client/shared/notification.rb +10 -0
  65. data/spec/unit/client/shared/pushy/app.rb +17 -0
  66. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  67. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  68. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  69. data/spec/unit/client/shared/wpns/app.rb +4 -0
  70. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  71. data/spec/unit/daemon/shared/store.rb +312 -0
  72. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  73. data/spec/unit/daemon/store/active_record_spec.rb +2 -290
  74. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  75. data/spec/unit_spec_helper.rb +3 -0
  76. metadata +89 -10
  77. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -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?
@@ -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
@@ -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?
@@ -1,9 +1,10 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Wns::RawNotification do
4
+ it_behaves_like 'Rpush::Client::Wns::RawNotification'
4
5
  let(:notification) do
5
- notif = Rpush::Client::ActiveRecord::Wns::RawNotification.new
6
- notif.app = Rpush::Client::ActiveRecord::Wns::App.new(name: "aname")
6
+ notif = described_class.new
7
+ notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
7
8
  notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
8
9
  notif.data = { foo: 'foo', bar: 'bar' }
9
10
  notif
@@ -13,14 +14,4 @@ describe Rpush::Client::ActiveRecord::Wns::RawNotification do
13
14
  allow(notification).to receive(:payload_data_size) { 5121 }
14
15
  expect(notification.valid?).to be(false)
15
16
  end
16
-
17
- it 'allows exact payload of 5 KB' do
18
- allow(notification).to receive(:payload_data_size) { 5120 }
19
- expect(notification.valid?).to be(true)
20
- end
21
-
22
- it 'allows the size of payload under 5 KB' do
23
- allow(notification).to receive(:payload_data_size) { 5119 }
24
- expect(notification.valid?).to be(true)
25
- end
26
17
  end if active_record?
@@ -1,4 +1,6 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Wpns::App do
4
- end
4
+ it_behaves_like 'Rpush::Client::Wpns::App'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::App'
6
+ end if active_record?
@@ -1,21 +1,6 @@
1
1
  require 'unit_spec_helper'
2
- require 'unit/notification_shared.rb'
3
2
 
4
3
  describe Rpush::Client::ActiveRecord::Wpns::Notification do
5
- it_should_behave_like 'an Notification subclass'
6
- let(:app) { Rpush::Client::ActiveRecord::Wpns::App.create!(name: 'test', auth_key: 'abc') }
7
- let(:notification_class) { Rpush::Client::ActiveRecord::Wpns::Notification }
8
- let(:notification) { notification_class.new }
9
-
10
- it "should have an url in the uri parameter" do
11
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(uri: "somthing")
12
- notification.valid?
13
- expect(notification.errors[:uri]).to include('is invalid')
14
- end
15
-
16
- it "should be invalid if there's no data" do
17
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(data: {})
18
- notification.valid?
19
- expect(notification.errors[:data]).to include("can't be blank")
20
- end
4
+ it_behaves_like 'Rpush::Client::Wpns::Notification'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
21
6
  end if active_record?