Skip to content
Browse files

training whitespace

  • Loading branch information...
1 parent ca98c7c commit 0d7d2420d6c521c7d397dbe1754010e2fe4fa6e1 @niku committed Apr 20, 2012
Showing with 34 additions and 34 deletions.
  1. +16 −16 lib/apn_on_rails/app/models/apn/notification.rb
  2. +18 −18 spec/apn_on_rails/app/models/apn/notification_spec.rb
View
32 lib/apn_on_rails/app/models/apn/notification.rb
@@ -1,29 +1,29 @@
-# Represents the message you wish to send.
+# Represents the message you wish to send.
# An APN::Notification belongs to an APN::Device.
-#
+#
# Example:
# apn = APN::Notification.new
# apn.badge = 5
# apn.sound = 'my_sound.aiff'
# apn.alert = 'Hello!'
# apn.device = APN::Device.find(1)
# apn.save
-#
+#
# To deliver call the following method:
# APN::Notification.send_notifications
-#
+#
# As each APN::Notification is sent the <tt>sent_at</tt> column will be timestamped,
# so as to not be sent again.
class APN::Notification < APN::Base
include ::ActionView::Helpers::TextHelper
extend ::ActionView::Helpers::TextHelper
serialize :custom_properties
-
+
belongs_to :device, :class_name => 'APN::Device'
has_one :app, :class_name => 'APN::App', :through => :device
-
+
# 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)
@@ -32,17 +32,17 @@ def alert=(message)
end
write_attribute('alert', message)
end
-
+
# Creates a Hash that will be the payload of an APN.
- #
+ #
# Example:
# apn = APN::Notification.new
# apn.badge = 5
# apn.sound = 'my_sound.aiff'
# apn.alert = 'Hello!'
# apn.apple_hash # => {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
#
- # Example 2:
+ # Example 2:
# apn = APN::Notification.new
# apn.badge = 0
# apn.sound = true
@@ -64,9 +64,9 @@ def apple_hash
end
result
end
-
+
# Creates the JSON string required for an APN message.
- #
+ #
# Example:
# apn = APN::Notification.new
# apn.badge = 5
@@ -76,18 +76,18 @@ 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
json = self.to_apple_json
message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message
end
-
+
def self.send_notifications
ActiveSupport::Deprecation.warn("The method APN::Notification.send_notifications is deprecated. Use APN::App.send_notifications instead.")
APN::App.send_notifications
end
-
-end # APN::Notification
+
+end # APN::Notification
View
36 spec/apn_on_rails/app/models/apn/notification_spec.rb
@@ -1,19 +1,19 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
describe APN::Notification do
-
+
describe 'alert' do
-
+
it 'should trim the message to 150 characters' do
noty = APN::Notification.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::Notification.first
noty.apple_hash.should == {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"},"typ" => "1"}
@@ -28,44 +28,44 @@
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::Notification.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::Notification.first
noty.custom_properties = nil
noty.device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
noty.message_for_sending.should == fixture_value('message_for_sending.bin')
end
-
+
it 'should raise an APN::Errors::ExceededMessageSizeError if the message is too big' do
noty = NotificationFactory.new(:device_id => DeviceFactory.create, :sound => true, :badge => nil)
noty.send(:write_attribute, 'alert', 'a' * 183)
lambda {
noty.message_for_sending
}.should raise_error(APN::Errors::ExceededMessageSizeError)
end
-
+
end
-
- describe 'send_notifications' do
-
+
+ describe 'send_notifications' do
+
it 'should warn the user the method is deprecated and call the corresponding method on APN::App' do
ActiveSupport::Deprecation.should_receive(:warn)
APN::App.should_receive(:send_notifications)
APN::Notification.send_notifications
end
end
-
-end
+
+end

0 comments on commit 0d7d242

Please sign in to comment.
Something went wrong with that request. Please try again.