jirapong-apn_on_rails 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/.specification +80 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +47 -0
  6. data/LICENSE +21 -0
  7. data/README +179 -0
  8. data/README.textile +224 -0
  9. data/Rakefile +35 -0
  10. data/apn_on_rails.gemspec +32 -0
  11. data/autotest/discover.rb +1 -0
  12. data/generators/apn_migrations_generator.rb +33 -0
  13. data/generators/templates/apn_migrations/001_create_apn_devices.rb +13 -0
  14. data/generators/templates/apn_migrations/002_create_apn_notifications.rb +23 -0
  15. data/generators/templates/apn_migrations/003_alter_apn_devices.rb +23 -0
  16. data/generators/templates/apn_migrations/004_create_apn_apps.rb +25 -0
  17. data/generators/templates/apn_migrations/005_create_groups.rb +23 -0
  18. data/generators/templates/apn_migrations/006_alter_apn_groups.rb +11 -0
  19. data/generators/templates/apn_migrations/007_create_device_groups.rb +27 -0
  20. data/generators/templates/apn_migrations/008_create_apn_group_notifications.rb +23 -0
  21. data/generators/templates/apn_migrations/009_create_pull_notifications.rb +16 -0
  22. data/generators/templates/apn_migrations/010_alter_apn_notifications.rb +21 -0
  23. data/generators/templates/apn_migrations/011_make_device_token_index_nonunique.rb +11 -0
  24. data/generators/templates/apn_migrations/012_add_launch_notification_to_apn_pull_notifications.rb +9 -0
  25. data/lib/apn_on_rails.rb +4 -0
  26. data/lib/apn_on_rails/apn_on_rails.rb +81 -0
  27. data/lib/apn_on_rails/app/models/apn/app.rb +151 -0
  28. data/lib/apn_on_rails/app/models/apn/base.rb +11 -0
  29. data/lib/apn_on_rails/app/models/apn/device.rb +49 -0
  30. data/lib/apn_on_rails/app/models/apn/device_grouping.rb +16 -0
  31. data/lib/apn_on_rails/app/models/apn/group.rb +12 -0
  32. data/lib/apn_on_rails/app/models/apn/group_notification.rb +79 -0
  33. data/lib/apn_on_rails/app/models/apn/notification.rb +93 -0
  34. data/lib/apn_on_rails/app/models/apn/pull_notification.rb +28 -0
  35. data/lib/apn_on_rails/libs/connection.rb +70 -0
  36. data/lib/apn_on_rails/libs/feedback.rb +39 -0
  37. data/lib/apn_on_rails/rails/railtie.rb +15 -0
  38. data/lib/apn_on_rails/tasks/apn.rake +30 -0
  39. data/lib/apn_on_rails/tasks/db.rake +23 -0
  40. data/lib/apn_on_rails/version.rb +3 -0
  41. data/lib/apn_on_rails_tasks.rb +3 -0
  42. data/lib/generators/apn_on_rails/install/USAGE +8 -0
  43. data/lib/generators/apn_on_rails/install/install_generator.rb +38 -0
  44. data/lib/generators/apn_on_rails/install/templates/001_create_apn_devices.rb +13 -0
  45. data/lib/generators/apn_on_rails/install/templates/002_create_apn_notifications.rb +23 -0
  46. data/lib/generators/apn_on_rails/install/templates/003_alter_apn_devices.rb +25 -0
  47. data/lib/generators/apn_on_rails/install/templates/004_create_apn_apps.rb +18 -0
  48. data/lib/generators/apn_on_rails/install/templates/005_create_groups.rb +23 -0
  49. data/lib/generators/apn_on_rails/install/templates/006_alter_apn_groups.rb +11 -0
  50. data/lib/generators/apn_on_rails/install/templates/007_create_device_groups.rb +27 -0
  51. data/lib/generators/apn_on_rails/install/templates/008_create_apn_group_notifications.rb +23 -0
  52. data/lib/generators/apn_on_rails/install/templates/009_create_pull_notifications.rb +16 -0
  53. data/lib/generators/apn_on_rails/install/templates/010_alter_apn_notifications.rb +21 -0
  54. data/lib/generators/apn_on_rails/install/templates/011_make_device_token_index_nonunique.rb +11 -0
  55. data/lib/generators/apn_on_rails/install/templates/012_add_launch_notification_to_apn_pull_notifications.rb +9 -0
  56. data/spec/active_record/setup_ar.rb +20 -0
  57. data/spec/apn_on_rails/app/models/apn/app_spec.rb +230 -0
  58. data/spec/apn_on_rails/app/models/apn/device_spec.rb +61 -0
  59. data/spec/apn_on_rails/app/models/apn/group_notification_spec.rb +66 -0
  60. data/spec/apn_on_rails/app/models/apn/notification_spec.rb +71 -0
  61. data/spec/apn_on_rails/app/models/apn/pull_notification_spec.rb +100 -0
  62. data/spec/apn_on_rails/libs/connection_spec.rb +40 -0
  63. data/spec/apn_on_rails/libs/feedback_spec.rb +43 -0
  64. data/spec/extensions/string.rb +10 -0
  65. data/spec/factories/app_factory.rb +27 -0
  66. data/spec/factories/device_factory.rb +29 -0
  67. data/spec/factories/device_grouping_factory.rb +22 -0
  68. data/spec/factories/group_factory.rb +27 -0
  69. data/spec/factories/group_notification_factory.rb +22 -0
  70. data/spec/factories/notification_factory.rb +22 -0
  71. data/spec/factories/pull_notification_factory.rb +22 -0
  72. data/spec/fixtures/hexa.bin +1 -0
  73. data/spec/fixtures/message_for_sending.bin +0 -0
  74. data/spec/rails_root/config/apple_push_notification_development.pem +19 -0
  75. data/spec/spec_helper.rb +64 -0
  76. metadata +242 -0
