notifiable-rails 0.15.2 → 0.15.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e5c9e0517d0c144b71ee217a4d01ba004f2d535
4
- data.tar.gz: 2294beb4bd3cded57e19c4c95039311c958f52af
3
+ metadata.gz: 83b57f3c9bf7316dfd03fd35f33ab946757bae77
4
+ data.tar.gz: 74b884fe096cdb15ef63c051d33743c06019cd28
5
5
  SHA512:
6
- metadata.gz: f1f8a84df5cb874e8576323c8985a6765c821e62d49ac725e509b64033282c65ab751b8536051c408021cc73342967baf0eaa6ff55c3da8169c2c44a7ed35bb4
7
- data.tar.gz: de8e5cab899553948f08ef806228eea319c1cd85fafa899536ab93f9229adc525b9b74be1e5b665c127fd40b4780f7d5ac581386e5f5f42e68655641e1d27c15
6
+ metadata.gz: a43e0b1d07bc1101b373c54295942826580d063d1534c555c5ed748663d661cdc34160452f1b212f9d0e1fdf96a99f149ebb68184e9baca6959465344748b198
7
+ data.tar.gz: 849f950abc4c4735d9efd34b66ae7fc40c3aa0fd98c33143319e5219088cf6f35f40702d6a10a051b25151abe456ab680d4e623dd63b19521ebf059005d569f0
@@ -3,7 +3,7 @@ module Notifiable
3
3
 
4
4
  class NotificationsController < Notifiable.api_controller_class
5
5
 
6
- before_filter :ensure_current_notifiable_user!, :find_notification_status!, :check_authorisation!
6
+ before_filter :find_notification_status!, :check_authorisation!
7
7
 
8
8
  def opened
9
9
  if @notification_status.opened! && @notification_status.notification.increment!(:opened_count)
@@ -16,20 +16,13 @@ module Notifiable
16
16
 
17
17
  private
18
18
  def find_notification_status!
19
- return head :status => :not_acceptable unless params[:notification_id] && params[:device_token] && (params[:device_token][:device_id] || params[:device_token][:token])
20
- device_token = params[:device_token][:device_id] ?
21
- DeviceToken.find_by!("device_id = ?", params[:device_token][:device_id]) :
22
- DeviceToken.find_by!("token = ?", params[:device_token][:token])
23
-
24
- @notification_status = NotificationStatus.find_by!("notification_id = ? AND device_token_id = ?", params[:notification_id], device_token.id)
19
+ return head :status => :not_acceptable unless params[:notification_id] && params[:device_token_id]
20
+
21
+ @notification_status = NotificationStatus.find_by!("notification_id = ? AND device_token_id = ?", params[:notification_id], params[:device_token_id])
25
22
  end
26
23
 
27
24
  def check_authorisation!
28
- head :status => :not_acceptable unless current_notifiable_user == @notification_status.device_token.user
29
- end
30
-
31
- def ensure_current_notifiable_user!
32
- head :status => :not_acceptable unless current_notifiable_user
25
+ head :status => :unauthorized unless current_notifiable_user == @notification_status.device_token.user
33
26
  end
34
27
  end
35
28
 
@@ -4,8 +4,8 @@ Notifiable.configure do |config|
4
4
  config.api_controller_class = ApplicationController
5
5
 
6
6
  # Set the params permitted for creation of device tokens
7
- # Defaults to [:device_id, :token, :provider]
8
- #config.api_device_token_params = [:device_id, :token, :provider]
7
+ # Defaults to [:token, :provider, :app_id]
8
+ #config.api_device_token_params = [:token, :provider, :app_id]
9
9
 
10
10
  # The class representing the holder of the device
11
11
  config.user_class = User
@@ -1,3 +1,3 @@
1
1
  module Notifiable
2
- VERSION = "0.15.2"
2
+ VERSION = "0.15.3"
3
3
  end
