rapns 1.0.7 → 2.0.0rc1

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.
Files changed (39) hide show
  1. data/CHANGELOG.md +7 -0
  2. data/LICENSE +7 -0
  3. data/README.md +58 -41
  4. data/bin/rapns +23 -5
  5. data/lib/generators/rapns_generator.rb +2 -4
  6. data/lib/generators/templates/add_app_to_rapns.rb +11 -0
  7. data/lib/generators/templates/create_rapns_apps.rb +15 -0
  8. data/lib/rapns/app.rb +9 -0
  9. data/lib/rapns/daemon/app_runner.rb +131 -0
  10. data/lib/rapns/daemon/connection.rb +5 -3
  11. data/lib/rapns/daemon/delivery_handler.rb +13 -15
  12. data/lib/rapns/daemon/delivery_handler_pool.rb +8 -10
  13. data/lib/rapns/daemon/delivery_queue.rb +36 -4
  14. data/lib/rapns/daemon/feedback_receiver.rb +19 -12
  15. data/lib/rapns/daemon/feeder.rb +8 -10
  16. data/lib/rapns/daemon/logger.rb +5 -3
  17. data/lib/rapns/daemon.rb +52 -38
  18. data/lib/rapns/notification.rb +16 -5
  19. data/lib/rapns/patches.rb +2 -2
  20. data/lib/rapns/version.rb +1 -1
  21. data/lib/rapns.rb +2 -1
  22. data/spec/rapns/daemon/app_runner_spec.rb +207 -0
  23. data/spec/rapns/daemon/connection_spec.rb +177 -236
  24. data/spec/rapns/daemon/delivery_handler_pool_spec.rb +10 -14
  25. data/spec/rapns/daemon/delivery_handler_spec.rb +92 -79
  26. data/spec/rapns/daemon/feedback_receiver_spec.rb +29 -23
  27. data/spec/rapns/daemon/feeder_spec.rb +40 -44
  28. data/spec/rapns/daemon/logger_spec.rb +21 -3
  29. data/spec/rapns/daemon_spec.rb +65 -125
  30. data/spec/rapns/notification_spec.rb +16 -0
  31. data/spec/spec_helper.rb +4 -1
  32. metadata +14 -15
  33. data/History.md +0 -5
  34. data/lib/generators/templates/rapns.yml +0 -31
  35. data/lib/rapns/daemon/certificate.rb +0 -27
  36. data/lib/rapns/daemon/configuration.rb +0 -98
  37. data/lib/rapns/daemon/pool.rb +0 -36
  38. data/spec/rapns/daemon/certificate_spec.rb +0 -22
  39. data/spec/rapns/daemon/configuration_spec.rb +0 -231
@@ -1,182 +1,122 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Rapns::Daemon, "when starting" do
4
- module Rails
5
- end
6
-
7
- let(:config) do
8
- {
9
- "airbrake_notify" => true,
10
- "certificate" => "development.pem",
11
- "certificate_password" => "abc123",
12
- "pid_file" => "rapns.pid",
13
- "push" => {
14
- "port" => 123,
15
- "host" => "localhost",
16
- "poll" => 4,
17
- "connections" => 3
18
- },
19
- "feedback" => {
20
- "port" => 123,
21
- "host" => "localhost",
22
- "poll" => 30,
23
- }
24
- }
25
- end
26
-
27
- before do
28
- Rails.stub(:root).and_return("/rails_root")
29
-
30
- @configuration = Rapns::Daemon::Configuration.new("development", "/rails_root/config/rapns/rapns.yml")
31
- @configuration.stub(:read_config).and_return({"development" => config})
32
- Rapns::Daemon::Configuration.stub(:new).and_return(@configuration)
4
+ module Rails; end
33
5
 
34
- @certificate = Rapns::Daemon::Certificate.new("/rails_root/config/rapns/development.pem")
35
- @certificate.stub(:read_certificate).and_return("certificate contents")
36
- Rapns::Daemon::Certificate.stub(:new).and_return(@certificate)
6
+ let(:certificate) { stub }
7
+ let(:password) { stub }
8
+ let(:config) { stub(:pid_file => nil, :push_poll => 2, :airbrake_notify => false, :foreground => true) }
9
+ let(:logger) { stub(:info => nil, :error => nil) }
37
10
 
