notifiable-gcm-spacialdb 0.9.0 → 0.10.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: a1f15251a237ef16e25ecaa65fe48602e225a139
4
- data.tar.gz: eb2737d7853ec2df977625cecfae70a9788ff9ea
3
+ metadata.gz: 9d6f7c97e0686c9df19b325d26045a5f03778150
4
+ data.tar.gz: f376083ac33fe4e4e9939e78ab6a5ca1a266c155
5
5
  SHA512:
6
- metadata.gz: d67af3e91b582015475f9034d3904f719f04a68089be72b425dcfa964ef270fd86457a008cf4f7bc8c26f06393c3685239a0d5c1f6267ae52aaf3a4deb083931
7
- data.tar.gz: a0bf883223f62ee049272639782a9cf927886951b29eb24a73c79ea93fc0bae9e35eb92a6eedd887eba485f187b6fef445467b4085b43a52379901f4fec8e6e8
6
+ metadata.gz: c79af147476ad3e19d1593c54736c907894c1faf3006abb3ed8a3920bf0bb2d5e914f03204d0a9c4abedbbee36a1519c266bafc2cb051487987011e9aca57e44
7
+ data.tar.gz: 2117913e0dc1b6d914d6122d3448c979a828b67da6e5fd6764a48f9ed3a3d24c3577ba5e338522a3645d8af2dcefb0f5bad7858d411bbeaf355bf99d2e2e0965
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ _yardoc
18
18
  doc/
19
19
 
20
20
  .DS_Store
21
+ /.byebug_history
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ ruby '2.4.3'
4
+
3
5
  # Specify your gem's dependencies in notifiable-apns-grocer.gemspec
4
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,98 +1,141 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notifiable-gcm-spacialdb (0.8.0)
5
- gcm (~> 0.0.6)
6
- notifiable-rails (>= 0.24.1)
4
+ notifiable-gcm-spacialdb (0.10.0)
5
+ gcm (~> 0.1.1)
6
+ notifiable-rails (>= 0.26.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionmailer (4.1.15)
12
- actionpack (= 4.1.15)
13
- actionview (= 4.1.15)
11
+ actioncable (5.1.5)
12
+ actionpack (= 5.1.5)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.5)
16
+ actionpack (= 5.1.5)
17
+ actionview (= 5.1.5)
18
+ activejob (= 5.1.5)
14
19
  mail (~> 2.5, >= 2.5.4)
15
- actionpack (4.1.15)
16
- actionview (= 4.1.15)
17
- activesupport (= 4.1.15)
18
- rack (~> 1.5.2)
19
- rack-test (~> 0.6.2)
20
- actionview (4.1.15)
21
- activesupport (= 4.1.15)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.5)
22
+ actionview (= 5.1.5)
23
+ activesupport (= 5.1.5)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.5)
29
+ activesupport (= 5.1.5)
22
30
  builder (~> 3.1)
23
- erubis (~> 2.7.0)
24
- activemodel (4.1.15)
25
- activesupport (= 4.1.15)
26
- builder (~> 3.1)
27
- activerecord (4.1.15)
28
- activemodel (= 4.1.15)
29
- activesupport (= 4.1.15)
30
- arel (~> 5.0.0)
31
- activesupport (4.1.15)
32
- i18n (~> 0.6, >= 0.6.9)
33
- json (~> 1.7, >= 1.7.7)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.5)
35
+ activesupport (= 5.1.5)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.5)
38
+ activesupport (= 5.1.5)
39
+ activerecord (5.1.5)
40
+ activemodel (= 5.1.5)
41
+ activesupport (= 5.1.5)
42
+ arel (~> 8.0)
43
+ activerecord-postgis-adapter (5.2.1)
44
+ activerecord (~> 5.1)
45
+ rgeo-activerecord (~> 6.0)
46
+ activesupport (5.1.5)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (~> 0.7)
34
49
  minitest (~> 5.1)
