notifiable-rails 0.20.0 → 0.21.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/{notifications_controller.rb → notification_statuses_controller.rb} +9 -13
- data/config/routes.rb +1 -1
- data/db/migrate/20131210115649_create_notifiable_device_tokens.rb +1 -0
- data/db/migrate/20131210115650_create_notifiable_notifications.rb +0 -10
- data/db/migrate/20131210115651_create_notifiable_localized_notifications.rb +22 -0
- data/db/migrate/{20131210115651_create_notifiable_statuses.rb → 20131210115652_create_notifiable_statuses.rb} +1 -1
- data/lib/generators/notifiable/install/templates/initializer.rb +1 -1
- data/lib/notifiable/device_token.rb +1 -0
- data/lib/notifiable/localized_notification.rb +14 -0
- data/lib/notifiable/notification.rb +12 -3
- data/lib/notifiable/notification_status.rb +6 -1
- data/lib/notifiable/notifier_base.rb +6 -2
- data/lib/notifiable/version.rb +1 -1
- data/lib/notifiable.rb +5 -1
- data/spec/controllers/device_tokens_controller_spec.rb +1 -1
- data/spec/controllers/{notifications_controller_spec.rb → notification_statuses_controller_spec.rb} +14 -14
- data/spec/model/device_token_spec.rb +16 -0
- data/spec/model/localized_notification_spec.rb +38 -0
- data/spec/model/notifiable_spec.rb +3 -3
- data/spec/model/notification_spec.rb +21 -30
- data/spec/spec_helper.rb +4 -0
- data/spec/support/factories.rb +17 -6
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/migrate/{20131210115652_create_users.rb → 20131210115660_create_users.rb} +0 -0
- data/spec/test_app/db/schema.rb +11 -3
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/log/development.log +57 -0
- data/spec/test_app/log/test.log +38505 -0
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68d901d11477d8f90ee9b4180d0c49ad37c38859
|
4
|
+
data.tar.gz: d734d5b725c04781ec6de1e07ef6b28e5280ff60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32251a7be76a5cad5a4277b80a7b2781e0a36cc16a5464c28d031f05de745744a16eb013a25bffeb11b07a8828f9965e5b9938261cb762cdd48e19639ff88b9c
|
7
|
+
data.tar.gz: dfc5f8e28c4c4f64408947584bb6c033e1a8bd087e6294b3753a1ccf4218a542b0a6e9342ed948477632a0c4e5dc83a71f46aaf5761bfafae562c38438ed44ad
|
data/app/controllers/notifiable/{notifications_controller.rb → notification_statuses_controller.rb}
RENAMED
@@ -1,29 +1,25 @@
|
|
1
|
-
|
2
1
|
module Notifiable
|
3
|
-
|
4
|
-
class NotificationsController < Notifiable.api_controller_class
|
5
|
-
|
2
|
+
class NotificationStatusesController < Notifiable.api_controller_class
|
6
3
|
before_filter :find_notification_status!, :check_authorisation!
|
7
|
-
|
4
|
+
|
8
5
|
def opened
|
9
|
-
if @notification_status.opened!
|
6
|
+
if @notification_status.opened!
|
10
7
|
head :status => :ok
|
11
8
|
else
|
12
9
|
render :json => { :errors => @notification_status.errors.full_messages }, :status => :unprocessable_entity
|
13
10
|
end
|
14
|
-
|
15
|
-
end
|
16
11
|
|
12
|
+
end
|
13
|
+
|
17
14
|
private
|
18
15
|
def find_notification_status!
|
19
|
-
return head :status => :not_acceptable unless params[:
|
20
|
-
|
21
|
-
@notification_status = NotificationStatus.
|
16
|
+
return head :status => :not_acceptable unless params[:localized_notification_id] && params[:device_token_id]
|
17
|
+
|
18
|
+
@notification_status = NotificationStatus.find_by_localized_notification_id_and_device_token_id!(params[:localized_notification_id], params[:device_token_id])
|
22
19
|
end
|
23
|
-
|
20
|
+
|
24
21
|
def check_authorisation!
|
25
22
|
head :status => :unauthorized unless current_notifiable_user == @notification_status.device_token.user
|
26
23
|
end
|
27
24
|
end
|
28
|
-
|
29
25
|
end
|
data/config/routes.rb
CHANGED
@@ -2,8 +2,6 @@ class CreateNotifiableNotifications < ActiveRecord::Migration
|
|
2
2
|
|
3
3
|
def change
|
4
4
|
create_table :notifiable_notifications do |t|
|
5
|
-
t.text :message
|
6
|
-
t.text :params
|
7
5
|
t.references :app
|
8
6
|
|
9
7
|
#stats
|
@@ -11,14 +9,6 @@ class CreateNotifiableNotifications < ActiveRecord::Migration
|
|
11
9
|
t.integer :gateway_accepted_count, :default => 0
|
12
10
|
t.integer :opened_count, :default => 0
|
13
11
|
|
14
|
-
# APNS - Optional
|
15
|
-
#t.integer :badge
|
16
|
-
#t.text :sound
|
17
|
-
#t.datetime :expiry
|
18
|
-
|
19
|
-
# MPNS - Optional
|
20
|
-
#t.text :title
|
21
|
-
|
22
12
|
t.timestamps
|
23
13
|
end
|
24
14
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateNotifiableLocalizedNotifications < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def change
|
4
|
+
create_table :notifiable_localized_notifications do |t|
|
5
|
+
t.text :message
|
6
|
+
t.text :params
|
7
|
+
t.string :locale
|
8
|
+
t.references :notification
|
9
|
+
|
10
|
+
# APNS - Optional
|
11
|
+
#t.integer :badge
|
12
|
+
#t.text :sound
|
13
|
+
#t.datetime :expiry
|
14
|
+
|
15
|
+
# MPNS - Optional
|
16
|
+
#t.text :title
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -5,7 +5,7 @@ Notifiable.configure do |config|
|
|
5
5
|
|
6
6
|
# Set the params permitted for creation of device tokens
|
7
7
|
# Defaults to [:token, :provider, :app_id]
|
8
|
-
#config.api_device_token_params = [:token, :provider, :app_id]
|
8
|
+
#config.api_device_token_params = [:token, :provider, :app_id, :locale]
|
9
9
|
|
10
10
|
# The class representing the holder of the device
|
11
11
|
config.user_class = User
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Notifiable
|
2
|
+
class LocalizedNotification < ActiveRecord::Base
|
3
|
+
belongs_to :notification, :class_name => "Notifiable::Notification"
|
4
|
+
#validates :notification, presence: true
|
5
|
+
|
6
|
+
serialize :params
|
7
|
+
|
8
|
+
has_many :notification_statuses, :class_name => 'Notifiable::NotificationStatus', :dependent => :destroy
|
9
|
+
|
10
|
+
def send_params
|
11
|
+
@send_params ||= (self.params ? self.params : {}).merge({:localized_notification_id => self.id})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -3,16 +3,25 @@ module Notifiable
|
|
3
3
|
|
4
4
|
serialize :params
|
5
5
|
|
6
|
-
has_many :
|
7
|
-
|
6
|
+
has_many :localized_notifications, :class_name => 'Notifiable::LocalizedNotification', :dependent => :destroy
|
7
|
+
accepts_nested_attributes_for :localized_notifications
|
8
8
|
|
9
|
-
|
9
|
+
belongs_to :app, :class_name => 'Notifiable::App'
|
10
|
+
validates :app, presence: true
|
11
|
+
|
12
|
+
def notification_statuses
|
13
|
+
Notifiable::NotificationStatus.joins(:localized_notification).where('notifiable_localized_notifications.notification_id' => self.id)
|
14
|
+
end
|
10
15
|
|
11
16
|
def batch
|
12
17
|
yield(self)
|
13
18
|
close
|
14
19
|
end
|
15
20
|
|
21
|
+
def localized_notification(locale)
|
22
|
+
self.localized_notifications.find_by(:locale => locale)
|
23
|
+
end
|
24
|
+
|
16
25
|
def add_notifiable(notifiable)
|
17
26
|
notifiable.device_tokens.each do |d|
|
18
27
|
self.add_device_token(d)
|
@@ -1,12 +1,17 @@
|
|
1
1
|
module Notifiable
|
2
2
|
class NotificationStatus < ActiveRecord::Base
|
3
|
-
|
3
|
+
|
4
|
+
belongs_to :localized_notification, :class_name => 'Notifiable::LocalizedNotification'
|
5
|
+
validates :localized_notification, presence: true
|
6
|
+
|
4
7
|
belongs_to :device_token, :class_name => 'Notifiable::DeviceToken'
|
8
|
+
validates :device_token, presence: true
|
5
9
|
|
6
10
|
self.table_name = 'notifiable_statuses'
|
7
11
|
|
8
12
|
def opened!
|
9
13
|
update_attribute(:status, -1)
|
14
|
+
self.localized_notification.notification.increment!(:opened_count)
|
10
15
|
end
|
11
16
|
|
12
17
|
def opened?
|
@@ -9,7 +9,7 @@ module Notifiable
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def send_notification(device_token)
|
12
|
-
enqueue(device_token)
|
12
|
+
enqueue(device_token, self.localized_notification(device_token))
|
13
13
|
end
|
14
14
|
|
15
15
|
def close
|
@@ -21,9 +21,13 @@ module Notifiable
|
|
21
21
|
def flush
|
22
22
|
|
23
23
|
end
|
24
|
+
|
25
|
+
def localized_notification(device_token)
|
26
|
+
self.notification.localized_notification(device_token.locale)
|
27
|
+
end
|
24
28
|
|
25
29
|
def processed(device_token, status)
|
26
|
-
receipts << {
|
30
|
+
receipts << {localized_notification_id: self.localized_notification(device_token).id, device_token_id: device_token.id, status: status, created_at: DateTime.now}
|
27
31
|
|
28
32
|
if receipts.count > Notifiable.notification_status_batch_size
|
29
33
|
save_receipts
|
data/lib/notifiable/version.rb
CHANGED
data/lib/notifiable.rb
CHANGED
@@ -4,6 +4,7 @@ require 'notifiable/notifiable_concern'
|
|
4
4
|
require 'notifiable/railtie' if defined?(Rails)
|
5
5
|
require 'notifiable/engine'
|
6
6
|
require 'notifiable/notification'
|
7
|
+
require 'notifiable/localized_notification'
|
7
8
|
require 'notifiable/notification_status'
|
8
9
|
require 'notifiable/device_token'
|
9
10
|
require 'notifiable/notifier_base'
|
@@ -13,7 +14,10 @@ module Notifiable
|
|
13
14
|
mattr_accessor :api_controller_class
|
14
15
|
|
15
16
|
mattr_accessor :api_device_token_params
|
16
|
-
@@api_device_token_params = [:token, :provider, :app_id]
|
17
|
+
@@api_device_token_params = [:token, :provider, :app_id, :locale]
|
18
|
+
|
19
|
+
mattr_accessor :locales
|
20
|
+
@@locales = [:en]
|
17
21
|
|
18
22
|
mattr_accessor :user_class
|
19
23
|
|
@@ -76,7 +76,7 @@ describe Notifiable::DeviceTokensController do
|
|
76
76
|
|
77
77
|
context "old" do
|
78
78
|
let(:user1) { FactoryGirl.create(:user) }
|
79
|
-
let(:user2) { FactoryGirl.create(:
|
79
|
+
let(:user2) { FactoryGirl.create(:user_with_en_token) }
|
80
80
|
let(:user2_device_token) { user2.device_tokens.first }
|
81
81
|
let(:app) { FactoryGirl.create(:app) }
|
82
82
|
let(:invalid_device_token) { FactoryGirl.create(:invalid_mock_token) }
|
data/spec/controllers/{notifications_controller_spec.rb → notification_statuses_controller_spec.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Notifiable::
|
3
|
+
describe Notifiable::NotificationStatusesController do
|
4
4
|
|
5
|
-
let(:user1_device_token) { user1.device_tokens.first }
|
6
|
-
let(:user2) {
|
7
|
-
let(:anonymous_device_token) {
|
5
|
+
#let(:user1_device_token) { user1.device_tokens.first }
|
6
|
+
#let(:user2) { create(:user) }
|
7
|
+
#let(:anonymous_device_token) { create(:mock_token) }
|
8
8
|
|
9
9
|
before(:each) do
|
10
10
|
@request.env["HTTP_ACCEPT"] = "application/json"
|
@@ -19,10 +19,10 @@ describe Notifiable::NotificationsController do
|
|
19
19
|
let(:notifiable_app) { create(:app) }
|
20
20
|
let(:user) { create(:user) }
|
21
21
|
let(:token) { create(:mock_token, :app => notifiable_app, :user_id => user.id) }
|
22
|
-
|
23
|
-
|
22
|
+
let(:localized_notification) { create(:localized_notification, :locale => :en) }
|
23
|
+
subject!(:status) { create(:notification_status, :localized_notification => localized_notification, :device_token => token) }
|
24
24
|
|
25
|
-
before(:each) { put :opened, {:
|
25
|
+
before(:each) { put :opened, {:localized_notification_id => localized_notification.id, :device_token_id => token.id, :user_email => user.email} }
|
26
26
|
|
27
27
|
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
28
28
|
it { expect(Notifiable::NotificationStatus.first.opened?).to eq true }
|
@@ -34,10 +34,10 @@ describe Notifiable::NotificationsController do
|
|
34
34
|
let(:user1) { create(:user) }
|
35
35
|
let(:user2) { create(:user) }
|
36
36
|
let(:token) { create(:mock_token, :app => notifiable_app, :user_id => user1.id) }
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
before(:each) { put :opened, {:
|
37
|
+
let(:localized_notification) { create(:localized_notification, :locale => :en) }
|
38
|
+
subject!(:status) { create(:notification_status, :localized_notification => localized_notification, :device_token => token) }
|
39
|
+
|
40
|
+
before(:each) { put :opened, {:localized_notification_id => localized_notification.id, :device_token_id => token.id, :user_email => user2.email} }
|
41
41
|
|
42
42
|
it { expect(response.status).to eq 401 }
|
43
43
|
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
@@ -49,10 +49,10 @@ describe Notifiable::NotificationsController do
|
|
49
49
|
describe "anonymously" do
|
50
50
|
let(:notifiable_app) { create(:app) }
|
51
51
|
let(:token) { create(:mock_token, :app => notifiable_app) }
|
52
|
-
|
53
|
-
let!(:status) { create(:notification_status, :
|
52
|
+
let(:localized_notification) { create(:localized_notification, :locale => :en) }
|
53
|
+
let!(:status) { create(:notification_status, :localized_notification => localized_notification, :device_token => token) }
|
54
54
|
|
55
|
-
before(:each) { put :opened, {:
|
55
|
+
before(:each) { put :opened, {:localized_notification_id => localized_notification.id, :device_token_id => token.id} }
|
56
56
|
|
57
57
|
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
58
58
|
it { expect(Notifiable::NotificationStatus.first.opened?).to eq true }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Notifiable::DeviceToken do
|
4
|
+
|
5
|
+
describe "#locale" do
|
6
|
+
subject(:token) { create(:mock_token, :locale => 'en') }
|
7
|
+
|
8
|
+
it { expect(token.locale).to eq 'en' }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#notification_statuses" do
|
12
|
+
subject(:token) { create(:mock_token, :notification_statuses => create_list(:notification_status, 2)) }
|
13
|
+
|
14
|
+
it { expect(token.notification_statuses.count).to eq 2 }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Notifiable::LocalizedNotification do
|
4
|
+
|
5
|
+
describe "#locale" do
|
6
|
+
subject!(:l) { create(:localized_notification, :locale => 'en') }
|
7
|
+
|
8
|
+
it { expect(Notifiable::LocalizedNotification.first.locale).to eq 'en' }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#message" do
|
12
|
+
subject!(:l) { create(:localized_notification, :message => "Test message") }
|
13
|
+
|
14
|
+
it { expect(Notifiable::LocalizedNotification.first.message).to eq "Test message" }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#params" do
|
18
|
+
subject!(:l) { create(:localized_notification, :params => {:custom_property => "A different message"}) }
|
19
|
+
|
20
|
+
it { expect(Notifiable::LocalizedNotification.first.params).to eq({:custom_property => "A different message"}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#notification" do
|
24
|
+
let(:n) {create(:notification)}
|
25
|
+
subject!(:l) { create(:localized_notification, :notification => n) }
|
26
|
+
|
27
|
+
it { expect(Notifiable::LocalizedNotification.first.notification).to eq n }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#destroy" do
|
31
|
+
subject(:l) { create(:localized_notification) }
|
32
|
+
let!(:s) { create(:notification_status, :localized_notification => l) }
|
33
|
+
|
34
|
+
before(:each) { l.destroy }
|
35
|
+
|
36
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 0 }
|
37
|
+
end
|
38
|
+
end
|
@@ -5,8 +5,8 @@ describe Notifiable::Concern do
|
|
5
5
|
describe "#send_notification" do
|
6
6
|
|
7
7
|
context "single" do
|
8
|
-
let(:user1) { create(:
|
9
|
-
let(:notification1) { create(:
|
8
|
+
let(:user1) { create(:user_with_en_token) }
|
9
|
+
let(:notification1) { create(:notification_with_en_localization) }
|
10
10
|
|
11
11
|
before(:each) { user1.send_notification(notification1) }
|
12
12
|
|
@@ -15,7 +15,7 @@ describe Notifiable::Concern do
|
|
15
15
|
|
16
16
|
context "invalid device" do
|
17
17
|
let(:user1) { FactoryGirl.create(:user_with_invalid_mock_token) }
|
18
|
-
let(:notification1) { create(:
|
18
|
+
let(:notification1) { create(:notification_with_en_localization) }
|
19
19
|
|
20
20
|
before(:each) { user1.send_notification(notification1) }
|
21
21
|
|
@@ -1,27 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Notifiable::Notification do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
subject!(:n) { create(:notification, :message => "Test message") }
|
12
|
-
|
13
|
-
it { expect(Notifiable::Notification.first.message).to eq "Test message" }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#params" do
|
17
|
-
subject!(:n) { create(:notification, :params => {:custom_property => "A different message"}) }
|
18
|
-
|
19
|
-
it { expect(Notifiable::Notification.first.params).to eq({:custom_property => "A different message"}) }
|
4
|
+
|
5
|
+
describe "#localized_notifications" do
|
6
|
+
subject(:n) { create(:notification) }
|
7
|
+
let!(:localizations) { create_list(:localized_notification, 2, :notification => n)}
|
8
|
+
|
9
|
+
it { expect(Notifiable::Notification.count).to eq 1 }
|
10
|
+
it { expect(Notifiable::Notification.first.localized_notifications.count).to eq 2 }
|
20
11
|
end
|
21
12
|
|
22
13
|
describe "#destroy" do
|
23
|
-
subject(:n) { create(:
|
24
|
-
let!(:s) { create(:notification_status, :
|
14
|
+
subject(:n) { create(:localized_notification) }
|
15
|
+
let!(:s) { create(:notification_status, :localized_notification => n) }
|
25
16
|
|
26
17
|
before(:each) { n.destroy }
|
27
18
|
|
@@ -30,11 +21,11 @@ describe Notifiable::Notification do
|
|
30
21
|
|
31
22
|
describe "#add_notifiable" do
|
32
23
|
context "for a single user" do
|
33
|
-
subject(:notification) { create(:
|
34
|
-
let(:u) { create(:
|
24
|
+
subject(:notification) { create(:notification_with_en_localization) }
|
25
|
+
let(:u) { create(:user_with_en_token) }
|
35
26
|
|
36
27
|
before(:each) do
|
37
|
-
|
28
|
+
notification.batch do |n|
|
38
29
|
n.add_notifiable(u)
|
39
30
|
end
|
40
31
|
end
|
@@ -48,12 +39,12 @@ describe Notifiable::Notification do
|
|
48
39
|
end
|
49
40
|
|
50
41
|
context "for two users" do
|
51
|
-
subject(:notification) { create(:
|
52
|
-
let(:u1) { create(:
|
53
|
-
let(:u2) { create(:
|
42
|
+
subject(:notification) { create(:notification_with_en_localization) }
|
43
|
+
let(:u1) { create(:user_with_en_token) }
|
44
|
+
let(:u2) { create(:user_with_en_token) }
|
54
45
|
|
55
46
|
before(:each) do
|
56
|
-
|
47
|
+
notification.batch do |n|
|
57
48
|
n.add_notifiable(u1)
|
58
49
|
n.add_notifiable(u2)
|
59
50
|
end
|
@@ -73,10 +64,10 @@ describe Notifiable::Notification do
|
|
73
64
|
|
74
65
|
describe "#add_device_token" do
|
75
66
|
context "single token" do
|
76
|
-
subject(:
|
77
|
-
let(:dt) { create(:
|
67
|
+
subject(:notification) { create(:notification_with_en_localization) }
|
68
|
+
let(:dt) { create(:device_token, :locale => :en) }
|
78
69
|
|
79
|
-
before(:each) {
|
70
|
+
before(:each) { notification.batch {|n| n.add_device_token(dt) } }
|
80
71
|
|
81
72
|
it { expect(Notifiable::Notification.first.sent_count).to eq 1 }
|
82
73
|
it { expect(Notifiable::Notification.first.gateway_accepted_count).to eq 1 }
|
@@ -87,11 +78,11 @@ describe Notifiable::Notification do
|
|
87
78
|
end
|
88
79
|
|
89
80
|
context "undefined provider" do
|
90
|
-
subject(:
|
81
|
+
subject(:notification) { create(:notification) }
|
91
82
|
let(:dt) { create(:mock_token, :provider => :sms) }
|
92
83
|
|
93
84
|
before(:each) do
|
94
|
-
|
85
|
+
notification.batch do |n|
|
95
86
|
begin
|
96
87
|
n.add_device_token(unconfigured_device_token)
|
97
88
|
rescue
|
data/spec/spec_helper.rb
CHANGED
@@ -45,6 +45,10 @@ RSpec.configure do |config|
|
|
45
45
|
# Infer the spec type from the containing folder
|
46
46
|
config.infer_spec_type_from_file_location!
|
47
47
|
|
48
|
+
config.before(:suite) do
|
49
|
+
#FactoryGirl.lint
|
50
|
+
end
|
51
|
+
|
48
52
|
config.before(:each) {
|
49
53
|
DatabaseCleaner.start
|
50
54
|
Notifiable.delivery_method = :send
|
data/spec/support/factories.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
FactoryGirl.define do
|
2
2
|
|
3
|
-
|
3
|
+
sequence(:token) {|n| "ABCD#{n}" }
|
4
|
+
|
5
|
+
factory :device_token, aliases: [:mock_token], :class => Notifiable::DeviceToken do
|
4
6
|
provider :mock
|
5
|
-
|
7
|
+
token
|
6
8
|
app
|
7
9
|
|
8
10
|
factory :invalid_mock_token do
|
@@ -15,13 +17,22 @@ FactoryGirl.define do
|
|
15
17
|
|
16
18
|
factory :notification, :class => Notifiable::Notification do
|
17
19
|
app
|
20
|
+
|
21
|
+
factory :notification_with_en_localization do
|
22
|
+
after(:create) do |notification, evaluator|
|
23
|
+
FactoryGirl.create(:localized_notification, :locale => :en, :notification => notification)
|
24
|
+
end
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
28
|
+
factory :localized_notification, :class => Notifiable::LocalizedNotification do
|
29
|
+
notification
|
30
|
+
end
|
20
31
|
|
21
32
|
factory :notification_status, :class => Notifiable::NotificationStatus do
|
22
|
-
|
33
|
+
localized_notification
|
23
34
|
status 0
|
24
|
-
|
35
|
+
device_token
|
25
36
|
end
|
26
37
|
|
27
38
|
sequence(:email) {|n| "person-#{n}@example.com" }
|
@@ -29,9 +40,9 @@ FactoryGirl.define do
|
|
29
40
|
factory :user do
|
30
41
|
email
|
31
42
|
|
32
|
-
factory :
|
43
|
+
factory :user_with_en_token do
|
33
44
|
after(:create) do |user, evaluator|
|
34
|
-
FactoryGirl.create(:
|
45
|
+
FactoryGirl.create(:device_token, :user_id => user.id, :locale => :en)
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
Binary file
|
data/spec/test_app/db/migrate/{20131210115652_create_users.rb → 20131210115660_create_users.rb}
RENAMED
File without changes
|
data/spec/test_app/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20131210115660) do
|
15
15
|
|
16
16
|
create_table "notifiable_apps", force: true do |t|
|
17
17
|
t.string "name"
|
@@ -23,6 +23,7 @@ ActiveRecord::Schema.define(version: 20131210115652) 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 "locale"
|
26
27
|
t.boolean "is_valid", default: true
|
27
28
|
t.integer "user_id"
|
28
29
|
t.integer "app_id"
|
@@ -33,9 +34,16 @@ ActiveRecord::Schema.define(version: 20131210115652) do
|
|
33
34
|
add_index "notifiable_device_tokens", ["token"], name: "index_notifiable_device_tokens_on_token", unique: true
|
34
35
|
add_index "notifiable_device_tokens", ["user_id"], name: "index_notifiable_device_tokens_on_user_id"
|
35
36
|
|
36
|
-
create_table "
|
37
|
+
create_table "notifiable_localized_notifications", force: true do |t|
|
37
38
|
t.text "message"
|
38
39
|
t.text "params"
|
40
|
+
t.string "locale"
|
41
|
+
t.integer "notification_id"
|
42
|
+
t.datetime "created_at"
|
43
|
+
t.datetime "updated_at"
|
44
|
+
end
|
45
|
+
|
46
|
+
create_table "notifiable_notifications", force: true do |t|
|
39
47
|
t.integer "app_id"
|
40
48
|
t.integer "sent_count", default: 0
|
41
49
|
t.integer "gateway_accepted_count", default: 0
|
@@ -45,7 +53,7 @@ ActiveRecord::Schema.define(version: 20131210115652) do
|
|
45
53
|
end
|
46
54
|
|
47
55
|
create_table "notifiable_statuses", force: true do |t|
|
48
|
-
t.integer "
|
56
|
+
t.integer "localized_notification_id"
|
49
57
|
t.integer "device_token_id"
|
50
58
|
t.integer "status"
|
51
59
|
t.datetime "created_at"
|
Binary file
|