presskit-apn_on_rails 0.1
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.
- data/.rspec +2 -0
- data/.specification +80 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +21 -0
- data/README +179 -0
- data/README.textile +209 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/generators/apn_migrations_generator.rb +31 -0
- data/generators/templates/apn_migrations/001_create_apn_devices.rb +13 -0
- data/generators/templates/apn_migrations/002_create_apn_notifications.rb +23 -0
- data/generators/templates/apn_migrations/003_alter_apn_devices.rb +25 -0
- data/generators/templates/apn_migrations/004_create_apn_apps.rb +18 -0
- data/generators/templates/apn_migrations/005_create_groups.rb +23 -0
- data/generators/templates/apn_migrations/006_alter_apn_groups.rb +11 -0
- data/generators/templates/apn_migrations/007_create_device_groups.rb +27 -0
- data/generators/templates/apn_migrations/008_create_apn_group_notifications.rb +23 -0
- data/generators/templates/apn_migrations/009_create_pull_notifications.rb +16 -0
- data/generators/templates/apn_migrations/010_alter_apn_notifications.rb +21 -0
- data/generators/templates/apn_migrations/011_make_device_token_index_nonunique.rb +11 -0
- data/generators/templates/apn_migrations/012_add_launch_notification_to_apn_pull_notifications.rb +9 -0
- data/lib/apn_on_rails.rb +4 -0
- data/lib/apn_on_rails/apn_on_rails.rb +81 -0
- data/lib/apn_on_rails/app/models/apn/app.rb +152 -0
- data/lib/apn_on_rails/app/models/apn/base.rb +9 -0
- data/lib/apn_on_rails/app/models/apn/device.rb +50 -0
- data/lib/apn_on_rails/app/models/apn/device_grouping.rb +16 -0
- data/lib/apn_on_rails/app/models/apn/group.rb +12 -0
- data/lib/apn_on_rails/app/models/apn/group_notification.rb +79 -0
- data/lib/apn_on_rails/app/models/apn/notification.rb +93 -0
- data/lib/apn_on_rails/app/models/apn/pull_notification.rb +28 -0
- data/lib/apn_on_rails/libs/connection.rb +70 -0
- data/lib/apn_on_rails/libs/feedback.rb +39 -0
- data/lib/apn_on_rails/tasks/apn.rake +30 -0
- data/lib/apn_on_rails/tasks/db.rake +19 -0
- data/lib/apn_on_rails_tasks.rb +3 -0
- data/presskit-apn_on_rails.gemspec +144 -0
- data/spec/active_record/setup_ar.rb +19 -0
- data/spec/apn_on_rails/app/models/apn/app_spec.rb +230 -0
- data/spec/apn_on_rails/app/models/apn/device_spec.rb +60 -0
- data/spec/apn_on_rails/app/models/apn/group_notification_spec.rb +66 -0
- data/spec/apn_on_rails/app/models/apn/notification_spec.rb +71 -0
- data/spec/apn_on_rails/app/models/apn/pull_notification_spec.rb +100 -0
- data/spec/apn_on_rails/libs/connection_spec.rb +40 -0
- data/spec/apn_on_rails/libs/feedback_spec.rb +43 -0
- data/spec/extensions/string.rb +10 -0
- data/spec/factories/app_factory.rb +27 -0
- data/spec/factories/device_factory.rb +29 -0
- data/spec/factories/device_grouping_factory.rb +22 -0
- data/spec/factories/group_factory.rb +27 -0
- data/spec/factories/group_notification_factory.rb +22 -0
- data/spec/factories/notification_factory.rb +22 -0
- data/spec/factories/pull_notification_factory.rb +22 -0
- data/spec/fixtures/hexa.bin +1 -0
- data/spec/fixtures/message_for_sending.bin +0 -0
- data/spec/rails_root/config/apple_push_notification_development.pem +19 -0
- data/spec/spec_helper.rb +55 -0
- metadata +282 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{presskit-apn_on_rails}
|
8
|
+
s.version = "0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["markbates", "Rebecca Nesson", "Caleb Adam Haye"]
|
12
|
+
s.date = %q{2011-11-31}
|
13
|
+
s.description = %q{APN on Rails is a Ruby on Rails gem that allows you to
|
14
|
+
easily add Apple Push Notification (iPhone) support to your Rails application. This version includes an association between an assumed User model and APN::Device
|
15
|
+
}
|
16
|
+
s.email = %q{caleb@fire.coop}
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README",
|
20
|
+
"README.textile"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".rspec",
|
24
|
+
".specification",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE",
|
28
|
+
"README",
|
29
|
+
"README.textile",
|
30
|
+
"Rakefile",
|
31
|
+
"VERSION",
|
32
|
+
"presskit-apn_on_rails.gemspec",
|
33
|
+
"autotest/discover.rb",
|
34
|
+
"generators/apn_migrations_generator.rb",
|
35
|
+
"generators/templates/apn_migrations/001_create_apn_devices.rb",
|
36
|
+
"generators/templates/apn_migrations/002_create_apn_notifications.rb",
|
37
|
+
"generators/templates/apn_migrations/003_alter_apn_devices.rb",
|
38
|
+
"generators/templates/apn_migrations/004_create_apn_apps.rb",
|
39
|
+
"generators/templates/apn_migrations/005_create_groups.rb",
|
40
|
+
"generators/templates/apn_migrations/006_alter_apn_groups.rb",
|
41
|
+
"generators/templates/apn_migrations/007_create_device_groups.rb",
|
42
|
+
"generators/templates/apn_migrations/008_create_apn_group_notifications.rb",
|
43
|
+
"generators/templates/apn_migrations/009_create_pull_notifications.rb",
|
44
|
+
"generators/templates/apn_migrations/010_alter_apn_notifications.rb",
|
45
|
+
"generators/templates/apn_migrations/011_make_device_token_index_nonunique.rb",
|
46
|
+
"generators/templates/apn_migrations/012_add_launch_notification_to_apn_pull_notifications.rb",
|
47
|
+
"lib/apn_on_rails.rb",
|
48
|
+
"lib/apn_on_rails/apn_on_rails.rb",
|
49
|
+
"lib/apn_on_rails/app/models/apn/app.rb",
|
50
|
+
"lib/apn_on_rails/app/models/apn/base.rb",
|
51
|
+
"lib/apn_on_rails/app/models/apn/device.rb",
|
52
|
+
"lib/apn_on_rails/app/models/apn/device_grouping.rb",
|
53
|
+
"lib/apn_on_rails/app/models/apn/group.rb",
|
54
|
+
"lib/apn_on_rails/app/models/apn/group_notification.rb",
|
55
|
+
"lib/apn_on_rails/app/models/apn/notification.rb",
|
56
|
+
"lib/apn_on_rails/app/models/apn/pull_notification.rb",
|
57
|
+
"lib/apn_on_rails/libs/connection.rb",
|
58
|
+
"lib/apn_on_rails/libs/feedback.rb",
|
59
|
+
"lib/apn_on_rails/tasks/apn.rake",
|
60
|
+
"lib/apn_on_rails/tasks/db.rake",
|
61
|
+
"lib/apn_on_rails_tasks.rb",
|
62
|
+
"spec/active_record/setup_ar.rb",
|
63
|
+
"spec/apn_on_rails/app/models/apn/app_spec.rb",
|
64
|
+
"spec/apn_on_rails/app/models/apn/device_spec.rb",
|
65
|
+
"spec/apn_on_rails/app/models/apn/group_notification_spec.rb",
|
66
|
+
"spec/apn_on_rails/app/models/apn/notification_spec.rb",
|
67
|
+
"spec/apn_on_rails/app/models/apn/pull_notification_spec.rb",
|
68
|
+
"spec/apn_on_rails/libs/connection_spec.rb",
|
69
|
+
"spec/apn_on_rails/libs/feedback_spec.rb",
|
70
|
+
"spec/extensions/string.rb",
|
71
|
+
"spec/factories/app_factory.rb",
|
72
|
+
"spec/factories/device_factory.rb",
|
73
|
+
"spec/factories/device_grouping_factory.rb",
|
74
|
+
"spec/factories/group_factory.rb",
|
75
|
+
"spec/factories/group_notification_factory.rb",
|
76
|
+
"spec/factories/notification_factory.rb",
|
77
|
+
"spec/factories/pull_notification_factory.rb",
|
78
|
+
"spec/fixtures/hexa.bin",
|
79
|
+
"spec/fixtures/message_for_sending.bin",
|
80
|
+
"spec/rails_root/config/apple_push_notification_development.pem",
|
81
|
+
"spec/spec_helper.rb"
|
82
|
+
]
|
83
|
+
s.homepage = %q{http://github.com/calebhaye/apn_on_rails}
|
84
|
+
s.require_paths = ["lib"]
|
85
|
+
s.rubygems_version = %q{1.3.7}
|
86
|
+
s.summary = %q{Apple Push Notifications on Rails}
|
87
|
+
s.test_files = [
|
88
|
+
"spec/active_record/setup_ar.rb",
|
89
|
+
"spec/apn_on_rails/app/models/apn/app_spec.rb",
|
90
|
+
"spec/apn_on_rails/app/models/apn/device_spec.rb",
|
91
|
+
"spec/apn_on_rails/app/models/apn/group_notification_spec.rb",
|
92
|
+
"spec/apn_on_rails/app/models/apn/notification_spec.rb",
|
93
|
+
"spec/apn_on_rails/app/models/apn/pull_notification_spec.rb",
|
94
|
+
"spec/apn_on_rails/libs/connection_spec.rb",
|
95
|
+
"spec/apn_on_rails/libs/feedback_spec.rb",
|
96
|
+
"spec/extensions/string.rb",
|
97
|
+
"spec/factories/app_factory.rb",
|
98
|
+
"spec/factories/device_factory.rb",
|
99
|
+
"spec/factories/device_grouping_factory.rb",
|
100
|
+
"spec/factories/group_factory.rb",
|
101
|
+
"spec/factories/group_notification_factory.rb",
|
102
|
+
"spec/factories/notification_factory.rb",
|
103
|
+
"spec/factories/pull_notification_factory.rb",
|
104
|
+
"spec/spec_helper.rb"
|
105
|
+
]
|
106
|
+
|
107
|
+
if s.respond_to? :specification_version then
|
108
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
109
|
+
s.specification_version = 3
|
110
|
+
|
111
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
112
|
+
s.add_runtime_dependency(%q<configatron>, [">= 0"])
|
113
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
114
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
115
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
116
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
117
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.0"])
|
118
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
119
|
+
s.add_development_dependency(%q<actionpack>, ["~> 2.3.0"])
|
120
|
+
s.add_development_dependency(%q<activerecord>, ["~> 2.3.0"])
|
121
|
+
else
|
122
|
+
s.add_dependency(%q<configatron>, [">= 0"])
|
123
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
124
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
125
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
126
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
127
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
|
128
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
129
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
|
130
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
|
131
|
+
end
|
132
|
+
else
|
133
|
+
s.add_dependency(%q<configatron>, [">= 0"])
|
134
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
135
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
136
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
137
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
138
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.0"])
|
139
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
140
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.0"])
|
141
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.0"])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
logger = Logger.new(STDOUT)
|
5
|
+
logger.level = Logger::INFO
|
6
|
+
ActiveRecord::Base.logger = logger
|
7
|
+
|
8
|
+
db_file = File.join(File.dirname(__FILE__), 'test.db')
|
9
|
+
FileUtils.rm(db_file) if File.exists?(db_file)
|
10
|
+
# File.open(db_file, 'w')
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection({
|
13
|
+
:adapter => 'sqlite3',
|
14
|
+
:database => db_file
|
15
|
+
})
|
16
|
+
|
17
|
+
ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', '..', 'generators', 'templates', 'apn_migrations'))
|
18
|
+
|
19
|
+
# raise hell
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe APN::App do
|
4
|
+
|
5
|
+
describe 'send_notifications' do
|
6
|
+
|
7
|
+
it 'should send the unsent notifications' do
|
8
|
+
|
9
|
+
app = AppFactory.create
|
10
|
+
device = DeviceFactory.create({:app_id => app.id})
|
11
|
+
notifications = [NotificationFactory.create({:device_id => device.id}),
|
12
|
+
NotificationFactory.create({:device_id => device.id})]
|
13
|
+
|
14
|
+
notifications.each_with_index do |notify, i|
|
15
|
+
notify.stub(:message_for_sending).and_return("message-#{i}")
|
16
|
+
notify.should_receive(:sent_at=).with(instance_of(Time))
|
17
|
+
notify.should_receive(:save)
|
18
|
+
end
|
19
|
+
|
20
|
+
APN::App.should_receive(:all).once.and_return([app])
|
21
|
+
app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
|
22
|
+
|
23
|
+
APN::Device.should_receive(:find_each).twice.and_yield(device)
|
24
|
+
|
25
|
+
device.should_receive(:unsent_notifications).and_return(notifications,[])
|
26
|
+
|
27
|
+
|
28
|
+
ssl_mock = mock('ssl_mock')
|
29
|
+
ssl_mock.should_receive(:write).with('message-0')
|
30
|
+
ssl_mock.should_receive(:write).with('message-1')
|
31
|
+
APN::Connection.should_receive(:open_for_delivery).twice.and_yield(ssl_mock, nil)
|
32
|
+
APN::App.send_notifications
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'send_notifications_not_associated_with_an_app' do
|
39
|
+
|
40
|
+
it 'should send unsent notifications that are associated with devices that are not with any app' do
|
41
|
+
RAILS_ENV = 'staging'
|
42
|
+
device = DeviceFactory.create
|
43
|
+
device.app_id = nil
|
44
|
+
device.save
|
45
|
+
APN::App.all.each { |a| a.destroy }
|
46
|
+
notifications = [NotificationFactory.create({:device_id => device.id}),
|
47
|
+
NotificationFactory.create({:device_id => device.id})]
|
48
|
+
|
49
|
+
notifications.each_with_index do |notify, i|
|
50
|
+
notify.stub(:message_for_sending).and_return("message-#{i}")
|
51
|
+
notify.should_receive(:sent_at=).with(instance_of(Time))
|
52
|
+
notify.should_receive(:save)
|
53
|
+
end
|
54
|
+
|
55
|
+
APN::Device.should_receive(:find_each).and_yield(device)
|
56
|
+
device.should_receive(:unsent_notifications).and_return(notifications)
|
57
|
+
|
58
|
+
ssl_mock = mock('ssl_mock')
|
59
|
+
ssl_mock.should_receive(:write).with('message-0')
|
60
|
+
ssl_mock.should_receive(:write).with('message-1')
|
61
|
+
APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
|
62
|
+
APN::App.send_notifications
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'send_group_notifications' do
|
67
|
+
|
68
|
+
it 'should send the unsent group notifications' do
|
69
|
+
|
70
|
+
app = AppFactory.create
|
71
|
+
device = DeviceFactory.create({:app_id => app.id})
|
72
|
+
group = GroupFactory.create({:app_id => app.id})
|
73
|
+
device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
|
74
|
+
gnotys = [GroupNotificationFactory.create({:group_id => group.id}),
|
75
|
+
GroupNotificationFactory.create({:group_id => group.id})]
|
76
|
+
gnotys.each_with_index do |gnoty, i|
|
77
|
+
gnoty.stub!(:message_for_sending).and_return("message-#{i}")
|
78
|
+
gnoty.should_receive(:sent_at=).with(instance_of(Time))
|
79
|
+
gnoty.should_receive(:save)
|
80
|
+
end
|
81
|
+
|
82
|
+
APN::App.should_receive(:all).and_return([app])
|
83
|
+
app.should_receive(:unsent_group_notifications).at_least(:once).and_return(gnotys)
|
84
|
+
app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
|
85
|
+
|
86
|
+
ssl_mock = mock('ssl_mock')
|
87
|
+
ssl_mock.should_receive(:write).with('message-0')
|
88
|
+
ssl_mock.should_receive(:write).with('message-1')
|
89
|
+
APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
|
90
|
+
|
91
|
+
APN::App.send_group_notifications
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'send single group notification' do
|
98
|
+
|
99
|
+
it 'should send the argument group notification' do
|
100
|
+
app = AppFactory.create
|
101
|
+
device = DeviceFactory.create({:app_id => app.id})
|
102
|
+
group = GroupFactory.create({:app_id => app.id})
|
103
|
+
device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
|
104
|
+
gnoty = GroupNotificationFactory.create({:group_id => group.id})
|
105
|
+
gnoty.stub!(:message_for_sending).and_return("message-0")
|
106
|
+
gnoty.should_receive(:sent_at=).with(instance_of(Time))
|
107
|
+
gnoty.should_receive(:save)
|
108
|
+
|
109
|
+
app.should_receive(:cert).at_least(:once).and_return(app.apn_dev_cert)
|
110
|
+
|
111
|
+
ssl_mock = mock('ssl_mock')
|
112
|
+
ssl_mock.should_receive(:write).with('message-0')
|
113
|
+
APN::Connection.should_receive(:open_for_delivery).and_yield(ssl_mock, nil)
|
114
|
+
|
115
|
+
app.send_group_notification(gnoty)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'nil cert when sending notifications' do
|
121
|
+
|
122
|
+
it 'should raise an exception for sending notifications for an app with no cert' do
|
123
|
+
app = AppFactory.create
|
124
|
+
APN::App.should_receive(:all).and_return([app])
|
125
|
+
app.should_receive(:cert).and_return(nil)
|
126
|
+
lambda {
|
127
|
+
APN::App.send_notifications
|
128
|
+
}.should raise_error(APN::Errors::MissingCertificateError)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'nil cert when sending group notifications' do
|
134
|
+
|
135
|
+
it 'should raise an exception for sending group notifications for an app with no cert' do
|
136
|
+
app = AppFactory.create
|
137
|
+
APN::App.should_receive(:all).and_return([app])
|
138
|
+
app.should_receive(:cert).and_return(nil)
|
139
|
+
lambda {
|
140
|
+
APN::App.send_group_notifications
|
141
|
+
}.should raise_error(APN::Errors::MissingCertificateError)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'nil cert when sending single group notification' do
|
147
|
+
|
148
|
+
it 'should raise an exception for sending group notifications for an app with no cert' do
|
149
|
+
app = AppFactory.create
|
150
|
+
device = DeviceFactory.create({:app_id => app.id})
|
151
|
+
group = GroupFactory.create({:app_id => app.id})
|
152
|
+
device_grouping = DeviceGroupingFactory.create({:group_id => group.id,:device_id => device.id})
|
153
|
+
gnoty = GroupNotificationFactory.create({:group_id => group.id})
|
154
|
+
app.should_receive(:cert).and_return(nil)
|
155
|
+
lambda {
|
156
|
+
app.send_group_notification(gnoty)
|
157
|
+
}.should raise_error(APN::Errors::MissingCertificateError)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
describe 'process_devices' do
|
163
|
+
|
164
|
+
it 'should destroy devices that have a last_registered_at date that is before the feedback_at date' do
|
165
|
+
app = AppFactory.create
|
166
|
+
devices = [DeviceFactory.create(:app_id => app.id, :last_registered_at => 1.week.ago, :feedback_at => Time.now),
|
167
|
+
DeviceFactory.create(:app_id => app.id, :last_registered_at => 1.week.from_now, :feedback_at => Time.now)]
|
168
|
+
puts "device ids are #{devices[0].id} and #{devices[1].id}"
|
169
|
+
devices[0].last_registered_at = 1.week.ago
|
170
|
+
devices[0].save
|
171
|
+
devices[1].last_registered_at = 1.week.from_now
|
172
|
+
devices[1].save
|
173
|
+
APN::Feedback.should_receive(:devices).twice.and_return(devices)
|
174
|
+
APN::App.should_receive(:all).and_return([app])
|
175
|
+
app.should_receive(:cert).twice.and_return(app.apn_dev_cert)
|
176
|
+
lambda {
|
177
|
+
APN::App.process_devices
|
178
|
+
}.should change(APN::Device, :count).by(-1)
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe 'process_devices for global app' do
|
184
|
+
|
185
|
+
it 'should destroy devices that have a last_registered_at date that is before the feedback_at date that have no app' do
|
186
|
+
device = DeviceFactory.create(:app_id => nil, :last_registered_at => 1.week.ago, :feedback_at => Time.now)
|
187
|
+
device.app_id = nil
|
188
|
+
device.last_registered_at = 1.week.ago
|
189
|
+
device.save
|
190
|
+
APN::Feedback.should_receive(:devices).and_return([device])
|
191
|
+
APN::App.should_receive(:all).and_return([])
|
192
|
+
lambda {
|
193
|
+
APN::App.process_devices
|
194
|
+
}.should change(APN::Device, :count).by(-1)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe 'nil cert when processing devices' do
|
199
|
+
|
200
|
+
it 'should raise an exception for processing devices for an app with no cert' do
|
201
|
+
app = AppFactory.create
|
202
|
+
APN::App.should_receive(:all).and_return([app])
|
203
|
+
app.should_receive(:cert).and_return(nil)
|
204
|
+
lambda {
|
205
|
+
APN::App.process_devices
|
206
|
+
}.should raise_error(APN::Errors::MissingCertificateError)
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
describe 'cert for production environment' do
|
212
|
+
|
213
|
+
it 'should return the production cert for the app' do
|
214
|
+
app = AppFactory.create
|
215
|
+
RAILS_ENV = 'production'
|
216
|
+
app.cert.should == app.apn_prod_cert
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
describe 'cert for development and staging environment' do
|
222
|
+
|
223
|
+
it 'should return the development cert for the app' do
|
224
|
+
app = AppFactory.create
|
225
|
+
RAILS_ENV = 'staging'
|
226
|
+
app.cert.should == app.apn_dev_cert
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
|
2
|
+
|
3
|
+
describe APN::Device do
|
4
|
+
|
5
|
+
describe 'token' do
|
6
|
+
|
7
|
+
it 'should be unique' do
|
8
|
+
device = DeviceFactory.new(:token => APN::Device.first.token)
|
9
|
+
device.should_not be_valid
|
10
|
+
device.errors['token'].should include('has already been taken')
|
11
|
+
|
12
|
+
device = DeviceFactory.new(:token => device.token.succ)
|
13
|
+
device.should be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should get cleansed if it contains brackets' do
|
17
|
+
token = DeviceFactory.random_token
|
18
|
+
device = DeviceFactory.new(:token => "<#{token}>")
|
19
|
+
device.token.should == token
|
20
|
+
device.token.should_not == "<#{token}>"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be in the correct pattern' do
|
24
|
+
device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
|
25
|
+
device.should be_valid
|
26
|
+
device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6'
|
27
|
+
device.should_not be_valid
|
28
|
+
device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7!!'
|
29
|
+
device.should_not be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'to_hexa' do
|
35
|
+
|
36
|
+
it 'should convert the text string to hexadecimal' do
|
37
|
+
device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
|
38
|
+
device.to_hexa.should == fixture_value('hexa.bin')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'before_create' do
|
44
|
+
|
45
|
+
it 'should set the last_registered_at date to Time.now' do
|
46
|
+
time = Time.now
|
47
|
+
Time.stub(:now).and_return(time)
|
48
|
+
device = DeviceFactory.create
|
49
|
+
device.last_registered_at.should_not be_nil
|
50
|
+
device.last_registered_at.to_s.should == time.to_s
|
51
|
+
|
52
|
+
# ago = 1.week.ago
|
53
|
+
# device = DeviceFactory.create(:last_registered_at => ago)
|
54
|
+
# device.last_registered_at.should_not be_nil
|
55
|
+
# device.last_registered_at.to_s.should == ago.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|