@@ -7,6 +7,7 @@ describe Notifiable::NotificationsController do
7
7
  let(:user2) { FactoryGirl.create(:user) }
8
8
  let(:app) { user1_device_token.app }
9
9
  let(:notification) { FactoryGirl.create(:notification, :app => app)}
10
+ let(:anonymous_device_token) { FactoryGirl.create(:mock_token) }
10
11
 
11
12
  before(:each) do
12
13
  @request.env["HTTP_ACCEPT"] = "application/json"
@@ -16,9 +17,25 @@ describe Notifiable::NotificationsController do
16
17
  it "marks a status as opened" do
17
18
  FactoryGirl.create(:notification_status, :notification => notification, :device_token => user1_device_token)
18
19
 
19
- put :opened, {:notification_id => notification.id, :device_token => {:token => user1_device_token.token}, :user_email => user1.email}
20
+ put :opened, {:notification_id => notification.id, :device_token_id => user1_device_token.id, :user_email => user1.email}
20
21
 
21
- expect(response).to be_success
22
+ response.status.should == 200
23
+
24
+ Notifiable::NotificationStatus.count.should == 1
25
+ saved_status = Notifiable::NotificationStatus.first
26
+ saved_status.opened?.should be_true
27
+
28
+ Notifiable::Notification.count.should == 1
29
+ saved_notification = Notifiable::Notification.first
30
+ saved_notification.opened_count.should == 1
31
+ end
32
+
33
+ it "marks a status as opened anonymously" do
34
+ FactoryGirl.create(:notification_status, :notification => notification, :device_token => anonymous_device_token)
35
+
36
+ put :opened, {:notification_id => notification.id, :device_token_id => anonymous_device_token.id}
37
+
38
+ response.status.should == 200
22
39
 
23
40
  Notifiable::NotificationStatus.count.should == 1
24
41
  saved_status = Notifiable::NotificationStatus.first
@@ -32,9 +49,9 @@ describe Notifiable::NotificationsController do
32
49
  it "returns an error if the user is incorrect" do
33
50
  FactoryGirl.create(:notification_status, :notification => notification, :device_token => user1_device_token)
34
51
 
35
- post :opened, {:notification_id => notification.id, :device_token => {:token => user1_device_token.token}, :user_email => user2.email}
52
+ post :opened, {:notification_id => notification.id, :device_token_id => user1_device_token.id, :user_email => user2.email}
36
53
 
37
- expect(response.status).to eq(406)
54
+ response.status.should == 401
38
55
 
39
56
  Notifiable::NotificationStatus.count.should == 1
40
57
  saved_status = Notifiable::NotificationStatus.first
@@ -4,7 +4,6 @@ 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.string :device_id
8
7
  t.boolean :is_valid, :default => true
9
8
  t.integer :user_id
10
9
  t.references :app
@@ -12,7 +11,6 @@ class CreateNotifiableDeviceTokens < ActiveRecord::Migration
12
11
  t.timestamps
13
12
  end
14
13
 
15
- add_index :notifiable_device_tokens, :device_id, :unique => true
16
14
  add_index :notifiable_device_tokens, :token, :unique => true
17
15
  add_index :notifiable_device_tokens, :user_id
18
16
  end
@@ -23,7 +23,6 @@ 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.string "device_id"
27
26
  t.boolean "is_valid", default: true
28
27
  t.integer "user_id"
29
28
  t.integer "app_id"
@@ -31,7 +30,6 @@ ActiveRecord::Schema.define(version: 20131229104039) do
31
30
  t.datetime "updated_at"
32
31
  end
33
32
 
34
- add_index "notifiable_device_tokens", ["device_id"], name: "index_notifiable_device_tokens_on_device_id", unique: true
35
33
  add_index "notifiable_device_tokens", ["token"], name: "index_notifiable_device_tokens_on_token", unique: true
36
34
  add_index "notifiable_device_tokens", ["user_id"], name: "index_notifiable_device_tokens_on_user_id"
37
35
 
Binary file