notifiable-rails 0.18.0 → 0.19.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.
- checksums.yaml +4 -4
- data/app/controllers/notifiable/device_tokens_controller.rb +1 -1
- data/lib/generators/notifiable/install/templates/create_notifiable_device_tokens.rb +1 -0
- data/lib/notifiable/device_token.rb +0 -1
- data/lib/notifiable/notification.rb +5 -2
- data/lib/notifiable/version.rb +1 -1
- data/spec/controllers/device_tokens_controller_spec.rb +13 -0
- data/spec/notifiable_spec.rb +8 -0
- data/spec/support/factories.rb +10 -0
- data/spec/test_app/db/migrate/20131228225139_create_notifiable_device_tokens.rb +2 -1
- data/spec/test_app/db/schema.rb +2 -1
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/log/test.log +8081 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6771605e049c4c99a9ca06e52203f8b5b348d7e0
|
4
|
+
data.tar.gz: 46439784fe393b8282422590d34454b977ea32e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
@@ -22,7 +22,7 @@ module Notifiable
|
|
22
22
|
def add_device_token(d)
|
23
23
|
provider = d.provider.to_sym
|
24
24
|
|
25
|
-
|
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]
|
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
|
data/lib/notifiable/version.rb
CHANGED
@@ -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
|
|
data/spec/notifiable_spec.rb
CHANGED
@@ -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
|
data/spec/support/factories.rb
CHANGED
@@ -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
|
14
|
+
add_index :notifiable_device_tokens, :token
|
14
15
|
add_index :notifiable_device_tokens, :user_id
|
15
16
|
end
|
16
17
|
|
data/spec/test_app/db/schema.rb
CHANGED
@@ -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"
|
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
|