notifiable-gcm-spacialdb 0.4.3 → 0.4.4

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: 39da622a652408c9b14236037e7c5f3277b47ccb
4
- data.tar.gz: 4b077b4d0e543dfbea5d478619bb6d9ea2eaa471
3
+ metadata.gz: 536406a49ca504f3664c9ebcc375c0c88a2870dd
4
+ data.tar.gz: 6b999987c6c6aa7886b4a7305b96d372fe59eb06
5
5
  SHA512:
6
- metadata.gz: 887884ce3c312cb2b85f7fbf0a81101f1bee97c6884d47947d2d764e259c9a3c15013a4df2315e2f9ff01c7f61be108f1c9264fd2b5ae78d09ac29a0eb4d77a4
7
- data.tar.gz: 3882e1069905b53f58541148a5094a35d52969d0438c87478397f0cf19b3f2b4f1aafd282a4260451408ebb12d38aa551898e24f54a0d95b8a9cfc4a3b1204e2
6
+ metadata.gz: 39a29232f4829ac8f5e54d0b23d4929a14fc1dacedc28323a1e70d22379681d73141fb61c812def3408e6e70eed951ec6d943685a54fb289ce646d65950ab078
7
+ data.tar.gz: 1d155d711bf712c94fcfc0d2720659cf120dc06a38a5c101f65691b05c148550d60221b431451f27dfa70bd9a94a2958b4885b747adefa57cbc9385d2ca18195
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- notifiable-gcm-spacialdb (0.4.3)
4
+ notifiable-gcm-spacialdb (0.4.4)
5
5
  gcm (~> 0.0.6)
6
6
  notifiable-rails (>= 0.6.0)
7
7
 
@@ -52,14 +52,14 @@ module Notifiable
52
52
  # Remove the token if it is marked NotRegistered (user deleted the App for example)
53
53
  if ["InvalidRegistration", "NotRegistered"].include? result["error"]
54
54
  device_tokens[idx].update_attribute('is_valid', false)
55
- else
56
55
 
57
- # Update the token if a canonical ID is returned
58
- if result["registration_id"]
59
- device_tokens[idx].update_attribute('token', result["registration_id"])
60
- end
56
+ # Process canonical IDs
57
+ elsif result["registration_id"] && Notifiable::DeviceToken.exists?(:token => result["registration_id"])
58
+ device_tokens[idx].update_attribute('is_valid', false)
59
+ elsif result["registration_id"]
60
+ device_tokens[idx].update_attribute('token', result["registration_id"])
61
61
  end
62
-
62
+
63
63
  processed(notification, device_tokens[idx], error_code(result["error"]))
64
64
  end
65
65
  else
@@ -1,7 +1,7 @@
1
1
  module Notifiable
2
2
  module Gcm
3
3
  module Spacialdb
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.4"
5
5
  end
6
6
  end
7
7
  end
data/spec/batch_spec.rb CHANGED
@@ -60,16 +60,31 @@ describe Notifiable::Gcm::Spacialdb::Batch do
60
60
  d.is_valid.should == false
61
61
  end
62
62
 
63
- it "updates a token to the canonical ID" do
63
+ it "updates a token to the canonical ID if it does not exist" do
64
64
  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" }]}')
65
65
 
66
66
  Notifiable.batch {|b| b.add(n, u)}
67
67
 
68
68
  Notifiable::NotificationStatus.count.should == 1
69
69
  Notifiable::NotificationStatus.first.status = 0
70
+ Notifiable::DeviceToken.count.should == 1
70
71
  d.token.should eql "GHJ12345"
71
72
  end
72
73
 
74
+
75
+ it "marks a token as invalid if the canonical ID already exists" do
76
+ Notifiable::DeviceToken.create(:token => "GHJ12345", :provider => :gcm)
77
+
78
+ 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" }]}')
79
+
80
+ Notifiable.batch {|b| b.add(n, u)}
81
+
82
+ Notifiable::NotificationStatus.count.should == 1
83
+ Notifiable::NotificationStatus.first.status = 0
84
+ Notifiable::DeviceToken.count.should == 2
85
+ d.is_valid.should be_false
86
+ end
87
+
73
88
  it "deals gracefully with an unauthenticated key" do
74
89
  stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '<html>Message</html>', :status => 401)
75
90
 
@@ -3,12 +3,18 @@ class CreateNotifiableDeviceTokens < ActiveRecord::Migration
3
3
  def change
4
4
  create_table :notifiable_device_tokens do |t|
5
5
  t.string :token
6
- t.string :user_id
7
6
  t.string :provider
7
+ t.string :device_id
8
8
  t.boolean :is_valid, :default => true
9
+ t.integer :user_id
10
+ t.references :app
9
11
 
10
12
  t.timestamps
11
13
  end
14
+
15
+ add_index :notifiable_device_tokens, :device_id, :unique => true
16
+ add_index :notifiable_device_tokens, :token, :unique => true
17
+ add_index :notifiable_device_tokens, :user_id
12
18
  end
13
19
 
14
20
  end
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.4.3
4
+ version: 0.4.4
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-02-16 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: notifiable-rails