35
- thread_safe (~> 0.1)
36
50
  tzinfo (~> 1.1)
37
- addressable (2.3.5)
38
- arel (5.0.1.20140414130214)
39
- builder (3.2.2)
40
- byebug (5.0.0)
41
- columnize (= 0.9.0)
42
- columnize (0.9.0)
43
- concurrent-ruby (1.0.1)
44
- crack (0.4.1)
45
- safe_yaml (~> 0.9.0)
51
+ addressable (2.5.2)
52
+ public_suffix (>= 2.0.2, < 4.0)
53
+ arel (8.0.0)
54
+ builder (3.2.3)
55
+ byebug (10.0.1)
56
+ concurrent-ruby (1.0.5)
57
+ crack (0.4.3)
58
+ safe_yaml (~> 1.0.0)
59
+ crass (1.0.3)
46
60
  database_cleaner (1.2.0)
47
- diff-lcs (1.2.5)
48
- docile (1.1.2)
49
- erubis (2.7.0)
50
- gcm (0.0.9)
61
+ diff-lcs (1.3)
62
+ docile (1.1.5)
63
+ erubi (1.7.1)
64
+ gcm (0.1.1)
51
65
  httparty
52
66
  json
53
- httparty (0.13.7)
54
- json (~> 1.8)
67
+ globalid (0.4.1)
68
+ activesupport (>= 4.2.0)
69
+ httparty (0.16.1)
55
70
  multi_xml (>= 0.5.2)
56
- i18n (0.7.0)
57
- json (1.8.3)
58
- mail (2.6.4)
59
- mime-types (>= 1.16, < 4)
60
- mime-types (3.0)
61
- mime-types-data (~> 3.2015)
62
- mime-types-data (3.2016.0221)
63
- minitest (5.8.4)
64
- multi_json (1.8.4)
65
- multi_xml (0.5.5)
66
- notifiable-rails (0.24.1)
67
- rails (~> 4.1.0)
68
- rack (1.5.5)
69
- rack-test (0.6.3)
70
- rack (>= 1.0)
71
- rails (4.1.15)
72
- actionmailer (= 4.1.15)
73
- actionpack (= 4.1.15)
74
- actionview (= 4.1.15)
75
- activemodel (= 4.1.15)
76
- activerecord (= 4.1.15)
77
- activesupport (= 4.1.15)
78
- bundler (>= 1.3.0, < 2.0)
79
- railties (= 4.1.15)
80
- sprockets-rails (~> 2.0)
81
- railties (4.1.15)
82
- actionpack (= 4.1.15)
83
- activesupport (= 4.1.15)
71
+ i18n (0.9.5)
72
+ concurrent-ruby (~> 1.0)
73
+ json (2.1.0)
74
+ loofah (2.2.1)
75
+ crass (~> 1.0.2)
76
+ nokogiri (>= 1.5.9)
77
+ mail (2.7.0)
78
+ mini_mime (>= 0.1.1)
79
+ method_source (0.9.0)
80
+ mini_mime (1.0.0)
81
+ mini_portile2 (2.3.0)
82
+ minitest (5.11.3)
83
+ multi_json (1.13.1)
84
+ multi_xml (0.6.0)
85
+ nio4r (2.3.0)
86
+ nokogiri (1.8.2)
87
+ mini_portile2 (~> 2.3.0)
88
+ notifiable-rails (0.26.3)
89
+ activerecord-postgis-adapter
90
+ pg
91
+ rails
92
+ pg (1.0.0)
93
+ public_suffix (3.0.2)
94
+ rack (2.0.4)
95
+ rack-test (0.8.3)
96
+ rack (>= 1.0, < 3)
97
+ rails (5.1.5)
98
+ actioncable (= 5.1.5)
99
+ actionmailer (= 5.1.5)
100
+ actionpack (= 5.1.5)
101
+ actionview (= 5.1.5)
102
+ activejob (= 5.1.5)
103
+ activemodel (= 5.1.5)
104
+ activerecord (= 5.1.5)
105
+ activesupport (= 5.1.5)
106
+ bundler (>= 1.3.0)
107
+ railties (= 5.1.5)
108
+ sprockets-rails (>= 2.0.0)
109
+ rails-dom-testing (2.0.3)
110
+ activesupport (>= 4.2.0)
111
+ nokogiri (>= 1.6)
112
+ rails-html-sanitizer (1.0.3)
113
+ loofah (~> 2.0)
114
+ railties (5.1.5)
115
+ actionpack (= 5.1.5)
116
+ activesupport (= 5.1.5)
117
+ method_source
84
118
  rake (>= 0.8.7)
