notifiable-rails 0.18.0 → 0.19.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: cbaafd78d10a107a81067e143a9d6adbafaaae50
4
- data.tar.gz: c18c874d3fbe4f4adb5aec8c26f162d2449bf7c0
3
+ metadata.gz: 6771605e049c4c99a9ca06e52203f8b5b348d7e0
4
+ data.tar.gz: 46439784fe393b8282422590d34454b977ea32e8
5
5
  SHA512:
6
- metadata.gz: 1f30704e7c7fb1566c2dd82f833da44a6188e37dc207fb795ba18c1fa46436573943552bca39a7be6a25734d1c21df3f2e126c0d30a830ccea39d2f70a2e6078
7
- data.tar.gz: f4c16109523ffc3dd18efe5a34dd105cd472ffeef79b35daf05951c8d009e7b4c5badf79e6df16f074738c32f23d210ea0415ce195b06b2afb1ea52209f1db03
6
+ metadata.gz: e0b39ee3bb705fe1e945a32e4a00f334720417616173150413e0ea1f9c7ce0551f784202408c3db4bfe1f46b0d8ebf221b471f922b2ac5d0ad7a9a5e251e12b2
7
+ data.tar.gz: 4e91ea250c6b0d81fff90e7f142fd21d87aba3ab02bdb64ed8ee901e3ebc25ce6060df2a145ebc81ce520564c2092d632b69d86c4a7916e13179195036f89c90
@@ -10,7 +10,7 @@ module Notifiable
10
10
  before_filter :find_device_token, :ensure_authorized!, :except => :create
11
11
 
12
12
  def create
13
- @device_token = DeviceToken.find_by(:token => params[:token])
13
+ @device_token = DeviceToken.find_by(:token => params[:token], :is_valid => true)
14
14
  @device_token = DeviceToken.new unless @device_token
15
15
 
16
16
  perform_update(device_token_params)
@@ -4,6 +4,7 @@ class CreateNotifiableDeviceTokens < ActiveRecord::Migration
4
4
  create_table :notifiable_device_tokens do |t|
5
5
  t.string :token
6
6
  t.string :provider
7
+ t.boolean :is_valid, :default => true
7
8
  t.integer :user_id
8
9
  t.references :app
9
10
 
@@ -3,7 +3,6 @@ module Notifiable
3
3
  belongs_to :app, :class_name => "Notifiable::App"
4
4
 
5
5
  validates_presence_of :token, :provider, :app
6
- validates_uniqueness_of :token
7
6
 
8
7
  def user
9
8
  user_id.blank? ? nil : Notifiable.user_class.find(user_id)
@@ -22,7 +22,7 @@ module Notifiable
22
22
  def add_device_token(d)
23
23
  provider = d.provider.to_sym
24
24
 
25
- if notifiers[provider].nil?
25
+ unless notifiers[provider]
26
26
  clazz = Notifiable.notifier_classes[provider]
27
27
  raise "Notifier #{provider} not configured" unless clazz
28
28
 
@@ -32,7 +32,10 @@ module Notifiable
32
32
  notifiers[provider] = notifier
33
33
  end
34
34
 
35
- notifiers[provider].send_notification(d)
35
+ notifier = @notifiers[provider]
36
+ if d.is_valid? && !notifier.nil?
37
+ notifier.send_notification(d)
38
+ end
36
39
  end
37
40
 
38
41
  def send_params
@@ -1,3 +1,3 @@
1
1
  module Notifiable
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -6,6 +6,7 @@ describe Notifiable::DeviceTokensController do
6
6
  let(:user2) { FactoryGirl.create(:user_with_mock_token) }
7
7
  let(:user2_device_token) { user2.device_tokens.first }
8
8
  let(:app) { FactoryGirl.create(:app) }
9
+ let(:invalid_device_token) { FactoryGirl.create(:invalid_mock_token) }
9
10
 
10
11
  before(:each) do
11
12
  @request.env["HTTP_ACCEPT"] = "application/json"
@@ -54,6 +55,18 @@ describe Notifiable::DeviceTokensController do
54
55
  dt.app.should.eql? app
