notifiable-rails 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b109b7e4229eae4cc3b4033b5443695cf79efa1c
4
- data.tar.gz: 94a994b5dccaac5d746602c77e15a4c13b1d3ec1
3
+ metadata.gz: 8866068be795e5ab4b9eeaca25bd7a32652a7aaa
4
+ data.tar.gz: 43335737e5ce55937010d5e596ca3c236845e019
5
5
  SHA512:
6
- metadata.gz: 67da3afd51f2d586796dea736ffec204ae6787a7293e66ab491afbb6265bc66cb00201534039d6c9285307b32f8bbdef9a12491341907fc174f949c80974f25d
7
- data.tar.gz: ff2c59f101908c96f1cfca9d16b396e9e068ed64c57d1922307b6c871d13e2f1f29e96cbf9fa8eb2906d7bf04792b07c75495be90ebc74c02594660078bd2596
6
+ metadata.gz: 8185060efd46e0014da52f7108a73774532b21fa387cb3d8a1f811ecf444e80f7dc2f590c9d3715fc82816be609686ceba5a5e94dc2ad20aae0efda66e513e70
7
+ data.tar.gz: 3cd022e2dd580c5db9a9ae8f130b7ba37401044bce353dd524bf8212124815f63c7592dcbc85a966cd5a0a058fbd43ba5ba3c57ea2868b0ff496d5255b966349
@@ -10,5 +10,14 @@ module Notifiable
10
10
 
11
11
  self.configuration[provider].each_pair {|key, value| notifier.send("#{key}=", value) if notifier.methods.include?("#{key}=".to_sym) }
12
12
  end
13
+
14
+ def save_notification_statuses?
15
+ self.configuration[:save_notification_statuses].nil? ? true : self.configuration[:save_notification_statuses]
16
+ end
17
+
18
+ def save_notification_statuses=(save_notification_statuses)
19
+ self.configuration[:save_notification_statuses] = save_notification_statuses
20
+ end
21
+
13
22
  end
14
23
  end
@@ -42,12 +42,6 @@ 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
-
51
45
  private
52
46
  def notifiers
53
47
  @notifiers ||= {}
@@ -56,7 +50,6 @@ module Notifiable
56
50
  def close
57
51
  notifiers.each_value {|n| n.close}
58
52
  @notifiers = nil
59
- summarise
60
53
  end
61
54
  end
62
55
  end
@@ -31,14 +31,14 @@ module Notifiable
31
31
  end
32
32
 
33
33
  def processed(device_token, status)
34
- if Notifiable.save_receipts
34
+ if @notification.app.save_notification_statuses?
35
35
  receipts << {localized_notification_id: self.localized_notification(device_token).id, device_token_id: device_token.id, status: status, created_at: DateTime.now}
36
-
37
36
  save_receipts if receipts.count >= Notifiable.notification_status_batch_size
38
- else
39
- @notification.sent_count += 1
40
- @notification.save if (@notification.sent_count % Notifiable.notification_status_batch_size == 0)
41
37
  end
38
+
39
+ @notification.sent_count += 1
40
+ @notification.gateway_accepted_count += 1 if status == 0
41
+ @notification.save if (@notification.sent_count % Notifiable.notification_status_batch_size == 0)
42
42
  end
43
43
 
44
44
  def test_env?
@@ -53,7 +53,6 @@ module Notifiable
53
53
  def save_receipts
54
54
  Notifiable::NotificationStatus.bulk_insert! receipts
55
55
  @receipts = []
56
- @notification.summarise
57
56
  end
58
57
  end
59
58
  end
@@ -1,3 +1,3 @@
1
1
  module Notifiable
2
- VERSION = "0.22.1"
2
+ VERSION = "0.23.0"
3
3
  end
@@ -13,7 +13,6 @@ describe Notifiable::NotifierBase do
13
13
  end
14
14
 
15
15
  describe "#processed" do
16
- let(:notifiable_app) { FactoryGirl.create(:app, :configuration => {:configurable_mock => {:use_sandbox => true}}) }
17
16
  let(:notification) { FactoryGirl.create(:notification_with_en_localization, :app => notifiable_app) }
18
17
 
19
18
  let(:device_token1) { FactoryGirl.create(:device_token, :app => notifiable_app, :locale => 'en') }
@@ -24,8 +23,12 @@ describe Notifiable::NotifierBase do
24
23
 
25
24
  before(:each) { Notifiable.notification_status_batch_size = 2 }
26
25
 
27
- context "saving receipts" do
28
- before(:each) do
26
+ context "saving receipts by default" do
27
+ let(:notifiable_app) { FactoryGirl.create(:app, :configuration => {:configurable_mock => {:use_sandbox => true}}) }
28
+
29
+ before(:each) do
30
+ notifiable_app.save_notification_statuses = true
31
+
29
32
  notifier.processed(device_token1, 0)
30
33
  notifier.processed(device_token2, 0)
31
34
  end
@@ -34,10 +37,10 @@ describe Notifiable::NotifierBase do
34
37
  it { expect(Notifiable::Notification.first.sent_count).to eq 2 }
35
38
  end
36
39
 
37
- context "not saving receipts" do
38
- before(:each) do
39
- Notifiable.save_receipts = false
40
+ context "not saving statuses" do
41
+ let(:notifiable_app) { FactoryGirl.create(:app, :configuration => {:save_notification_statuses => false, :configurable_mock => {:use_sandbox => true}}) }
40
42
 
43
+ before(:each) do
41
44
  notifier.processed(device_token1, 0)
42
45
  notifier.processed(device_token2, 0)
43
46
  end