38
- @handler_pool = Rapns::Daemon::DeliveryHandlerPool.new(3)
39
- @handler_pool.stub(:populate)
40
- Rapns::Daemon::DeliveryHandlerPool.stub(:new).and_return(@handler_pool)
41
-
42
- Rapns::Daemon::FeedbackReceiver.stub(:start)
11
+ before do
43
12
  Rapns::Daemon::Feeder.stub(:start)
44
- Rapns::Daemon.stub(:daemonize)
13
+ Rapns::Daemon::Logger.stub(:new).and_return(logger)
14
+ Rapns::Daemon::AppRunner.stub(:sync => nil, :stop => nil)
15
+ Rapns::Daemon.stub(:daemonize => nil, :reconnect_database => nil, :exit => nil, :puts => nil)
45
16
  File.stub(:open)
46
- @logger = mock("Logger", :info => nil, :error => nil)
47
- Rapns::Daemon::Logger.stub(:new).and_return(@logger)
48
- end
49
-
50
- it "should load the configuration" do
51
- Rapns::Daemon::Configuration.should_receive(:new).with("development", "/rails_root/config/rapns/rapns.yml").and_return(@configuration)
52
- @configuration.load
53
- @configuration.should_receive(:load)
54
- Rapns::Daemon.start("development", {})
55
- end
56
-
57
- it "should make the configuration accessible" do
58
- Rapns::Daemon.start("development", {})
59
- Rapns::Daemon.configuration.should == @configuration
60
- end
61
-
62
- it "should load the certificate" do
63
- Rapns::Daemon::Certificate.should_receive(:new).with("/rails_root/config/rapns/development.pem").and_return(@certificate)
64
- @certificate.should_receive(:load)
65
- Rapns::Daemon.start("development", {})
66
- end
67
-
68
- it "should make the certificate accessible" do
69
- Rapns::Daemon.start("development", {})
70
- Rapns::Daemon.certificate.should == @certificate
17
+ Rails.stub(:root).and_return("/rails_root")
71
18
  end
72
19
 
73
- it "should initialize the delivery queue" do
74
- Rapns::Daemon::DeliveryQueue.should_receive(:new)
75
- Rapns::Daemon.start("development", {})
20
+ it "forks into a daemon if the foreground option is false" do
21
+ config.stub(:foreground => false)
22
+ ActiveRecord::Base.stub(:establish_connection)
23
+ Rapns::Daemon.should_receive(:daemonize)
24
+ Rapns::Daemon.start("development", config)
76
25
  end
77
26
 
78
- it "should populate the delivery handler pool" do
79
- Rapns::Daemon::DeliveryHandlerPool.should_receive(:new).with(3).and_return(@handler_pool)
80
- @handler_pool.should_receive(:populate)
81
- Rapns::Daemon.start("development", {})
27
+ it "does not fork into a daemon if the foreground option is true" do
28
+ config.stub(:foreground => true)
29
+ Rapns::Daemon.should_not_receive(:daemonize)
30
+ Rapns::Daemon.start("development", config)
82
31
  end
83
32
 
84
- it "should make the delivery handler pool accessible" do
85
- Rapns::Daemon.start("development", {})
86
- Rapns::Daemon.delivery_handler_pool.should == @handler_pool
33
+ it "writes the process ID to the PID file" do
34
+ Rapns::Daemon.should_receive(:write_pid_file)
35
+ Rapns::Daemon.start("development", config)
87
36
  end
88
37
 
89
- it "should fork a child process if the foreground option is false" do
90
- ActiveRecord::Base.stub(:establish_connection)
91
- Rapns::Daemon.should_receive(:daemonize)
92
- Rapns::Daemon.start("development", false)
38
+ it "logs an error if the PID file could not be written" do
39
+ config.stub(:pid_file => '/rails_root/rapns.pid')
40
+ File.stub(:open).and_raise(Errno::ENOENT)
41
+ logger.should_receive(:error).with("Failed to write PID to '/rails_root/rapns.pid': #<Errno::ENOENT: No such file or directory>")
42
+ Rapns::Daemon.start("development", config)
93
43
  end
94
44
 
95
- it "should not fork a child process if the foreground option is true" do
96
- Rapns::Daemon.should_not_receive(:daemonize)
97
- Rapns::Daemon.start("development", true)
45
+ it "starts the feeder" do
46
+ Rapns::Daemon::Feeder.should_receive(:start).with(2)
47
+ Rapns::Daemon.start("development", config)
98
48
  end
99
49
 