55
56
  end
56
57
 
58
+ it "uses an existing token unless its invalid" do
59
+ post :create, :token => invalid_device_token.token, :provider => invalid_device_token.provider, :app_id => app.id, :user_email => user1.email
60
+ response.status.should == 200
61
+ Notifiable.api_device_token_params.push('id').each{|p| json.should have_key(p.to_s)}
62
+
63
+ Notifiable::DeviceToken.count.should == 2
64
+ user1.device_tokens.count.should == 1
65
+ dt = Notifiable::DeviceToken.last
66
+ dt.token.should.eql? invalid_device_token.token
67
+ dt.is_valid.should be_true
68
+ end
69
+
57
70
  it "doesn't create a token if no app is specified" do
58
71
  post :create, :token => "ABC123", :user_email => user1.email, :provider => :mpns
59
72
 
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Notifiable::Concern do
4
4
  let(:user1) { FactoryGirl.create(:user_with_mock_token) }
5
+ let(:invalid_token_user) { FactoryGirl.create(:user_with_invalid_mock_token) }
5
6
  let(:notification1) { FactoryGirl.create(:notification, :message => "First test message")}
6
7
 
7
8
  it "sends a single push notification" do
@@ -9,4 +10,11 @@ describe Notifiable::Concern do
9
10
 
10
11
  Notifiable::NotificationStatus.count.should == 1
11
12
  end
13
+
14
+ it "sends zero notifications if the device is not valid" do
15
+ invalid_token_user.send_notification(notification1)
16
+
17
+ Notifiable::NotificationStatus.count.should == 0
18
+ end
19
+
12
20
  end
@@ -4,6 +4,10 @@ FactoryGirl.define do
4
4
  provider :mock
5
5
  sequence(:token) {|n| "ABCD#{n}" }
6
6
  app
7
+
8
+ factory :invalid_mock_token do
9
+ is_valid false
10
+ end
7
11
  end
8
12
 
9
13
  factory :app, :class => Notifiable::App do
@@ -29,6 +33,12 @@ FactoryGirl.define do
29
33
  FactoryGirl.create(:mock_token, :user_id => user.id)
30
34
  end
31
35
  end
36
+
37
+ factory :user_with_invalid_mock_token do
38
+ after(:create) do |user, evaluator|
39
+ FactoryGirl.create(:invalid_mock_token, :user_id => user.id)
40
+ end
41
+ end
32
42
  end
33
43
 
34
44
 
@@ -4,13 +4,14 @@ class CreateNotifiableDeviceTokens < ActiveRecord::Migration
4
4
  create_table :notifiable_device_tokens do |t|
5
5
  t.string :token
6
6
  t.string :provider
7
+ t.boolean :is_valid, :default => true
7
8
  t.integer :user_id
8
9
  t.references :app
9
10
 
10
11
  t.timestamps
11
12
  end
12
13
 
13
- add_index :notifiable_device_tokens, :token, :unique => true
14
+ add_index :notifiable_device_tokens, :token
14
15
  add_index :notifiable_device_tokens, :user_id
15
16
  end
16
17
 
@@ -23,13 +23,14 @@ ActiveRecord::Schema.define(version: 20131229104039) do
23
23
  create_table "notifiable_device_tokens", force: true do |t|
24
24
  t.string "token"
25
25
  t.string "provider"
26
+ t.boolean "is_valid", default: true
26
27
  t.integer "user_id"
27
28
  t.integer "app_id"
28
29
  t.datetime "created_at"
29
30
  t.datetime "updated_at"
30
31
  end
31
32
 
32
- add_index "notifiable_device_tokens", ["token"], name: "index_notifiable_device_tokens_on_token", unique: true
33
+ add_index "notifiable_device_tokens", ["token"], name: "index_notifiable_device_tokens_on_token"
33
34
  add_index "notifiable_device_tokens", ["user_id"], name: "index_notifiable_device_tokens_on_user_id"
34
35
 
35
36
  create_table "notifiable_notifications", force: true do |t|
Binary file