From ed4b3a5404515f88d8f283d38c312e025a0451de Mon Sep 17 00:00:00 2001 From: Enrico Stano Date: Tue, 19 Jun 2018 12:31:37 +0200 Subject: [PATCH] Flag push_notifications as processed --- app/services/push_notifications/broadcast.rb | 1 + spec/services/push_notifications/broadcast_spec.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/push_notifications/broadcast.rb b/app/services/push_notifications/broadcast.rb index b34e83f3b..3a32ed701 100644 --- a/app/services/push_notifications/broadcast.rb +++ b/app/services/push_notifications/broadcast.rb @@ -9,6 +9,7 @@ def send client = Exponent::Push::Client.new + push_notifications.update_all(processed_at: Time.now.utc) client.publish(notifications) end diff --git a/spec/services/push_notifications/broadcast_spec.rb b/spec/services/push_notifications/broadcast_spec.rb index 0e6513f92..8b7ff6b5d 100644 --- a/spec/services/push_notifications/broadcast_spec.rb +++ b/spec/services/push_notifications/broadcast_spec.rb @@ -14,6 +14,7 @@ title: 'Hola' ) end + let(:push_notifications) { PushNotification.all } let(:client) { instance_double(Exponent::Push::Client) } let(:notification) do { @@ -26,7 +27,16 @@ expect(Exponent::Push::Client).to receive(:new).and_return(client) expect(client).to receive(:publish).with([notification]) - described_class.new(push_notifications: [push_notification]).send + described_class.new(push_notifications: push_notifications).send + end + + it 'flags the push_notification as processed' do + allow(Exponent::Push::Client).to receive(:new).and_return(client) + allow(client).to receive(:publish).with([notification]) + + described_class.new(push_notifications: push_notifications).send + + expect(push_notification.reload.processed_at).to_not be_nil end end end