Browse files

fix "RangeError: 256 out of char range", because Integer#chr handles …

…255 at most, but the value to be 256.
  • Loading branch information...
1 parent 0d7d242 commit 515603ad66cc58222a9b6fa566a4a073d14fac2c @niku committed Apr 24, 2012
View
2 lib/apn_on_rails/app/models/apn/notification.rb
@@ -80,7 +80,7 @@ def to_apple_json
# Creates the binary message needed to send to Apple.
def message_for_sending
json = self.to_apple_json
- message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
+ message = "\0\0 #{self.device.to_hexa}#{[json.length].pack('n')}#{json}"
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message
end
View
8 spec/apn_on_rails/app/models/apn/notification_spec.rb
@@ -57,6 +57,14 @@
}.should raise_error(APN::Errors::ExceededMessageSizeError)
end
+ it 'should not raise any error if the payload is not too big' do
+ noty = NotificationFactory.new(:device_id => DeviceFactory.create, :sound => true, :badge => nil)
+ noty.stub(:to_apple_json).and_return('_' * 256)
+ lambda {
+ noty.message_for_sending
+ }.should_not raise_error
+ end
+
end
describe 'send_notifications' do

0 comments on commit 515603a

Please sign in to comment.