notifiable-rails 0.15.1 → 0.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/notifiable/device_tokens_controller.rb +11 -11
- data/lib/notifiable/version.rb +1 -1
- data/spec/controllers/device_tokens_controller_spec.rb +17 -9
- data/spec/spec_helper.rb +1 -0
- data/spec/support/request_helpers.rb +7 -0
- data/spec/test_app/log/test.log +3524 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5c9e0517d0c144b71ee217a4d01ba004f2d535
|
4
|
+
data.tar.gz: 2294beb4bd3cded57e19c4c95039311c958f52af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f8a84df5cb874e8576323c8985a6765c821e62d49ac725e509b64033282c65ab751b8536051c408021cc73342967baf0eaa6ff55c3da8169c2c44a7ed35bb4
|
7
|
+
data.tar.gz: de8e5cab899553948f08ef806228eea319c1cd85fafa899536ab93f9229adc525b9b74be1e5b665c127fd40b4780f7d5ac581386e5f5f42e68655641e1d27c15
|
@@ -13,19 +13,11 @@ module Notifiable
|
|
13
13
|
@device_token = DeviceToken.find_by(:token => params[:token])
|
14
14
|
@device_token = DeviceToken.new unless @device_token
|
15
15
|
|
16
|
-
|
17
|
-
render :json => { :id => @device_token.id }, :status => :ok
|
18
|
-
else
|
19
|
-
render :json => { :errors => @device_token.errors.full_messages }, :status => :unprocessable_entity
|
20
|
-
end
|
16
|
+
perform_update(device_token_params)
|
21
17
|
end
|
22
18
|
|
23
19
|
def update
|
24
|
-
|
25
|
-
head :status => :ok
|
26
|
-
else
|
27
|
-
render :json => { :errors => @device_token.errors.full_messages }, :status => :unprocessable_entity
|
28
|
-
end
|
20
|
+
perform_update(device_token_params)
|
29
21
|
end
|
30
22
|
|
31
23
|
def destroy
|
@@ -36,7 +28,15 @@ module Notifiable
|
|
36
28
|
end
|
37
29
|
end
|
38
30
|
|
39
|
-
private
|
31
|
+
private
|
32
|
+
def perform_update(params)
|
33
|
+
if @device_token.update_attributes(params)
|
34
|
+
render :json => @device_token.to_json(:only => Notifiable.api_device_token_params.push(:id)), :status => :ok
|
35
|
+
else
|
36
|
+
render :json => { :errors => @device_token.errors.full_messages }, :status => :unprocessable_entity
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
40
|
def device_token_params
|
41
41
|
device_token_params = params.permit(Notifiable.api_device_token_params)
|
42
42
|
|
data/lib/notifiable/version.rb
CHANGED
@@ -15,7 +15,8 @@ describe Notifiable::DeviceTokensController do
|
|
15
15
|
it "creates a new device token for an existing user" do
|
16
16
|
post :create, :token => "ABC123", :user_email => user1.email, :provider => :apns, :app_id => app.id
|
17
17
|
|
18
|
-
|
18
|
+
response.status.should == 200
|
19
|
+
Notifiable.api_device_token_params.push('id').each{|p| json.should have_key(p.to_s)}
|
19
20
|
|
20
21
|
Notifiable::DeviceToken.count.should == 1
|
21
22
|
user1.device_tokens.count.should == 1
|
@@ -28,7 +29,8 @@ describe Notifiable::DeviceTokensController do
|
|
28
29
|
it "creates a new device token for an anonymous user" do
|
29
30
|
post :create, :token => "ABC123", :provider => :apns, :app_id => app.id
|
30
31
|
|
31
|
-
|
32
|
+
response.status.should == 200
|
33
|
+
Notifiable.api_device_token_params.push('id').each{|p| json.should have_key(p.to_s)}
|
32
34
|
|
33
35
|
Notifiable::DeviceToken.count.should == 1
|
34
36
|
dt = Notifiable::DeviceToken.first
|
@@ -41,7 +43,8 @@ describe Notifiable::DeviceTokensController do
|
|
41
43
|
it "uses an existing token" do
|
42
44
|
post :create, :token => user2_device_token.token, :provider => user2_device_token.provider, :app_id => app.id, :user_email => user2.email
|
43
45
|
|
44
|
-
|
46
|
+
response.status.should == 200
|
47
|
+
Notifiable.api_device_token_params.push('id').each{|p| json.should have_key(p.to_s)}
|
45
48
|
|
46
49
|
Notifiable::DeviceToken.count.should == 1
|
47
50
|
user2.device_tokens.count.should == 1
|
@@ -54,7 +57,7 @@ describe Notifiable::DeviceTokensController do
|
|
54
57
|
it "doesn't create a token if no app is specified" do
|
55
58
|
post :create, :token => "ABC123", :user_email => user1.email, :provider => :mpns
|
56
59
|
|
57
|
-
|
60
|
+
response.status.should == 422
|
58
61
|
Notifiable::DeviceToken.count.should == 0
|
59
62
|
end
|
60
63
|
|
@@ -62,7 +65,9 @@ describe Notifiable::DeviceTokensController do
|
|
62
65
|
|
63
66
|
post :create, :token => user2_device_token.token, :provider => :mpns
|
64
67
|
|
65
|
-
|
68
|
+
response.status.should == 200
|
69
|
+
Notifiable.api_device_token_params.push('id').each{|p| json.should have_key(p.to_s)}
|
70
|
+
|
66
71
|
Notifiable::DeviceToken.count.should == 1
|
67
72
|
dt = Notifiable::DeviceToken.first
|
68
73
|
dt.token.should eql user2_device_token.token
|
@@ -72,7 +77,8 @@ describe Notifiable::DeviceTokensController do
|
|
72
77
|
it "updates token for an existing device token" do
|
73
78
|
put :update, :id => user2_device_token.id, :token => "DEF456", :user_email => user2.email
|
74
79
|
|
75
|
-
|
80
|
+
response.status.should == 200
|
81
|
+
Notifiable.api_device_token_params.each{|p| json.should have_key(p.to_s)}
|
76
82
|
|
77
83
|
Notifiable::DeviceToken.count.should == 1
|
78
84
|
dt = Notifiable::DeviceToken.first
|
@@ -89,21 +95,23 @@ describe Notifiable::DeviceTokensController do
|
|
89
95
|
it "doesn't delete token unless authorised" do
|
90
96
|
delete :destroy, :id => user2_device_token.id
|
91
97
|
|
92
|
-
|
98
|
+
response.status.should == 401
|
99
|
+
|
93
100
|
Notifiable::DeviceToken.where(:token => user2_device_token.token).count.should == 1
|
94
101
|
end
|
95
102
|
|
96
103
|
it "doesn't delete tokens of other users" do
|
97
104
|
delete :destroy, :id => user2_device_token.id, :user_email => user1.email
|
98
105
|
|
99
|
-
|
106
|
+
response.status.should == 401
|
107
|
+
|
100
108
|
Notifiable::DeviceToken.where(:token => user2_device_token.token).count.should == 1
|
101
109
|
end
|
102
110
|
|
103
111
|
it "doesnt delete tokens if they don't exist" do
|
104
112
|
delete :destroy, :id => 59, :user_email => user1.email
|
105
113
|
|
106
|
-
|
114
|
+
response.status.should == 404
|
107
115
|
Notifiable::DeviceToken.where(:token => user2_device_token.token).count.should == 1
|
108
116
|
end
|
109
117
|
|
data/spec/spec_helper.rb
CHANGED
@@ -29,6 +29,7 @@ RSpec.configure do |config|
|
|
29
29
|
config.infer_base_class_for_anonymous_controllers = false
|
30
30
|
config.order = "random"
|
31
31
|
config.include EngineControllerTestMonkeyPatch, :type => :controller
|
32
|
+
config.include Requests::JsonHelpers, :type => :controller
|
32
33
|
|
33
34
|
config.before(:each) {
|
34
35
|
DatabaseCleaner.start
|