85
119
  thor (>= 0.18.1, < 2.0)
86
120
  rake (10.1.1)
87
- rspec (2.14.1)
88
- rspec-core (~> 2.14.0)
89
- rspec-expectations (~> 2.14.0)
90
- rspec-mocks (~> 2.14.0)
91
- rspec-core (2.14.7)
92
- rspec-expectations (2.14.4)
93
- diff-lcs (>= 1.1.3, < 2.0)
94
- rspec-mocks (2.14.4)
95
- safe_yaml (0.9.7)
121
+ rgeo (1.0.0)
122
+ rgeo-activerecord (6.0.0)
123
+ activerecord (~> 5.0)
124
+ rgeo (~> 1.0)
125
+ rspec (3.7.0)
126
+ rspec-core (~> 3.7.0)
127
+ rspec-expectations (~> 3.7.0)
128
+ rspec-mocks (~> 3.7.0)
129
+ rspec-core (3.7.1)
130
+ rspec-support (~> 3.7.0)
131
+ rspec-expectations (3.7.0)
132
+ diff-lcs (>= 1.2.0, < 2.0)
133
+ rspec-support (~> 3.7.0)
134
+ rspec-mocks (3.7.0)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.7.0)
137
+ rspec-support (3.7.1)
138
+ safe_yaml (1.0.4)
96
139
  simplecov (0.8.2)
97
140
  docile (~> 1.1.0)
98
141
  multi_json
@@ -100,21 +143,24 @@ GEM
100
143
  simplecov-html (0.8.0)
101
144
  simplecov-rcov (0.2.3)
102
145
  simplecov (>= 0.4.1)
103
- sprockets (3.5.2)
146
+ sprockets (3.7.1)
104
147
  concurrent-ruby (~> 1.0)
105
148
  rack (> 1, < 3)
106
- sprockets-rails (2.3.3)
107
- actionpack (>= 3.0)
108
- activesupport (>= 3.0)
109
- sprockets (>= 2.8, < 4.0)
110
- sqlite3 (1.3.8)
111
- thor (0.19.1)
112
- thread_safe (0.3.5)
113
- tzinfo (1.2.2)
149
+ sprockets-rails (3.2.1)
150
+ actionpack (>= 4.0)
151
+ activesupport (>= 4.0)
152
+ sprockets (>= 3.0.0)
153
+ sqlite3 (1.3.13)
154
+ thor (0.20.0)
155
+ thread_safe (0.3.6)
156
+ tzinfo (1.2.5)
114
157
  thread_safe (~> 0.1)
115
- webmock (1.17.1)
158
+ webmock (1.17.4)
116
159
  addressable (>= 2.2.7)
117
160
  crack (>= 0.3.2)
161
+ websocket-driver (0.6.5)
162
+ websocket-extensions (>= 0.1.0)
163
+ websocket-extensions (0.1.3)
118
164
 
119
165
  PLATFORMS
120
166
  ruby
@@ -125,8 +171,14 @@ DEPENDENCIES
125
171
  database_cleaner (~> 1.2.0)
126
172
  notifiable-gcm-spacialdb!
127
173
  rake (~> 10.1.1)
