Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #71 from sidereel/master
Browse files Browse the repository at this point in the history
Fixing nonzero nil error when an apns status has not been set
  • Loading branch information
mattt committed Aug 13, 2014
2 parents f38953b + f4c3eaa commit 92ad25a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/houston/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def valid?
end

def error
APNSError.new(APNSError::CODES[@apns_error_code]) if @apns_error_code.nonzero?
APNSError.new(APNSError::CODES[@apns_error_code]) if @apns_error_code && @apns_error_code.nonzero?
end

private
Expand Down
27 changes: 27 additions & 0 deletions spec/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,31 @@ def parse_items(items_stream)
expect(items.find { |item| item[0] == 5 }).to be_nil
end
end

describe '#error' do
context 'a status code has been set' do
it 'returns an error object mapped to that status code' do
status_code = 1
notification = Houston::Notification.new(notification_options)
notification.apns_error_code = status_code
expect(notification.error.message).to eq(Houston::Notification::APNSError::CODES[status_code])
end
end

context 'a status code has been set to 0' do
it 'returns nil' do
status_code = 0
notification = Houston::Notification.new(notification_options)
notification.apns_error_code = status_code
expect(notification.error).to be_nil
end
end

context 'a status code has not been set' do
it 'returns nil' do
notification = Houston::Notification.new(notification_options)
expect(notification.error).to be_nil
end
end
end
end

0 comments on commit 92ad25a

Please sign in to comment.