@@ -0,0 +1,11 @@
1
+ class MakeDeviceTokenIndexNonunique < ActiveRecord::Migration
2
+ def self.up
3
+ remove_index :apn_devices, :column => :token
4
+ add_index :apn_devices, :token
5
+ end
6
+
7
+ def self.down
8
+ remove_index :apn_devices, :column => :token
9
+ add_index :apn_devices, :token, :unique => true
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class AddLaunchNotificationToApnPullNotifications < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :apn_pull_notifications, :launch_notification, :boolean
4
+ end
5
+
6
+ def self.down
7
+ remove_column :apn_pull_notifications, :launch_notification
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'logger'
4
+
5
+
6
+ logger = Logger.new(STDOUT)
7
+ logger.level = Logger::INFO
8
+ ActiveRecord::Base.logger = logger
9
+
10
+ db_file = File.join(File.dirname(__FILE__), 'test.db')
11
+ FileUtils.rm(db_file) if File.exists?(db_file)
12
+
13
+ ActiveRecord::Base.establish_connection({
14
+ :adapter => 'sqlite3',
15
+ :database => db_file
16
+ })
17
+
18
+ ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', '..', 'generators', 'templates', 'apn_migrations'))
19
+
20
+ # raise hell
@@ -0,0 +1,230 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+
3
+ describe APN::App do
4
+
5
+ describe 'send_notifications' do
6
+
7
+ it 'should send the unsent notifications' do
8
+
9
+ app = AppFactory.create
10
+ device = DeviceFactory.create({:app_id => app.id})
11
+ notifications = [NotificationFactory.create({:device_id => device.id}),
12
+ NotificationFactory.create({:device_id => device.id})]
13
+
14
+ notifications.each_with_index do |notify, i|
15
+ notify.stub(:message_for_sending).and_return("message-#{i}")
16
+ notify.should_receive(:sent_at=).with(instance_of(Time))
17
+ notify.should_receive(:save)
18
+ end
19
+
20
+ APN::App.should_receive(:all).once.and_return([app])
21
+ app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
22
+
23
+ APN::Device.should_receive(:find_each).twice.and_yield(device)
24
+
25
+ device.should_receive(:unsent_notifications).and_return(notifications,[])
26
+
27
+
28
+ ssl_mock = mock('ssl_mock')
29
+ ssl_mock.should_receive(:write).with('message-0')
30
+ ssl_mock.should_receive(:write).with('message-1')
31
+ APN::Connection.should_receive(:open_for_delivery).twice.and_yield(ssl_mock, nil)
32
+ APN::App.send_notifications
33
+
34
+ end
35
+
36
+ end
37
+
38
+ describe 'send_notifications_not_associated_with_an_app' do
39
+
40
+ it 'should send unsent notifications that are associated with devices that are not with any app' do
41
+ RAILS_ENV = 'staging'
42
+ device = DeviceFactory.create
43
+ device.app_id = nil
44
+ device.save
45
+ APN::App.all.each { |a| a.destroy }
46
+ notifications = [NotificationFactory.create({:device_id => device.id}),
47
+ NotificationFactory.create({:device_id => device.id})]
48
+
49
+ notifications.each_with_index do |notify, i|
50
+ notify.stub(:message_for_sending).and_return("message-#{i}")
51
+ notify.should_receive(:sent_at=).with(instance_of(Time))
52
+ notify.should_receive(:save)
53
+ end
54
+
55
+ APN::Device.should_receive(:find_each).and_yield(device)
56
+ device.should_receive(:unsent_notifications).and_return(notifications)
57
+
58
+ ssl_mock = mock('ssl_mock')
59
+ ssl_mock.should_receive(:write).with('message-0')
60
+ ssl_mock.should_receive(:write).with('message-1')
61
+ APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
62
+ APN::App.send_notifications
63
+ end
64
+ end
65
+
66
+ describe 'send_group_notifications' do
67
+
68
+ it 'should send the unsent group notifications' do
69
+
70
+ app = AppFactory.create
71
+ device = DeviceFactory.create({:app_id => app.id})
72
+ group = GroupFactory.create({:app_id => app.id})
73
+ device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
74
+ gnotys = [GroupNotificationFactory.create({:group_id => group.id}),
75
+ GroupNotificationFactory.create({:group_id => group.id})]
76
+ gnotys.each_with_index do |gnoty, i|
77
+ gnoty.stub!(:message_for_sending).and_return("message-#{i}")
78
+ gnoty.should_receive(:sent_at=).with(instance_of(Time))
79
+ gnoty.should_receive(:save)
80
+ end
81
+
82
+ APN::App.should_receive(:all).and_return([app])
83
+ app.should_receive(:unsent_group_notifications).at_least(:once).and_return(gnotys)
84
+ app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
85
+
86
+ ssl_mock = mock('ssl_mock')
87
+ ssl_mock.should_receive(:write).with('message-0')
88
+ ssl_mock.should_receive(:write).with('message-1')
89
+ APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
90
+
91
+ APN::App.send_group_notifications
92
+
93
+ end
94
+
95
+ end
96
+
97
+ describe 'send single group notification' do
98
+
99
+ it 'should send the argument group notification' do
100
+ app = AppFactory.create
101
+ device = DeviceFactory.create({:app_id => app.id})
102
+ group = GroupFactory.create({:app_id => app.id})
103
+ device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
104
+ gnoty = GroupNotificationFactory.create({:group_id => group.id})
105
+ gnoty.stub!(:message_for_sending).and_return("message-0")
106
+ gnoty.should_receive(:sent_at=).with(instance_of(Time))
107
+ gnoty.should_receive(:save)
108
+
109
+ app.should_receive(:cert).at_least(:once).and_return(app.apn_dev_cert)
110
+
111
+ ssl_mock = mock('ssl_mock')
112
+ ssl_mock.should_receive(:write).with('message-0')
113
+ APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
114
+
115
+ app.send_group_notification(gnoty)
116
+ end
117
+
118
+ end
119
+
120
+ describe 'nil cert when sending notifications' do
121
+
122
+ it 'should raise an exception for sending notifications for an app with no cert' do
123
+ app = AppFactory.create
124
+ APN::App.should_receive(:all).and_return([app])
125
+ app.should_receive(:cert).and_return(nil)
126
+ lambda {
127
+ APN::App.send_notifications
128
+ }.should raise_error(APN::Errors::MissingCertificateError)
129
+ end
130
+
131
+ end
132
+
133
+ describe 'nil cert when sending group notifications' do
134
+
135
+ it 'should raise an exception for sending group notifications for an app with no cert' do
136
+ app = AppFactory.create
137
+ APN::App.should_receive(:all).and_return([app])
138
+ app.should_receive(:cert).and_return(nil)
139
+ lambda {
140
+ APN::App.send_group_notifications
141
+ }.should raise_error(APN::Errors::MissingCertificateError)
142
+ end
143
+
144
+ end
145
+
146
+ describe 'nil cert when sending single group notification' do
147
+
148
+ it 'should raise an exception for sending group notifications for an app with no cert' do
149
+ app = AppFactory.create
150
+ device = DeviceFactory.create({:app_id => app.id})
151
+ group = GroupFactory.create({:app_id => app.id})
152
+ device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
153
+ gnoty = GroupNotificationFactory.create({:group_id => group.id})
154
+ app.should_receive(:cert).and_return(nil)
155
+ lambda {
156
+ app.send_group_notification(gnoty)
157
+ }.should raise_error(APN::Errors::MissingCertificateError)
158
+ end
159
+
160
+ end
161
+
162
+ describe 'process_devices' do
163
+
164
+ it 'should destroy devices that have a last_registered_at date that is before the feedback_at date' do
165
+ app = AppFactory.create
166
+ devices = [DeviceFactory.create(:app_id => app.id, :last_registered_at => 1.week.ago, :feedback_at => Time.now),
167
+ DeviceFactory.create(:app_id => app.id, :last_registered_at => 1.week.from_now, :feedback_at => Time.now)]
168
+ puts "device ids are #{devices[0].id} and #{devices[1].id}"
169
+ devices[0].last_registered_at = 1.week.ago
170
+ devices[0].save
171
+ devices[1].last_registered_at = 1.week.from_now
172
+ devices[1].save
173
+ APN::Feedback.should_receive(:devices).twice.and_return(devices)
174
+ APN::App.should_receive(:all).and_return([app])
175
+ app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
176
+ lambda {
177
+ APN::App.process_devices
178
+ }.should change(APN::Device, :count).by(-1)
179
+ end
180
+
181
+ end
182
+
183
+ describe 'process_devices for global app' do
184
+
185
+ it 'should destroy devices that have a last_registered_at date that is before the feedback_at date that have no app' do
186
+ device = DeviceFactory.create(:app_id => nil, :last_registered_at => 1.week.ago, :feedback_at => Time.now)
187
+ device.app_id = nil
188
+ device.last_registered_at = 1.week.ago
189
+ device.save
190
+ APN::Feedback.should_receive(:devices).and_return([device])
191
+ APN::App.should_receive(:all).and_return([])
192
+ lambda {
193
+ APN::App.process_devices
194
+ }.should change(APN::Device, :count).by(-1)
195
+ end
196
+ end
197
+
198
+ describe 'nil cert when processing devices' do
199
+
200
+ it 'should raise an exception for processing devices for an app with no cert' do
201
+ app = AppFactory.create
202
+ APN::App.should_receive(:all).and_return([app])
203
+ app.should_receive(:cert).and_return(nil)
204
+ lambda {
205
+ APN::App.process_devices
206
+ }.should raise_error(APN::Errors::MissingCertificateError)
207
+ end
208
+
209
+ end
210
+
211
+ describe 'cert for production environment' do
212
+
213
+ it 'should return the production cert for the app' do
214
+ app = AppFactory.create
215
+ RAILS_ENV = 'production'
216
+ app.cert.should == app.apn_prod_cert
217
+ end
218
+
219
+ end
220
+
221
+ describe 'cert for development and staging environment' do
222
+
223
+ it 'should return the development cert for the app' do
224
+ app = AppFactory.create
225
+ RAILS_ENV = 'staging'
226
+ app.cert.should == app.apn_dev_cert
227
+ end
228
+ end
229
+
230
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+
3
+ describe APN::Device do
4
+
5
+ describe 'token' do
6
+
7
+ it 'should be unique' do
8
+ t = APN::Device.first.token
9
+ device = DeviceFactory.new(:token => t)
10
+ device.should_not be_valid
11
+ device.errors['token'].should include('has already been taken')
12
+
13
+ device = DeviceFactory.new(:token => device.token.succ)
14
+ device.should be_valid
15
+ end
16
+
17
+ it 'should get cleansed if it contains brackets' do
18
+ token = DeviceFactory.random_token
19
+ device = DeviceFactory.new(:token => "<#{token}>")
20
+ device.token.should == token
21
+ device.token.should_not == "<#{token}>"
22
+ end
23
+
24
+ it 'should be in the correct pattern' do
25
+ device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
26
+ device.should be_valid
27
+ device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6'
28
+ device.should_not be_valid
29
+ device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7!!'
30
+ device.should_not be_valid
31
+ end
32
+
33
+ end
34
+
35
+ describe 'to_hexa' do
36
+
37
+ it 'should convert the text string to hexadecimal' do
38
+ device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
39
+ device.to_hexa.should == fixture_value('hexa.bin')
40
+ end
41
+
42
+ end
43
+
44
+ describe 'before_create' do
45
+
46
+ it 'should set the last_registered_at date to Time.now' do
47
+ time = Time.now
48
+ Time.stub(:now).and_return(time)
49
+ device = DeviceFactory.create
50
+ device.last_registered_at.should_not be_nil
51
+ device.last_registered_at.to_s.should == time.to_s
52
+
53
+ # ago = 1.week.ago
54
+ # device = DeviceFactory.create(:last_registered_at => ago)
55
+ # device.last_registered_at.should_not be_nil
56
+ # device.last_registered_at.to_s.should == ago.to_s
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,66 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+
3
+ describe APN::GroupNotification do
4
+
5
+ describe 'alert' do
6
+
7
+ it 'should trim the message to 150 characters' do
8
+ noty = APN::GroupNotification.new
9
+ noty.alert = 'a' * 200
10
+ noty.alert.should == ('a' * 147) + '...'
11
+ end
12
+
13
+ end
14
+
15
+ describe 'apple_hash' do
16
+
17
+ it 'should return a hash of the appropriate params for Apple' do
18
+ noty = APN::GroupNotification.first
19
+ noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"},"typ" => "1"}
20
+ noty.custom_properties = nil
21
+ noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
22
+ noty.badge = nil
23
+ noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff", "alert" => "Hello!"}}
24
+ noty.alert = nil
25
+ noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff"}}
26
+ noty.sound = nil
27
+ noty.apple_hash.should == {"aps" => {}}
28
+ noty.sound = true
29
+ noty.apple_hash.should == {"aps" => {"sound" => "1.aiff"}}
30
+ end
31
+
32
+ end
33
+
34
+ describe 'to_apple_json' do
35
+
36
+ it 'should return the necessary JSON for Apple' do
37
+ noty = APN::GroupNotification.first
38
+ noty.to_apple_json.should == %{{"typ":"1","aps":{"badge":5,"sound":"my_sound.aiff","alert":"Hello!"}}}
39
+ end
40
+
41
+ end
42
+
43
+ describe 'message_for_sending' do
44
+
45
+ it 'should create a binary message to be sent to Apple' do
46
+ noty = APN::GroupNotification.first
47
+ noty.custom_properties = nil
48
+ device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
49
+ noty.message_for_sending(device).should == fixture_value('message_for_sending.bin')
50
+ end
51
+
52
+ it 'should raise an APN::Errors::ExceededMessageSizeError if the message is too big' do
53
+ app = AppFactory.create
54
+ device = DeviceFactory.create({:app_id => app.id})
55
+ group = GroupFactory.create({:app_id => app.id})
56
+ device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
57
+ noty = GroupNotificationFactory.new(:group_id => group.id, :sound => true, :badge => nil)
58
+ noty.send(:write_attribute, 'alert', 'a' * 183)
59
+ lambda {
60
+ noty.message_for_sending(device)
61
+ }.should raise_error(APN::Errors::ExceededMessageSizeError)
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+
3
+ describe APN::Notification do
4
+
5
+ describe 'alert' do
6
+
7
+ it 'should trim the message to 150 characters' do
8
+ noty = APN::Notification.new
9
+ noty.alert = 'a' * 200
10
+ noty.alert.should == ('a' * 147) + '...'
11
+ end
12
+
13
+ end
14
+
15
+ describe 'apple_hash' do
16
+
17
+ it 'should return a hash of the appropriate params for Apple' do
18
+ noty = APN::Notification.first
19
+ noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"},"typ" => "1"}
20
+ noty.custom_properties = nil
21
+ noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
22
+ noty.badge = nil
23
+ noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff", "alert" => "Hello!"}}
24
+ noty.alert = nil
25
+ noty.apple_hash.should == {"aps" => {"sound" => "my_sound.aiff"}}
26
+ noty.sound = nil
27
+ noty.apple_hash.should == {"aps" => {}}
28
+ noty.sound = true
29
+ noty.apple_hash.should == {"aps" => {"sound" => "1.aiff"}}
30
+ end
31
+
32
+ end
33
+
34
+ describe 'to_apple_json' do
35
+
36
+ it 'should return the necessary JSON for Apple' do
37
+ noty = APN::Notification.first
38
+ noty.to_apple_json.should == %{{"typ":"1","aps":{"badge":5,"sound":"my_sound.aiff","alert":"Hello!"}}}
39
+ end
40
+
41
+ end
42
+
43
+ describe 'message_for_sending' do
44
+
45
+ it 'should create a binary message to be sent to Apple' do
46
+ noty = APN::Notification.first
47
+ noty.custom_properties = nil
48
+ noty.device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
49
+ noty.message_for_sending.should == fixture_value('message_for_sending.bin')
50
+ end
51
+
52
+ it 'should raise an APN::Errors::ExceededMessageSizeError if the message is too big' do
53
+ noty = NotificationFactory.new(:device_id => DeviceFactory.create, :sound => true, :badge => nil)
54
+ noty.send(:write_attribute, 'alert', 'a' * 183)
55
+ lambda {
56
+ noty.message_for_sending
57
+ }.should raise_error(APN::Errors::ExceededMessageSizeError)
58
+ end
59
+
60
+ end
61
+
62
+ describe 'send_notifications' do
63
+
64
+ it 'should warn the user the method is deprecated and call the corresponding method on APN::App' do
65
+ ActiveSupport::Deprecation.should_receive(:warn)
66
+ APN::App.should_receive(:send_notifications)
67
+ APN::Notification.send_notifications
68
+ end
69
+ end
70
+
71
+ end