100
- it "should write the process ID to the PID file" do
101
- Rapns::Daemon.should_receive(:write_pid_file)
102
- Rapns::Daemon.start("development", {})
50
+ it "syncs apps" do
51
+ Rapns::Daemon::AppRunner.should_receive(:sync)
52
+ Rapns::Daemon.start("development", config)
103
53
  end
104
54
 
105
- it "should log an error if the PID file could not be written" do
106
- File.stub(:open).and_raise(Errno::ENOENT)
107
- @logger.should_receive(:error).with("Failed to write PID to '/rails_root/rapns.pid': #<Errno::ENOENT: No such file or directory>")
108
- Rapns::Daemon.start("development", {})
55
+ it "sets up the logger" do
56
+ config.stub(:airbrake_notify => true)
57
+ Rapns::Daemon::Logger.should_receive(:new).with(:foreground => true, :airbrake_notify => true)
58
+ Rapns::Daemon.start("development", config)
109
59
  end
110
60
 
111
- it "should start the feedback receiver" do
112
- Rapns::Daemon::FeedbackReceiver.should_receive(:start)
113
- Rapns::Daemon.start("development", true)
61
+ it "makes the logger accessible" do
62
+ Rapns::Daemon.start("development", config)
63
+ Rapns::Daemon.logger.should == logger
114
64
  end
115
65
 
116
- it "should start the feeder" do
117
- Rapns::Daemon::Feeder.should_receive(:start)
118
- Rapns::Daemon.start("development", true)
66
+ it 'prints a warning if there are no apps' do
67
+ Rapns::App.stub(:count => 0)
68
+ Rapns::Daemon.should_receive(:puts).any_number_of_times
69
+ Rapns::Daemon.should_receive(:exit).with(1)
70
+ Rapns::Daemon.start("development", config)
119
71
  end
120
72
 
121
- it "should setup the logger" do
122
- Rapns::Daemon::Logger.should_receive(:new).with(:foreground => true, :airbrake_notify => true).and_return(@logger)
123
- Rapns::Daemon.start("development", true)
73
+ it 'prints a warning exists if rapns has not been upgraded' do
74
+ Rapns::App.stub(:count).and_raise(ActiveRecord::StatementInvalid)
75
+ Rapns::Daemon.should_receive(:puts).any_number_of_times
76
+ Rapns::Daemon.should_receive(:exit).with(1)
77
+ Rapns::Daemon.start("development", config)
124
78
  end
125
79
 
126
- it "should make the logger accessible" do
127
- Rapns::Daemon::Logger.stub(:new).and_return(@logger)
128
- Rapns::Daemon.start("development", true)
129
- Rapns::Daemon.logger.should == @logger
80
+ it 'warns if rapns.yml still exists' do
81
+ File.should_receive(:exists?).with('/rails_root/config/rapns/rapns.yml').and_return(true)
82
+ logger.should_receive(:warn).with("Since 2.0.0 rapns uses command-line options instead of a configuration file. Please remove config/rapns/rapns.yml.")
83
+ Rapns::Daemon.start("development", config)
130
84
  end
131
85
  end
132
86
 
133
87
  describe Rapns::Daemon, "when being shutdown" do
88
+ let(:config) { stub(:pid_file => '/rails_root/rapns.pid') }
89
+
134
90
  before do
135
- Rails.stub(:root).and_return("/rails_root")
91
+ Rapns::Daemon.stub(:config => config, :puts => nil)
136
92
  Rapns::Daemon::Feeder.stub(:stop)
137
- Rapns::Daemon::FeedbackReceiver.stub(:stop)
138
- @handler_pool = mock("DeliveryHandlerPool", :drain => nil)
139
- Rapns::Daemon.stub(:delivery_handler_pool).and_return(@handler_pool)
140
- @configuration = mock("Configuration", :pid_file => File.join(Rails.root, "rapns.pid"))
141
- Rapns::Daemon.stub(:configuration).and_return(@configuration)
142
- Rapns::Daemon.stub(:puts)
143
- end
144
-
145
- it "should stop the feedback receiver" do
146
- Rapns::Daemon::FeedbackReceiver.should_receive(:stop)
147
- Rapns::Daemon.send(:shutdown)
93
+ Rapns::Daemon::AppRunner.stub(:stop)
148
94
  end
149
95
 
150
- it "should stop the feeder" do
96
+ it "stops the feeder" do
151
97
  Rapns::Daemon::Feeder.should_receive(:stop)
152
98
  Rapns::Daemon.send(:shutdown)
153
99
  end
154
100
 
