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 +4 -4
- data/lib/notifiable/notification.rb +6 -6
- data/lib/notifiable/notifier_base.rb +3 -4
- data/lib/notifiable/version.rb +1 -1
- data/spec/model/notifier_base_spec.rb +25 -0
- data/spec/test_app/log/test.log +8025 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18da379edb316d22c4fa33783e6b39557abd2acc
|
4
|
+
data.tar.gz: 2ea6c4d630af8b1c53715f6f554e8cbf741fc4bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/notifiable/version.rb
CHANGED
@@ -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
|