notifiable-rails 0.16.0 → 0.17.0

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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiable-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kamil Kocemba
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-01 00:00:00.000000000 Z
12
+ date: 2014-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -184,7 +184,6 @@ files:
184
184
  - lib/generators/notifiable/install/templates/initializer.rb
185
185
  - lib/notifiable/active_record.rb
186
186
  - lib/notifiable/app.rb
187
- - lib/notifiable/batch.rb
188
187
  - lib/notifiable/device_token.rb
189
188
  - lib/notifiable/engine.rb
190
189
  - lib/notifiable/notifiable_concern.rb
@@ -197,13 +196,12 @@ files:
197
196
  - lib/tasks/brakeman.rake
198
197
  - LICENSE
199
198
  - Rakefile
200
- - spec/batch_spec.rb
201
199
  - spec/controllers/device_tokens_controller_spec.rb
202
200
  - spec/controllers/notifications_controller_spec.rb
203
201
  - spec/notifiable_app_spec.rb
204
- - spec/notifiable_server_spec.rb
205
202
  - spec/notifiable_spec.rb
206
203
  - spec/notification_spec.rb
204
+ - spec/notifier_base_spec.rb
207
205
  - spec/spec_helper.rb
208
206
  - spec/support/engine_controller.rb
209
207
  - spec/support/factories.rb
@@ -277,13 +275,12 @@ signing_key:
277
275
  specification_version: 4
278
276
  summary: Rails engine to make push notifications a bit easier.
279
277
  test_files:
280
- - spec/batch_spec.rb
281
278
  - spec/controllers/device_tokens_controller_spec.rb
282
279
  - spec/controllers/notifications_controller_spec.rb
283
280
  - spec/notifiable_app_spec.rb
284
- - spec/notifiable_server_spec.rb
285
281
  - spec/notifiable_spec.rb
286
282
  - spec/notification_spec.rb
283
+ - spec/notifier_base_spec.rb
287
284
  - spec/spec_helper.rb
288
285
  - spec/support/engine_controller.rb
289
286
  - spec/support/factories.rb
