Permalink
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 3d5a590 commit d1a879e2a32983e1548a13f3ac7e7d19a25f0f5e @niku committed Apr 24, 2012
@@ -71,7 +71,7 @@ def to_apple_json
# Creates the binary message needed to send to Apple.
def message_for_sending(device)
json = self.to_apple_json
- message = "\0\0 #{device.to_hexa}\0#{json.length.chr}#{json}"
+ message = "\0\0 #{device.to_hexa}#{[json.length].pack('n')}#{json}"
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message
end
@@ -61,6 +61,18 @@
}.should raise_error(APN::Errors::ExceededMessageSizeError)
end
+ it 'should not raise any error if the payload is not too big' do
+ app = AppFactory.create
+ device = DeviceFactory.create({:app_id => app.id})
+ group = GroupFactory.create({:app_id => app.id})
+ device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
+ noty = GroupNotificationFactory.new(:group_id => group.id, :sound => true, :badge => nil)
+ noty.stub(:to_apple_json).and_return('_' * 256)
+ lambda {
+ noty.message_for_sending(device)
+ }.should_not raise_error
+ end
+
end
end

0 comments on commit d1a879e

Please sign in to comment.