128
- rspec (~> 2.14.1)
174
+ rspec (~> 3.7)
129
175
  simplecov (~> 0.8.2)
130
176
  simplecov-rcov (~> 0.2.3)
131
- sqlite3 (~> 1.3.8)
177
+ sqlite3
132
178
  webmock (~> 1.17.1)
179
+
180
+ RUBY VERSION
181
+ ruby 2.4.3p205
182
+
183
+ BUNDLED WITH
184
+ 1.16.1
@@ -12,90 +12,88 @@ module Notifiable
12
12
  @batch_size || 1000
13
13
  end
14
14
 
15
- def initialize(env, notification)
16
- super(env, notification)
17
- @batch = []
15
+ def batch
16
+ @batch ||= []
18
17
  end
19
18
 
20
- protected
21
- def enqueue(device_token, localized_notification)
22
- raise "API Key missing" if @api_key.nil?
23
-
24
- @batch << device_token
25
- send_batch(localized_notification) if @batch.count >= batch_size
26
- end
27
-
28
- def flush
29
- send_batch(localized_notification(@batch.first)) unless @batch.empty?
30
- end
19
+ protected
20
+
21
+ def enqueue(device_token, notification)
22
+ raise "API Key missing" if @api_key.nil?
23
+
24
+ @batch_notification = notification
25
+ batch << device_token
26
+ send_batch(notification) if batch.count >= batch_size
27
+ end
28
+
29
+ def flush
30
+ send_batch(@batch_notification) unless batch.empty?
31
+ end
31
32
 
32
33
  private
33
- def send_batch(notification)
34
- if Notifiable.delivery_method == :test
35
- @batch.each {|d| processed(d, 0)}
36
- else
37
- gcm = ::GCM.new(@api_key)
38
-
39
- data = {:message => notification.message}.merge(notification.send_params)
40
- response = gcm.send_notification(@batch.collect{|dt| dt.token}, {:data => data})
41
-
42
- if response[:status_code] == 200
43
- process_success_response(response)
44
- else
45
- Rails.logger.error "Sending notification id: #{notification.id} code: #{response[:status_code]} response: #{response[:response]}"
46
- end
47
- end
48
- @batch = []
49
- end
50
-
51
- def process_success_response(response)
52
- body = JSON.parse(response.fetch(:body, "{}"))
53
- results = body.fetch("results", [])
54
- results.each_with_index do |result, i|
55
- dt = @batch[i]
56
-
57
- # Remove the token if it is marked NotRegistered (user deleted the App for example)
58
- if ["InvalidRegistration", "NotRegistered"].include? result["error"]
59
- dt.update_attribute('is_valid', false)
60
-
61
- # Process canonical IDs
62
- elsif result["registration_id"] && Notifiable::DeviceToken.exists?(:token => result["registration_id"])
63
- dt.update_attribute('is_valid', false)
64
- elsif result["registration_id"]
65
- dt.update_attribute('token', result["registration_id"])
66
- end
34
+
35
+ def send_batch(notification)
36
+ gcm = ::GCM.new(@api_key)
37
+
38
+ data = {:message => notification.message}.merge(notification.send_params)
39
+ response = gcm.send_notification(batch.collect{|dt| dt.token}, {:data => data})
67
40
 
68
- processed(dt, error_code(result["error"]))
69
- end
70
- end
41
+ if response[:status_code] == 200
42
+ process_success_response(response)
43
+ else
44
+ Rails.logger.error "Sending notification id: #{notification.id} code: #{response[:status_code]} response: #{response[:response]}"
45
+ end
46
+ @batch = []
47
+ end
71
48
 
