Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

training whitespace

  • Loading branch information...
commit 3d5a590fce83f479639424f39f6bc95f61f28e5b 1 parent 49fe5bd
@niku authored
View
26 lib/apn_on_rails/app/models/apn/group_notification.rb
@@ -2,19 +2,19 @@ class APN::GroupNotification < APN::Base
include ::ActionView::Helpers::TextHelper
extend ::ActionView::Helpers::TextHelper
serialize :custom_properties
-
+
belongs_to :group, :class_name => 'APN::Group'
has_one :app, :class_name => 'APN::App', :through => :group
has_many :device_groupings, :through => :group
-
+
validates_presence_of :group_id
-
+
def devices
self.group.devices
end
-
+
# Stores the text alert message you want to send to the device.
- #
+ #
# If the message is over 150 characters long it will get truncated
# to 150 characters with a <tt>...</tt>
def alert=(message)
@@ -23,9 +23,9 @@ def alert=(message)
end
write_attribute('alert', message)
end
-
+
# Creates a Hash that will be the payload of an APN.
- #
+ #
# Example:
# apn = APN::GroupNotification.new
# apn.badge = 5
@@ -33,7 +33,7 @@ def alert=(message)
# apn.alert = 'Hello!'
# apn.apple_hash # => {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
#
- # Example 2:
+ # Example 2:
# apn = APN::GroupNotification.new
# apn.badge = 0
# apn.sound = true
@@ -55,9 +55,9 @@ def apple_hash
end
result
end
-
+
# Creates the JSON string required for an APN message.
- #
+ #
# Example:
# apn = APN::Notification.new
# apn.badge = 5
@@ -67,7 +67,7 @@ def apple_hash
def to_apple_json
self.apple_hash.to_json
end
-
+
# Creates the binary message needed to send to Apple.
def message_for_sending(device)
json = self.to_apple_json
@@ -75,5 +75,5 @@ def message_for_sending(device)
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message
end
-
-end # APN::Notification
+
+end # APN::Notification
View
30 spec/apn_on_rails/app/models/apn/group_notification_spec.rb
@@ -1,19 +1,19 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
describe APN::GroupNotification do
-
+
describe 'alert' do
-
+
it 'should trim the message to 150 characters' do
noty = APN::GroupNotification.new
noty.alert = 'a' * 200
noty.alert.should == ('a' * 147) + '...'
end
-
+
end
-
+
describe 'apple_hash' do
-
+
it 'should return a hash of the appropriate params for Apple' do
noty = APN::GroupNotification.first
noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"},"typ" => "1"}
@@ -28,27 +28,27 @@
noty.sound = true
noty.apple_hash.should == {"aps" => {"sound" => "1.aiff"}}
end
-
+
end
-
+
describe 'to_apple_json' do
-
+
it 'should return the necessary JSON for Apple' do
noty = APN::GroupNotification.first
noty.to_apple_json.should == %{{"typ":"1","aps":{"badge":5,"sound":"my_sound.aiff","alert":"Hello!"}}}
end
-
+
end
-
+
describe 'message_for_sending' do
-
+
it 'should create a binary message to be sent to Apple' do
noty = APN::GroupNotification.first
noty.custom_properties = nil
device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
noty.message_for_sending(device).should == fixture_value('message_for_sending.bin')
end
-
+
it 'should raise an APN::Errors::ExceededMessageSizeError if the message is too big' do
app = AppFactory.create
device = DeviceFactory.create({:app_id => app.id})
@@ -60,7 +60,7 @@
noty.message_for_sending(device)
}.should raise_error(APN::Errors::ExceededMessageSizeError)
end
-
+
end
-
-end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.