155
- it "should drain the delivery handler pool" do
156
- @handler_pool.should_receive(:drain)
157
- Rapns::Daemon.send(:shutdown)
158
- end
159
-
160
- it "should not attempt to drain the delivery handler pool if it has not been initialized" do
161
- Rapns::Daemon.stub(:delivery_handler_pool).and_return(nil)
162
- @handler_pool.should_not_receive(:drain)
101
+ it "stops the app runners" do
102
+ Rapns::Daemon::AppRunner.should_receive(:stop)
163
103
  Rapns::Daemon.send(:shutdown)
164
104
  end
165
105
 
166
- it "should remove the PID file if one was written" do
106
+ it "removes the PID file if one was written" do
167
107
  File.stub(:exists?).and_return(true)
168
108
  File.should_receive(:delete).with("/rails_root/rapns.pid")
169
109
  Rapns::Daemon.send(:shutdown)
170
110
  end
171
111
 
172
- it "should not attempt to remove the PID file if it does not exist" do
112
+ it "does not attempt to remove the PID file if it does not exist" do
173
113
  File.stub(:exists?).and_return(false)
174
114
  File.should_not_receive(:delete)
175
115
  Rapns::Daemon.send(:shutdown)
176
116
  end
177
117
 
178
- it "should not remove the PID file if one was not written" do
179
- @configuration.stub(:pid_file).and_return(nil)
118
+ it "does not attempt to remove the PID file if one was not written" do
119
+ config.stub(:pid_file).and_return(nil)
180
120
  File.should_not_receive(:delete)
181
121
  Rapns::Daemon.send(:shutdown)
182
122
  end
@@ -101,6 +101,22 @@ describe Rapns::Notification, "as_json" do
101
101
  end
102
102
  end
103
103
 
104
+ describe Rapns::Notification, 'MDM' do
105
+ let(:magic) { 'abc123' }
106
+ let(:notification) { Rapns::Notification.new }
107
+
108
+ it 'includes the mdm magic in the payload' do
109
+ notification.mdm = magic
110
+ notification.as_json.should == {'mdm' => magic}
111
+ end
112
+
113
+ it 'does not include aps attribute' do
114
+ notification.alert = "i'm doomed"
115
+ notification.mdm = magic
116
+ notification.as_json.key?('aps').should be_false
117
+ end
118
+ end
119
+
104
120
  describe Rapns::Notification, "to_binary" do
105
121
  it "should correctly convert the notification to binary" do
106
122
  notification = Rapns::Notification.new