@@ -1,54 +0,0 @@
1
- module Notifiable
2
- class Batch
3
-
4
- def initialize(app)
5
- raise "Must specify Notifiable::App" unless app
6
- @app = app
7
- @notifiers = {}
8
- @notification_ids = []
9
- end
10
-
11
- def add_notifiable(notification, notifiable)
12
- notifiable.device_tokens.each do |d|
13
- self.add_device_token(notification, d)
14
- end
15
- end
16
-
17
- def add_device_token(notification, d)
18
- provider = d.provider.to_sym
19
-
20
- unless @notifiers[provider]
21
- clazz = Notifiable.notifier_classes[provider]
22
- raise "Notifier #{provider} not configured" unless clazz
23
- @notifiers[provider] = clazz.new
24
- @notifiers[provider].env = Rails.env
25
-
26
- if @app.configuration && @app.configuration[provider]
27
- @app.configuration[provider].each_pair {|key, value| @notifiers[provider].send("#{key}=", value) if @notifiers[provider].methods.include?("#{key}=".to_sym) }
28
- end
29
- end
30
-
31
- notifier = @notifiers[provider]
32
- if d.is_valid? && !notifier.nil?
33
- notifier.send_notification(notification, d)
34
- @notification_ids << notification.id
35
- end
36
- end
37
-
38
- def close
39
- @notifiers.each_value {|n| n.close}
40
- @notifiers = nil
41
- summarise
42
- end
43
-
44
- private
45
- def summarise
46
- notifications = Notification.where(:id => @notification_ids)
47
- notifications.each do |n|
48
- n.sent_count = n.notification_statuses.count
49
- n.gateway_accepted_count = n.notification_statuses.where(:status => 0).count
50
- n.save
51
- end
52
- end
53
- end
54
- end
data/spec/batch_spec.rb DELETED
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Notifiable::Batch do
4
- let(:user1) { FactoryGirl.create(:user) }
5
- let(:notification) { FactoryGirl.create(:notification, :app => app) }
6
- let(:app) { FactoryGirl.create(:app, :configuration => {:configurable_mock => {:use_sandbox => true}}) }
7
-
8
- it "adds a notifiable object" do
9
- FactoryGirl.create(:mock_token, :provider => :configurable_mock, :user_id => user1.id, :app => app)
10
-
11
- b = Notifiable::Batch.new(app)
12
- b.add_notifiable(notification, user1)
13
- b.close
14
-
15
- Notifiable::NotificationStatus.count.should == 1
16
- saved_notification = Notifiable::Notification.first
17
- saved_notification.sent_count.should == 1
18
- saved_notification.gateway_accepted_count.should == 1
19
- saved_notification.opened_count.should == 0
20
-
21
- saved_status = Notifiable::NotificationStatus.first
22
- saved_status.status.should == 0
23
- saved_status.created_at.should_not be_nil
24
- end
25
-
26
- it "adds a device token" do
27
- token = FactoryGirl.create(:mock_token, :provider => :configurable_mock, :user_id => user1.id, :app => app)
28
-
29
- b = Notifiable::Batch.new(app)
30
- b.add_device_token(notification, token)
31
- b.close
32
-
33
- Notifiable::NotificationStatus.count.should == 1
34
- saved_notification = Notifiable::Notification.first
35
- saved_notification.sent_count.should == 1
36
- saved_notification.gateway_accepted_count.should == 1
37
- end
38
-
39
- it "configures the provider via an App" do
40
- FactoryGirl.create(:mock_token, :provider => :configurable_mock, :user_id => user1.id, :app => app)
41
-
42
- b = Notifiable::Batch.new(app)
43
- b.add_notifiable(notification, user1)
44
-
45
- b.notifiers[:configurable_mock].env.should eql Rails.env
46
- b.notifiers[:configurable_mock].use_sandbox.should == true
47
- end
48
-
49
- end
50
-
51
- module Notifiable
52
- class Batch
53
- attr_accessor :notifiers
54
- end
55
- end
56
-
57
- class ConfigurableMockNotifier < Notifiable::NotifierBase
58
- attr_accessor :use_sandbox
59
-
60
- def enqueue(notification, device_token, message, params)
61
- processed(notification, device_token, 0)
62
- end
63
- end
64
-
65
- Notifiable.notifier_classes[:configurable_mock] = ConfigurableMockNotifier
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Notifiable do
4
- let(:user1) { FactoryGirl.create(:user_with_mock_token) }
5
- let(:user2) { FactoryGirl.create(:user_with_mock_token) }
6
- let(:notification1) { FactoryGirl.create(:notification, :message => "First test message")}
7
- let(:notification2) { FactoryGirl.create(:notification, :message => "Second test message")}
8
-
9
- before(:each) { FactoryGirl.create(:app) }
10
-
11
- it "sends two identical push notifications" do
12
- Notifiable.batch do |b|
13
- b.add_notifiable(notification1, user1)
14
- b.add_notifiable(notification1, user2)
15
- end
16
-
17
- Notifiable::NotificationStatus.count.should == 2
18
-
19
- all_notifications = Notifiable::NotificationStatus.all
20
- first_notification_token = all_notifications[0]
21
- first_notification_token.notification.message.should eql "First test message"
22
- first_notification_token.device_token.should eql user1.device_tokens[0]
23
-
24
- second_notification_token = all_notifications[1]
25
- second_notification_token.notification.message.should eql "First test message"
26
- second_notification_token.device_token.should eql user2.device_tokens[0]
27
- end
28
-
29
- it "sends two different push notifications" do
30
- Notifiable.batch do |b|
31
- b.add_notifiable(notification1, user1)
32
- b.add_notifiable(notification2, user2)
33
- end
34
-
35
- Notifiable::NotificationStatus.count.should == 2
36
-
37
- all_notifications = Notifiable::NotificationStatus.all
38
- first_notification_token = all_notifications[0]
39
- first_notification_token.status.should == 200
40
- first_notification_token.notification.message.should eql "First test message"
41
- first_notification_token.device_token.should eql user1.device_tokens[0]
42
-
43
- second_notification_token = all_notifications[1]
44
- second_notification_token.status.should == 200
45
- second_notification_token.notification.message.should eql "Second test message"
46
- second_notification_token.device_token.should eql user2.device_tokens[0]
47
- end
48
-
49
- it "raises an error if it can't find the notification provider" do
50
- user = FactoryGirl.create(:user)
51
- device_token = FactoryGirl.create(:mock_token, :provider => :sms, :user_id => user.id)
52
-
53
- expect { user.send_notification(notification1) }.to raise_error
54
- end
55
- end