72
- def error_code(error_message)
73
- case error_message
74
- when "MissingRegistration"
75
- 1
76
- when "InvalidRegistration"
77
- 2
78
- when "MismatchSenderId"
79
- 3
80
- when "NotRegistered"
81
- 4
82
- when "MessageTooBig"
83
- 5
84
- when "InvalidDataKey"
85
- 6
86
- when "InvalidTtl"
87
- 7
88
- when "Unavailable"
89
- 8
90
- when "InternalServerError"
91
- 9
92
- when "InvalidPackageName"
93
- 10
94
- else
95
- 0
49
+ def process_success_response(response)
50
+ body = JSON.parse(response.fetch(:body, "{}"))
51
+ results = body.fetch("results", [])
52
+ results.each_with_index do |result, i|
53
+ dt = batch[i]
54
+
55
+ # Remove the token if it is marked NotRegistered (user deleted the App for example)
56
+ if ["InvalidRegistration", "NotRegistered"].include? result["error"]
57
+ dt.destroy
58
+ # Process canonical IDs
59
+ elsif result["registration_id"] && Notifiable::DeviceToken.exists?(:token => result["registration_id"])
60
+ dt.destroy
61
+ elsif result["registration_id"]
62
+ dt.update_attribute('token', result["registration_id"])
96
63
  end
64
+
65
+ processed(dt, error_code(result["error"]))
66
+ end
67
+
68
+ end
69
+
70
+ def error_code(error_message)
71
+ case error_message
72
+ when "MissingRegistration"
73
+ 1
74
+ when "InvalidRegistration"
75
+ 2
76
+ when "MismatchSenderId"
77
+ 3
78
+ when "NotRegistered"
79
+ 4
80
+ when "MessageTooBig"
81
+ 5
82
+ when "InvalidDataKey"
83
+ 6
84
+ when "InvalidTtl"
85
+ 7
86
+ when "Unavailable"
87
+ 8
88
+ when "InternalServerError"
89
+ 9
90
+ when "InvalidPackageName"
91
+ 10
92
+ else
93
+ 0
97
94
  end
98
- end
95
+ end
96
+ end
99
97
  end
100
98
  end
101
99
  end
@@ -1,7 +1,7 @@
1
1
  module Notifiable
2
2
  module Gcm
3
3
  module Spacialdb
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end
6
6
  end
7
7
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Kamil Kocemba", "Matt Brooke-Smith"]
10
10
  spec.email = ["kamil@futureworkshops.com", "matt@futureworkshops.com"]
11
11
  spec.homepage = "http://www.futureworkshops.com"
12
- spec.description = "Plugin to use GCM with Notifiable-Rails"
13
- spec.summary = "Plugin to use GCM with Notifiable-Rails"
12
+ spec.description = "Plugin to use GCM with Notifiable"
13
+ spec.summary = "Plugin to use GCM with Notifiable"
14
14
  spec.license = "Apache 2.0"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "notifiable-rails", ">=0.24.1"
22
- spec.add_dependency "gcm", "~> 0.0.6"
21
+ spec.add_dependency "notifiable-rails", ">=0.26.3"
22
+ spec.add_dependency "gcm", '~> 0.1.1'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake", "~> 10.1.1"
26
- spec.add_development_dependency "rspec", "~> 2.14.1"
26
+ spec.add_development_dependency "rspec", '~> 3.7'
27
27
  spec.add_development_dependency "simplecov", "~> 0.8.2"
28
28
  spec.add_development_dependency "simplecov-rcov", "~> 0.2.3"
29
- spec.add_development_dependency "sqlite3", "~> 1.3.8"
29
+ spec.add_development_dependency "sqlite3"
30
30
  spec.add_development_dependency "database_cleaner", "~> 1.2.0"
31
31
  spec.add_development_dependency "webmock", "~> 1.17.1"
32
32
  spec.add_development_dependency "byebug"
data/spec/batch_spec.rb CHANGED
@@ -2,89 +2,50 @@ require 'spec_helper'
2
2
 
3
3
  describe Notifiable::Gcm::Spacialdb::Batch do
4
4
 