data/spec/spec_helper.rb CHANGED
@@ -24,8 +24,11 @@ ActiveRecord::Base.establish_connection('adapter' => $adapter, 'database' => 'ra
24
24
  require 'generators/templates/create_rapns_notifications'
25
25
  require 'generators/templates/create_rapns_feedback'
26
26
  require 'generators/templates/add_alert_is_json_to_rapns_notifications'
27
+ require 'generators/templates/add_app_to_rapns'
28
+ require 'generators/templates/create_rapns_apps'
27
29
 
28
- [CreateRapnsNotifications, CreateRapnsFeedback, AddAlertIsJsonToRapnsNotifications].each do |migration|
30
+ [CreateRapnsNotifications, CreateRapnsFeedback,
31
+ AddAlertIsJsonToRapnsNotifications, AddAppToRapns, CreateRapnsApps].each do |migration|
29
32
  migration.down rescue ActiveRecord::StatementInvalid
30
33
  migration.up
31
34
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
5
- prerelease:
4
+ version: 2.0.0rc1
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ian Leitch
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-22 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Easy to use library for Apple's Push Notification Service with Rails
15
15
  3
@@ -22,14 +22,15 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - lib/generators/rapns_generator.rb
24
24
  - lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb
25
+ - lib/generators/templates/add_app_to_rapns.rb
26
+ - lib/generators/templates/create_rapns_apps.rb
25
27
  - lib/generators/templates/create_rapns_feedback.rb
26
28
  - lib/generators/templates/create_rapns_notifications.rb
27
- - lib/generators/templates/rapns.yml
28
29
  - lib/rapns.rb
30
+ - lib/rapns/app.rb
29
31
  - lib/rapns/binary_notification_validator.rb
30
32
  - lib/rapns/daemon.rb
31
- - lib/rapns/daemon/certificate.rb
32
- - lib/rapns/daemon/configuration.rb
33
+ - lib/rapns/daemon/app_runner.rb
33
34
  - lib/rapns/daemon/connection.rb
34
35
  - lib/rapns/daemon/database_reconnectable.rb
35
36
  - lib/rapns/daemon/delivery_error.rb
@@ -41,7 +42,6 @@ files:
41
42
  - lib/rapns/daemon/feeder.rb
42
43
  - lib/rapns/daemon/interruptible_sleep.rb
43
44
  - lib/rapns/daemon/logger.rb
44
- - lib/rapns/daemon/pool.rb
45
45
  - lib/rapns/device_token_format_validator.rb
46
46
  - lib/rapns/feedback.rb
47
47
  - lib/rapns/notification.rb
@@ -50,9 +50,9 @@ files:
50
50
  - lib/rapns/patches/rails/3.1.1/postgresql_adapter.rb
51
51
  - lib/rapns/version.rb
52
52
  - README.md
53
- - History.md
54
- - spec/rapns/daemon/certificate_spec.rb
55
- - spec/rapns/daemon/configuration_spec.rb
53
+ - CHANGELOG.md
54
+ - LICENSE
55
+ - spec/rapns/daemon/app_runner_spec.rb
56
56
  - spec/rapns/daemon/connection_spec.rb
57
57
  - spec/rapns/daemon/database_reconnectable_spec.rb
58
58
  - spec/rapns/daemon/delivery_error_spec.rb
@@ -83,18 +83,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
- - - ! '>='
86
+ - - ! '>'
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: 1.3.1
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 1.8.17
91
+ rubygems_version: 1.8.23
92
92
  signing_key:
93
93
  specification_version: 3
94
94
  summary: Easy to use library for Apple's Push Notification Service with Rails 3
95
95
  test_files:
96
- - spec/rapns/daemon/certificate_spec.rb
97
- - spec/rapns/daemon/configuration_spec.rb
96
+ - spec/rapns/daemon/app_runner_spec.rb
98
97
  - spec/rapns/daemon/connection_spec.rb
99
98
  - spec/rapns/daemon/database_reconnectable_spec.rb
100
99
  - spec/rapns/daemon/delivery_error_spec.rb
data/History.md DELETED
@@ -1,5 +0,0 @@
1
-
2
- 1.0.7 / 2012-04-22
3
- ==================
4
-
5
- * Reconnect if the connnection has been idle for more than 30 minutes. TCP Keepalive alone is not enough to ensure the connection is still connected.
@@ -1,31 +0,0 @@
1
- development:
2
- certificate: development.pem
3
- certificate_password:
4
-
5
- push:
6
- host: gateway.sandbox.push.apple.com
7
- port: 2195
8
- poll: 2
9
- connections: 3
10
-
11
- feedback:
12
- host: feedback.sandbox.push.apple.com
13
- port: 2196
14
- poll: 60
15
-
16
- production:
17
- certificate: production.pem
18
- certificate_password:
19
- airbrake_notify: true
20
- pid_file: tmp/pids/rapns.pid
21
-
22
- push:
23
- host: gateway.push.apple.com
24
- port: 2195
25
- poll: 2
26
- connections: 3
27
-
28
- feedback:
29
- host: feedback.push.apple.com
30
- port: 2196
31
- poll: 60
@@ -1,27 +0,0 @@
1
- module Rapns
2
- class CertificateError < StandardError; end
3
-
4
- module Daemon
5
- class Certificate
6
- attr_accessor :certificate
7
-
8
- def initialize(certificate_path)
9
- @certificate_path = certificate_path
10
- end
11
-
12
- def load
13
- @certificate = read_certificate
14
- end
15
-
16
- protected
17
-
18
- def read_certificate
19
- if !File.exists?(@certificate_path)
20
- raise CertificateError, "#{@certificate_path} does not exist. The certificate location can be configured in config/rapns/rapns.yml."
21
- else
22
- File.read(@certificate_path)
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,98 +0,0 @@
1
- require "yaml"
2
-
3
- module Rapns
4
- class ConfigurationError < StandardError; end
5
-
6
- module Daemon
7
- class Configuration
8
- attr_accessor :push, :feedback
9
- attr_accessor :certificate, :certificate_password, :airbrake_notify, :pid_file
10
- alias_method :airbrake_notify?, :airbrake_notify
11
-
12
- def initialize(environment, config_path)
13
- @environment = environment
14
- @config_path = config_path
15
-
16
- self.push = Struct.new(:host, :port, :connections, :poll).new
17
- self.feedback = Struct.new(:host, :port, :poll).new
18
- end
19
-
20
- def load
21
- config = read_config
22
- ensure_environment_configured(config)
23
- config = config[@environment]
24
- set_variable(:push, :host, config)
25
- set_variable(:push, :port, config)
26
- set_variable(:push, :poll, config, :optional => true, :default => 2)
27
- set_variable(:push, :connections, config, :optional => true, :default => 3)
28
-
29
- set_variable(:feedback, :host, config)
30
- set_variable(:feedback, :port, config)
31
- set_variable(:feedback, :poll, config, :optional => true, :default => 60)
32
-
33
- set_variable(nil, :certificate, config)
34
- set_variable(nil, :airbrake_notify, config, :optional => true, :default => true)
35
- set_variable(nil, :certificate_password, config, :optional => true, :default => "")
36
- set_variable(nil, :pid_file, config, :optional => true, :default => "")
37
- end
38
-
39
- def certificate
40
- if Pathname.new(@certificate).absolute?
41
- @certificate
42
- else
43
- File.join(Rails.root, "config", "rapns", @certificate)
44
- end
45
- end
46
-
47
- def pid_file
48
- return if @pid_file.blank?
49
-
50
- if Pathname.new(@pid_file).absolute?
51
- @pid_file
52
- else
53
- File.join(Rails.root, @pid_file)
54
- end
55
- end
56
-
57
- protected
58
-
59
- def read_config
60
- ensure_config_exists
61
- File.open(@config_path) { |fd| YAML.load(fd) }
62
- end
63
-
64
- def set_variable(base_key, key, config, options = {})
65
- if base_key
66
- base = send(base_key)
67
- value = config.key?(base_key.to_s) ? config[base_key.to_s][key.to_s] : nil
68
- else
69
- base = self
70
- value = config[key.to_s]
71
- end
72
-
73
- if value.to_s.strip == ""
74
- if options[:optional]
75
- base.send("#{key}=", options[:default])
76
- else
77
- key_path = base_key ? "#{base_key}.#{key}" : key
78
- raise Rapns::ConfigurationError, "'#{key_path}' not defined for environment '#{@environment}' in #{@config_path}. You may need to run 'rails g rapns' after updating."
79
- end
80
- else
81
- base.send("#{key}=", value)
82
- end
83
- end
84
-
85
- def ensure_config_exists
86
- if !File.exists?(@config_path)
87
- raise Rapns::ConfigurationError, "#{@config_path} does not exist. Have you run 'rails g rapns'?"
88
- end
89
- end
90
-
91
- def ensure_environment_configured(config)
92
- if !config.key?(@environment)
93
- raise Rapns::ConfigurationError, "Configuration for environment '#{@environment}' not defined in #{@config_path}"
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,36 +0,0 @@
1
- module Rapns
2
- module Daemon
3
- class Pool
4
- def initialize(num_objects)
5
- @num_objects = num_objects
6
- @queue = Queue.new
7
- end
8
-
9
- def populate
10
- @num_objects.times do |i|
11
- object = new_object_for_pool(i)
12
- @queue.push(object)
13
- object_added_to_pool(object)
14
- end
15
- end
16
-
17
- def drain
18
- while !@queue.empty?
19
- object = @queue.pop
20
- object_removed_from_pool(object)
21
- end
22
- end
23
-
24
- protected
25
-
26
- def new_object_for_pool(i)
27
- end
28
-
29
- def object_added_to_pool(object)
30
- end
31
-
32
- def object_removed_from_pool(object)
33
- end
34
- end
35
- end
36
- end
@@ -1,22 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Rapns::Daemon::Certificate do
4
- it 'reads the certificate from the given path' do
5
- File.stub(:exists? => true)
6
- File.should_receive(:read).with("/dir/development.pem")
7
- cert = Rapns::Daemon::Certificate.new("/dir/development.pem")
8
- cert.load
9
- end
10
-
11
- it "should raise an error if the .pem file does not exist" do
12
- cert = Rapns::Daemon::Certificate.new("/tmp/rapns-missing.pem")
13
- expect { cert.load }.to raise_error(Rapns::CertificateError, "/tmp/rapns-missing.pem does not exist. The certificate location can be configured in config/rapns/rapns.yml.")
14
- end
15
-
16
- it "should set the certificate accessor" do
17
- cert = Rapns::Daemon::Certificate.new("/dir/development.pem")
18
- cert.stub(:read_certificate).and_return("certificate contents")
19
- cert.load
20
- cert.certificate.should == "certificate contents"
21
- end
22
- end