Skip to content

Commit

Permalink
Merge pull request #549 from platejoy/master
Browse files Browse the repository at this point in the history
Fix GCM priority when using Redis
  • Loading branch information
aried3r committed Feb 21, 2020
2 parents 341fa57 + b07c689 commit 13d3405
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rpush/client/active_model/gcm/notification.rb
Expand Up @@ -26,9 +26,9 @@ def self.included(base)
# I'm not happy about it, but this will have to do until I can take a further look.
def priority=(priority)
case priority
when 'high'
when 'high', GCM_PRIORITY_HIGH
super(GCM_PRIORITY_HIGH)
when 'normal'
when 'normal', GCM_PRIORITY_NORMAL
super(GCM_PRIORITY_NORMAL)
else
errors.add(:priority, 'must be one of either "normal" or "high"')
Expand Down
40 changes: 40 additions & 0 deletions spec/functional/gcm_priority_spec.rb
@@ -0,0 +1,40 @@
require 'functional_spec_helper'

describe 'GCM priority' do
let(:app) { Rpush::Gcm::App.new }
let(:notification) { Rpush::Gcm::Notification.new }
let(:hydrated_notification) { Rpush::Gcm::Notification.find(notification.id) }
let(:response) { double(Net::HTTPResponse, code: 200) }
let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }
let(:priority) { 'normal' }

before do
app.name = 'test'
app.auth_key = 'abc123'
app.save!

notification.app_id = app.id
notification.registration_ids = ['foo']
notification.data = { message: 'test' }
notification.priority = priority
notification.save!

allow(Net::HTTP::Persistent).to receive_messages(new: http)
end

it 'supports normal priority' do
expect(hydrated_notification.as_json['priority']).to eq('normal')
end

context 'high priority' do
let(:priority) { 'high' }

it 'supports high priority' do
expect(hydrated_notification.as_json['priority']).to eq('high')
end
end

it 'does not add an error when receiving expected priority' do
expect(hydrated_notification.errors.messages[:priority]).to be_empty
end
end

0 comments on commit 13d3405

Please sign in to comment.