notifiable-rails 0.21.1 → 0.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d71799addca4d1b62f55cc53648b8fbb79539e45
4
- data.tar.gz: b02d89f3dd6b820427a2ed913f5d4635e4e2e5fd
3
+ metadata.gz: 18da379edb316d22c4fa33783e6b39557abd2acc
4
+ data.tar.gz: 2ea6c4d630af8b1c53715f6f554e8cbf741fc4bb
5
5
  SHA512:
6
- metadata.gz: 5391c59e0e71f8849a174c7a53be0424de9ecd5e2f0db31f63abfa4076e75fe4bcb0486cabdd1d7822c636e4b2bd2cd10bddabd0736612c423edeaf40af6dec3
7
- data.tar.gz: 8e123732670e709c34a7b3c04db382f6ece68c548289562a505052dd3682484b8d3d35197092c009d7178ce9d9c88936603961eb944d4d5e0cfd35ffb4797589
6
+ metadata.gz: ddbfdedac518e617f7c959a4338184bc0316d4cbed4ffbacfa682736a425a1d8b0f16b6afc860529dc326c72c462d891d4176fcbaa7d301ea3fc172664d3f9e0
7
+ data.tar.gz: 1ae79d56178c07d58069dd2d92b34ef087374005d596849056da53afc10ddd3e8e5befa2c7f79aeed7eacdc3b07a3c80e6357b2c50383de15ef62ca4792e103c
@@ -42,6 +42,12 @@ module Notifiable
42
42
  notifiers[provider].send_notification(d) if d.is_valid?
43
43
  end
44
44
 
45
+ def summarise
46
+ self.sent_count = self.notification_statuses.count
47
+ self.gateway_accepted_count = self.notification_statuses.where(:status => 0).count
48
+ self.save
49
+ end
50
+
45
51
  private
46
52
  def notifiers
47
53
  @notifiers ||= {}
@@ -52,11 +58,5 @@ module Notifiable
52
58
  @notifiers = nil
53
59
  summarise
54
60
  end
55
-
56
- def summarise
57
- self.sent_count = self.notification_statuses.count
58
- self.gateway_accepted_count = self.notification_statuses.where(:status => 0).count
59
- self.save
60
- end
61
61
  end
62
62
  end
@@ -29,10 +29,8 @@ module Notifiable
29
29
 
30
30
  def processed(device_token, status)
31
31
  receipts << {localized_notification_id: self.localized_notification(device_token).id, device_token_id: device_token.id, status: status, created_at: DateTime.now}
32
-
33
- if receipts.count > Notifiable.notification_status_batch_size
34
- save_receipts
35
- end
32
+
33
+ save_receipts if receipts.count >= Notifiable.notification_status_batch_size
36
34
  end
37
35
 
38
36
  def test_env?
@@ -47,6 +45,7 @@ module Notifiable
47
45
  def save_receipts
48
46
  Notifiable::NotificationStatus.bulk_insert! receipts
49
47
  @receipts = []
48
+ @notification.summarise
50
49
  end
51
50
  end
52
51
  end
@@ -1,3 +1,3 @@
1
1
  module Notifiable
2
- VERSION = "0.21.1"
2
+ VERSION = "0.21.2"
3
3
  end
@@ -11,6 +11,31 @@ describe Notifiable::NotifierBase do
11
11
 
12
12
  it { expect(notifier.test_env?).to eq true }
13
13
  end
14
+
15
+ describe "#processed" do
16
+ let(:notifiable_app) { FactoryGirl.create(:app, :configuration => {:configurable_mock => {:use_sandbox => true}}) }
17
+ let(:notification) { FactoryGirl.create(:notification_with_en_localization, :app => notifiable_app) }
18
+
19
+ let(:device_token1) { FactoryGirl.create(:device_token, :app => notifiable_app, :locale => :en) }
20
+ let(:device_token2) { FactoryGirl.create(:device_token, :app => notifiable_app, :locale => :en) }
21
+ let(:device_token3) { FactoryGirl.create(:device_token, :app => notifiable_app, :locale => :en) }
22
+
23
+ subject(:notifier) { ConfigurableMockNotifier.new(Rails.env, notification) }
24
+
25
+ before(:each) do
26
+ ConfigurableMockNotifier.send(:public, *ConfigurableMockNotifier.protected_instance_methods)
27
+
28
+ Notifiable.notification_status_batch_size = 2
29
+ notifier.processed(device_token1, 0)
30
+ notifier.processed(device_token2, 0)
31
+ end
32
+
33
+ it { expect(Notifiable::NotificationStatus.count).to eq 2 }
34
+ it { expect(notification.sent_count).to eq 2 }
35
+
36
+ end
37
+
38
+
14
39
  end
15
40
 
16
41
  class ConfigurableMockNotifier < Notifiable::NotifierBase