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.
- data/CHANGELOG.md +7 -0
- data/LICENSE +7 -0
- data/README.md +58 -41
- data/bin/rapns +23 -5
- data/lib/generators/rapns_generator.rb +2 -4
- data/lib/generators/templates/add_app_to_rapns.rb +11 -0
- data/lib/generators/templates/create_rapns_apps.rb +15 -0
- data/lib/rapns/app.rb +9 -0
- data/lib/rapns/daemon/app_runner.rb +131 -0
- data/lib/rapns/daemon/connection.rb +5 -3
- data/lib/rapns/daemon/delivery_handler.rb +13 -15
- data/lib/rapns/daemon/delivery_handler_pool.rb +8 -10
- data/lib/rapns/daemon/delivery_queue.rb +36 -4
- data/lib/rapns/daemon/feedback_receiver.rb +19 -12
- data/lib/rapns/daemon/feeder.rb +8 -10
- data/lib/rapns/daemon/logger.rb +5 -3
- data/lib/rapns/daemon.rb +52 -38
- data/lib/rapns/notification.rb +16 -5
- data/lib/rapns/patches.rb +2 -2
- data/lib/rapns/version.rb +1 -1
- data/lib/rapns.rb +2 -1
- data/spec/rapns/daemon/app_runner_spec.rb +207 -0
- data/spec/rapns/daemon/connection_spec.rb +177 -236
- data/spec/rapns/daemon/delivery_handler_pool_spec.rb +10 -14
- data/spec/rapns/daemon/delivery_handler_spec.rb +92 -79
- data/spec/rapns/daemon/feedback_receiver_spec.rb +29 -23
- data/spec/rapns/daemon/feeder_spec.rb +40 -44
- data/spec/rapns/daemon/logger_spec.rb +21 -3
- data/spec/rapns/daemon_spec.rb +65 -125
- data/spec/rapns/notification_spec.rb +16 -0
- data/spec/spec_helper.rb +4 -1
- metadata +14 -15
- data/History.md +0 -5
- data/lib/generators/templates/rapns.yml +0 -31
- data/lib/rapns/daemon/certificate.rb +0 -27
- data/lib/rapns/daemon/configuration.rb +0 -98
- data/lib/rapns/daemon/pool.rb +0 -36
- data/spec/rapns/daemon/certificate_spec.rb +0 -22
- data/spec/rapns/daemon/configuration_spec.rb +0 -231
@@ -1,231 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Rapns::Daemon::Configuration do
|
4
|
-
module Rails
|
5
|
-
end
|
6
|
-
|
7
|
-
let(:config) do
|
8
|
-
{
|
9
|
-
"airbrake_notify" => false,
|
10
|
-
"certificate" => "production.pem",
|
11
|
-
"certificate_password" => "abc123",
|
12
|
-
"pid_file" => "rapns.pid",
|
13
|
-
"push" => {
|
14
|
-
"port" => 123,
|
15
|
-
"host" => "localhost",
|
16
|
-
"poll" => 4,
|
17
|
-
"connections" => 6
|
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
|
-
end
|
30
|
-
|
31
|
-
it 'opens the config from the given path' do
|
32
|
-
YAML.stub(:load => {"production" => config})
|
33
|
-
fd = stub(:read => nil)
|
34
|
-
File.should_receive(:open).with("/tmp/rapns-non-existant-file").and_yield(fd)
|
35
|
-
config = Rapns::Daemon::Configuration.new("production", "/tmp/rapns-non-existant-file")
|
36
|
-
config.stub(:ensure_config_exists)
|
37
|
-
config.load
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'reads the config as YAML' do
|
41
|
-
YAML.should_receive(:load).and_return({"production" => config})
|
42
|
-
fd = stub(:read => nil)
|
43
|
-
File.stub(:open).and_yield(fd)
|
44
|
-
config = Rapns::Daemon::Configuration.new("production", "/tmp/rapns-non-existant-file")
|
45
|
-
config.stub(:ensure_config_exists)
|
46
|
-
config.load
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should raise an error if the configuration file does not exist" do
|
50
|
-
expect { Rapns::Daemon::Configuration.new("production", "/tmp/rapns-non-existant-file").load }.to raise_error(Rapns::ConfigurationError, "/tmp/rapns-non-existant-file does not exist. Have you run 'rails g rapns'?")
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should raise an error if the environment is not configured" do
|
54
|
-
configuration = Rapns::Daemon::Configuration.new("development", "/some/config.yml")
|
55
|
-
configuration.stub(:read_config).and_return({"production" => {}})
|
56
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "Configuration for environment 'development' not defined in /some/config.yml")
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should raise an error if the push host is not configured" do
|
60
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
61
|
-
config["push"]["host"] = nil
|
62
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
63
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "'push.host' not defined for environment 'production' in /some/config.yml. You may need to run 'rails g rapns' after updating.")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should raise an error if the push port is not configured" do
|
67
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
68
|
-
config["push"]["port"] = nil
|
69
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
70
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "'push.port' not defined for environment 'production' in /some/config.yml. You may need to run 'rails g rapns' after updating.")
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should raise an error if the feedback host is not configured" do
|
74
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
75
|
-
config["feedback"]["host"] = nil
|
76
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
77
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "'feedback.host' not defined for environment 'production' in /some/config.yml. You may need to run 'rails g rapns' after updating.")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should raise an error if the feedback port is not configured" do
|
81
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
82
|
-
config["feedback"]["port"] = nil
|
83
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
84
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "'feedback.port' not defined for environment 'production' in /some/config.yml. You may need to run 'rails g rapns' after updating.")
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should raise an error if the certificate is not configured" do
|
88
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
89
|
-
configuration.stub(:read_config).and_return({"production" => config.except("certificate")})
|
90
|
-
expect { configuration.load }.to raise_error(Rapns::ConfigurationError, "'certificate' not defined for environment 'production' in /some/config.yml. You may need to run 'rails g rapns' after updating.")
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should set the push host" do
|
94
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
95
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
96
|
-
configuration.load
|
97
|
-
configuration.push.host.should == "localhost"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should set the push port" do
|
101
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
102
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
103
|
-
configuration.load
|
104
|
-
configuration.push.port.should == 123
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should set the feedback port" do
|
108
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
109
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
110
|
-
configuration.load
|
111
|
-
configuration.feedback.port.should == 123
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should set the feedback host" do
|
115
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
116
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
117
|
-
configuration.load
|
118
|
-
configuration.feedback.host.should == "localhost"
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should set the airbrake notify flag" do
|
122
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
123
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
124
|
-
configuration.load
|
125
|
-
configuration.airbrake_notify?.should == false
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should default the airbrake notify flag to true if not set" do
|
129
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
130
|
-
configuration.stub(:read_config).and_return({"production" => config.except("airbrake_notify")})
|
131
|
-
configuration.load
|
132
|
-
configuration.airbrake_notify?.should == true
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should set the push poll frequency" do
|
136
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
137
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
138
|
-
configuration.load
|
139
|
-
configuration.push.poll.should == 4
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should set the feedback poll frequency" do
|
143
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
144
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
145
|
-
configuration.load
|
146
|
-
configuration.feedback.poll.should == 30
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should default the push poll frequency to 2 if not set" do
|
150
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
151
|
-
config["push"]["poll"] = nil
|
152
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
153
|
-
configuration.load
|
154
|
-
configuration.push.poll.should == 2
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should default the feedback poll frequency to 60 if not set" do
|
158
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
159
|
-
config["feedback"]["poll"] = nil
|
160
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
161
|
-
configuration.load
|
162
|
-
configuration.feedback.poll.should == 60
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should set the number of push connections" do
|
166
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
167
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
168
|
-
configuration.load
|
169
|
-
configuration.push.connections.should == 6
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should default the number of push connections to 3 if not set" do
|
173
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
174
|
-
config["push"]["connections"] = nil
|
175
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
176
|
-
configuration.load
|
177
|
-
configuration.push.connections.should == 3
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should set the certificate password" do
|
181
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
182
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
183
|
-
configuration.load
|
184
|
-
configuration.certificate_password.should == "abc123"
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should set the certificate password to a blank string if it is not configured" do
|
188
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
189
|
-
configuration.stub(:read_config).and_return({"production" => config.except("certificate_password")})
|
190
|
-
configuration.load
|
191
|
-
configuration.certificate_password.should == ""
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should set the certificate, with absolute path" do
|
195
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
196
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
197
|
-
configuration.load
|
198
|
-
configuration.certificate.should == "/rails_root/config/rapns/production.pem"
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should keep the absolute path of the certificate if it has one" do
|
202
|
-
config["certificate"] = "/different_path/to/production.pem"
|
203
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
204
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
205
|
-
configuration.load
|
206
|
-
configuration.certificate.should == "/different_path/to/production.pem"
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should set the PID file path" do
|
210
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
211
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
212
|
-
configuration.load
|
213
|
-
configuration.pid_file.should == "/rails_root/rapns.pid"
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should keep the absolute path of the PID file if it has one" do
|
217
|
-
config["pid_file"] = "/some/absolue/path/rapns.pid"
|
218
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
219
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
220
|
-
configuration.load
|
221
|
-
configuration.pid_file.should == "/some/absolue/path/rapns.pid"
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should return nil if no PID file was set" do
|
225
|
-
config["pid_file"] = ""
|
226
|
-
configuration = Rapns::Daemon::Configuration.new("production", "/some/config.yml")
|
227
|
-
configuration.stub(:read_config).and_return({"production" => config})
|
228
|
-
configuration.load
|
229
|
-
configuration.pid_file.should be_nil
|
230
|
-
end
|
231
|
-
end
|