From 83ccdeb87a6d9cd9b506707be8814cc7a0f242d2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 29 Jan 2017 12:25:10 +0100 Subject: [PATCH] Fix tests --- app/services/send_push_notification_service.rb | 14 +++++++------- spec/spec_helper.rb | 6 +++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/services/send_push_notification_service.rb b/app/services/send_push_notification_service.rb index 802614fce68..526ae20cbc8 100644 --- a/app/services/send_push_notification_service.rb +++ b/app/services/send_push_notification_service.rb @@ -2,13 +2,13 @@ class SendPushNotificationService < BaseService def call(notification) - return if ENV['FCM_API_KEY'].blank? + return if ENV['FCM_API_KEY'].blank? - devices = Device.where(account: notification.account).pluck(:registration_id) - fcm = FCM.new(ENV['FCM_API_KEY']) + devices = Device.where(account: notification.account).pluck(:registration_id) + fcm = FCM.new(ENV['FCM_API_KEY']) - response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) - handle_response(response) + response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) + handle_response(response) end private @@ -19,10 +19,10 @@ class SendPushNotificationService < BaseService end def update_canonical_ids(ids) - ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } + ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } end def remove_bad_ids(bad_ids) - Device.where(registration_id: bad_ids).delete_all + Device.where(registration_id: bad_ids).delete_all unless bad_ids.empty? end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2fdce875509..a5dce977df8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,11 @@ RSpec.configure do |config| mocks.verify_partial_doubles = true end - config.after(:suite) do + config.before :each do + stub_request(:post, 'https://fcm.googleapis.com/fcm/send').to_return(status: 200, body: '') + end + + config.after :suite do FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"]) end end