5
- let(:a) { Notifiable::App.create }
6
- let(:n1) { Notifiable::Notification.create(:app => a) }
7
- let!(:ln) { Notifiable::LocalizedNotification.create(:message => "Test message", :params => {:flag => true}, :notification => n1, :locale => 'en') }
5
+ let(:app_configuration) { {save_notification_statuses: true, gcm: {api_key: 'abc123'}} }
6
+ let(:a) { Notifiable::App.create gcm_api_key: 'abc123', configuration: app_configuration }
7
+ let(:n1) { Notifiable::Notification.create(app: a, message: 'Test message', parameters: {flag: true} ) }
8
8
  let(:d) { Notifiable::DeviceToken.create(:token => "ABC123", :provider => :gcm, :app => a, :locale => 'en') }
9
+ let!(:stubbed_request) { stub_request(:post, "https://gcm-http.googleapis.com/gcm/send").with(body: request_body).to_return(body: response_body) }
10
+ let(:request_body) { }
11
+ let(:response_body) { }
9
12
 
10
- before(:each) do
11
- a.gcm_api_key = "abc123"
12
- end
13
-
14
- it "sends a single gcm notification" do
15
- stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}')
13
+ describe '#batch' do
14
+ before(:each) { n1.batch {|n| n.add_device_token(d)} }
16
15
 
17
- n1.batch {|n| n.add_device_token(d)}
18
-
19
- Notifiable::NotificationStatus.count.should == 1
20
- Notifiable::NotificationStatus.first.status = 0
21
- end
22
-
23
- it "sends custom attributes" do
24
- stub_request(:post, "https://android.googleapis.com/gcm/send")
25
- .with(:body => "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"localized_notification_id\":1}}")
26
- .to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}')
16
+ context 'single' do
17
+ let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
18
+ let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}' }
19
+ it { expect(Notifiable::NotificationStatus.count).to eq 1 }
20
+ it { expect(Notifiable::NotificationStatus.first.status).to eq 0 }
21
+ end
22
+
23
+ context 'custom attributes' do
24
+ let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
25
+ let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}' }
26
+ it { expect(Notifiable::NotificationStatus.count).to eq 1 }
27
+ it { expect(Notifiable::NotificationStatus.first.status).to eq 0 }
28
+ end
29
+
30
+ context 'deletes an unregistered token' do
31
+ let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
32
+ let(:response_body) { '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "NotRegistered" }]}' }
33
+ it { expect(Notifiable::NotificationStatus.count).to eq 0 }
34
+ it { expect(Notifiable::DeviceToken.count).to eq 0 }
35
+ end
36
+
37
+ context 'id change' do
38
+ let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
39
+ let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}' }
40
+ it { expect(Notifiable::NotificationStatus.count).to eq 1 }
41
+ it { expect(Notifiable::DeviceToken.count).to eq 1 }
42
+ it { expect(Notifiable::DeviceToken.first.token).to eq "GHJ12345" }
43
+ end
44
+
45
+ context 'bad key' do
46
+ let!(:stubbed_request) { stub_request(:post, "https://gcm-http.googleapis.com/gcm/send").to_return(body: '<html>Message</html>', status: 401) }
47
+ it { expect(Notifiable::NotificationStatus.count).to eq 0 }
48
+ end
27
49
 
28
- n1.batch {|n| n.add_device_token(d)}
29
-
30
-
31
- Notifiable::NotificationStatus.count.should == 1
32
- Notifiable::NotificationStatus.first.status = 0
33
50
  end
34
-
35
- it "marks a unregistered token as invalid" do
36
- stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "NotRegistered" }]}')
37
-
38
- n1.batch {|n| n.add_device_token(d)}
39
-
40
- Notifiable::NotificationStatus.count.should == 1
41
- Notifiable::NotificationStatus.first.status = 4
42
- d.is_valid.should == false
43
- end
44
-
45
- it "marks an invalid token as invalid" do
46
- stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "InvalidRegistration" }]}')
47
-
48
- n1.batch {|n| n.add_device_token(d)}
49
-
50
- Notifiable::NotificationStatus.count.should == 1
51
- Notifiable::NotificationStatus.first.status = 2
52
- d.is_valid.should == false
53
- end
54
-
55
- it "updates a token to the canonical ID if it does not exist" do
56
- stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}')
57
-
58
- n1.batch {|n| n.add_device_token(d)}
59
-
60
- Notifiable::NotificationStatus.count.should == 1
61
- Notifiable::NotificationStatus.first.status = 0
62
- Notifiable::DeviceToken.count.should == 1
63
- d.token.should eql "GHJ12345"
64
- end
65
-
66
-
67
- # it "marks a token as invalid if the canonical ID already exists" do
68
- # Notifiable::DeviceToken.create(:token => "GHJ12345", :provider => :gcm)
69
-
70
- # stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}')
71
-
72
- # n1.batch do |n|
73
- # n.add_device_token(d)
74
- # end
75
-
76
- # Notifiable::NotificationStatus.count.should == 1
77
- # Notifiable::NotificationStatus.first.status = 0
78
- # Notifiable::DeviceToken.count.should == 2
79
- # d.is_valid.should be_false
80
- # end
81
-
82
- it "deals gracefully with an unauthenticated key" do
83
- stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '<html>Message</html>', :status => 401)
84
-
85
- n1.batch {|n| n.add_device_token(d)}
86
-
87
- Notifiable::NotificationStatus.count.should == 0
88
- end
89
-
90
51
  end
data/spec/spec_helper.rb CHANGED
@@ -17,7 +17,7 @@ require 'byebug'
17
17
  require File.expand_path("../../lib/notifiable/gcm/spacialdb", __FILE__)
18
18
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
19
19
 
20
- db_path = 'spec/support/db/test.sqlite3'
20
+ db_path = 'spec/test.sqlite3'
21
21
  DatabaseCleaner.strategy = :truncation
22
22
 
23
23
  Rails.logger = Logger.new(STDOUT)
@@ -40,7 +40,8 @@ RSpec.configure do |config|
40
40
  )
41
41
 
42
42
  ActiveRecord::Migration.verbose = false
43
- ActiveRecord::Migrator.migrate "spec/support/db/migrate"
43
+ notifiable_rails_path = Gem.loaded_specs['notifiable-rails'].full_gem_path
44
+ ActiveRecord::Migrator.migrate File.join(notifiable_rails_path, 'db', 'migrate')
44
45
 
45
46
  # todo start stub
46
47
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiable-gcm-spacialdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.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: 2016-03-31 00:00:00.000000000 Z
12
+ date: 2018-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: notifiable-rails
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.24.1
20
+ version: 0.26.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.24.1
27
+ version: 0.26.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: gcm
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.0.6
34
+ version: 0.1.1
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: 0.0.6
41
+ version: 0.1.1
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 2.14.1
76
+ version: '3.7'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 2.14.1
83
+ version: '3.7'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: simplecov
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: sqlite3
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: 1.3.8
118
+ version: '0'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
- version: 1.3.8
125
+ version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: database_cleaner
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +165,7 @@ dependencies:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
- description: Plugin to use GCM with Notifiable-Rails
168
+ description: Plugin to use GCM with Notifiable
169
169
  email:
170
170
  - kamil@futureworkshops.com
171
171
  - matt@futureworkshops.com
@@ -175,8 +175,6 @@ extra_rdoc_files: []
175
175
  files:
176
176
  - ".gitignore"
177
177
  - ".rspec"
178
- - ".ruby-gemset"
179
- - ".ruby-version"
180
178
  - Gemfile
181
179
  - Gemfile.lock
182
180
  - LICENSE
@@ -188,11 +186,6 @@ files:
188
186
  - notifiable-gcm-spacialdb.gemspec
189
187
  - spec/batch_spec.rb
190
188
  - spec/spec_helper.rb
191
- - spec/support/db/migrate/20131210115648_create_notifiable_apps.rb
192
- - spec/support/db/migrate/20131210115649_create_notifiable_device_tokens.rb
193
- - spec/support/db/migrate/20131210115650_create_notifiable_notifications.rb
194
- - spec/support/db/migrate/20131210115651_create_notifiable_localized_notifications.rb
195
- - spec/support/db/migrate/20131210115652_create_notifiable_statuses.rb
196
189
  homepage: http://www.futureworkshops.com
197
190
  licenses:
198
191
  - Apache 2.0
@@ -213,15 +206,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
206
  version: '0'
214
207
  requirements: []
215
208
  rubyforge_project:
216
- rubygems_version: 2.2.3
209
+ rubygems_version: 2.6.14
217
210
  signing_key:
218
211
  specification_version: 4
219
- summary: Plugin to use GCM with Notifiable-Rails
212
+ summary: Plugin to use GCM with Notifiable
220
213
  test_files:
221
214
  - spec/batch_spec.rb
222
215
  - spec/spec_helper.rb
223
- - spec/support/db/migrate/20131210115648_create_notifiable_apps.rb
224
- - spec/support/db/migrate/20131210115649_create_notifiable_device_tokens.rb
225
- - spec/support/db/migrate/20131210115650_create_notifiable_notifications.rb
226
- - spec/support/db/migrate/20131210115651_create_notifiable_localized_notifications.rb
227
- - spec/support/db/migrate/20131210115652_create_notifiable_statuses.rb
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- notifiable-gcm-spacialdb
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.6
@@ -1,10 +0,0 @@
1
- class CreateNotifiableApps < ActiveRecord::Migration
2
- def change
3
- create_table :notifiable_apps do |t|
4
- t.string :name
5
- t.text :configuration
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- class CreateNotifiableDeviceTokens < ActiveRecord::Migration
2
-
3
- def change
4
- create_table :notifiable_device_tokens do |t|
5
- t.string :token
6
- t.string :provider
7
- t.string :locale
8
- t.boolean :is_valid, :default => true
9
- t.integer :user_id
10
- t.references :app
11
-
12
- t.timestamps
13
- end
14
-
15
- add_index :notifiable_device_tokens, :token, :unique => true
16
- add_index :notifiable_device_tokens, :user_id
17
- end
18
-
19
- end
@@ -1,16 +0,0 @@
1
- class CreateNotifiableNotifications < ActiveRecord::Migration
2
-
3
- def change
4
- create_table :notifiable_notifications do |t|
5
- t.references :app
6
-
7
- #stats
8
- t.integer :sent_count, :default => 0
9
- t.integer :gateway_accepted_count, :default => 0
10
- t.integer :opened_count, :default => 0
11
-
12
- t.timestamps
13
- end
14
- end
15
-
16
- end
@@ -1,22 +0,0 @@
1
- class CreateNotifiableLocalizedNotifications < ActiveRecord::Migration
2
-
3
- def change
4
- create_table :notifiable_localized_notifications do |t|
5
- t.text :message
6
- t.text :params
7
- t.string :locale
8
- t.references :notification
9
-
10
- # APNS - Optional
11
- #t.integer :badge
12
- #t.text :sound
13
- #t.datetime :expiry
14
-
15
- # MPNS - Optional
16
- #t.text :title
17
-
18
- t.timestamps
19
- end
20
- end
21
-
22
- end
@@ -1,12 +0,0 @@
1
- class CreateNotifiableStatuses < ActiveRecord::Migration
2
-
3
- def change
4
- create_table :notifiable_statuses do |t|
5
- t.references :localized_notification
6
- t.references :device_token
7
- t.integer :status
8
- t.datetime :created_at
9
- end
10
- end
11
-
12
- end