backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +46 -0
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +27 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +46 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +43 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +277 -0
@@ -0,0 +1,316 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Notifier::Mail do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:notifier) do
|
8
|
+
Backup::Notifier::Mail.new(model) do |mail|
|
9
|
+
mail.delivery_method = :smtp
|
10
|
+
mail.from = 'my.sender.email@gmail.com'
|
11
|
+
mail.to = 'my.receiver.email@gmail.com'
|
12
|
+
mail.address = 'smtp.gmail.com'
|
13
|
+
mail.port = 587
|
14
|
+
mail.domain = 'your.host.name'
|
15
|
+
mail.user_name = 'user'
|
16
|
+
mail.password = 'secret'
|
17
|
+
mail.authentication = 'plain'
|
18
|
+
mail.enable_starttls_auto = true
|
19
|
+
|
20
|
+
mail.sendmail = '/path/to/sendmail'
|
21
|
+
mail.sendmail_args = '-i -t -X/tmp/traffic.log'
|
22
|
+
mail.exim = '/path/to/exim'
|
23
|
+
mail.exim_args = '-i -t -X/tmp/traffic.log'
|
24
|
+
|
25
|
+
mail.mail_folder = '/path/to/backup/mails'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should be a subclass of Notifier::Base' do
|
30
|
+
Backup::Notifier::Mail.
|
31
|
+
superclass.should == Backup::Notifier::Base
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#initialize' do
|
35
|
+
after { Backup::Notifier::Mail.clear_defaults! }
|
36
|
+
|
37
|
+
it 'should load pre-configured defaults through Base' do
|
38
|
+
Backup::Notifier::Mail.any_instance.expects(:load_defaults!)
|
39
|
+
notifier
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should pass the model reference to Base' do
|
43
|
+
notifier.instance_variable_get(:@model).should == model
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when no pre-configured defaults have been set' do
|
47
|
+
it 'should use the values given' do
|
48
|
+
notifier.delivery_method.should == :smtp
|
49
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
50
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
51
|
+
notifier.address.should == 'smtp.gmail.com'
|
52
|
+
notifier.port.should == 587
|
53
|
+
notifier.domain.should == 'your.host.name'
|
54
|
+
notifier.user_name.should == 'user'
|
55
|
+
notifier.password.should == 'secret'
|
56
|
+
notifier.authentication.should == 'plain'
|
57
|
+
notifier.enable_starttls_auto.should == true
|
58
|
+
|
59
|
+
notifier.sendmail.should == '/path/to/sendmail'
|
60
|
+
notifier.sendmail_args.should == '-i -t -X/tmp/traffic.log'
|
61
|
+
notifier.exim.should == '/path/to/exim'
|
62
|
+
notifier.exim_args.should == '-i -t -X/tmp/traffic.log'
|
63
|
+
|
64
|
+
notifier.mail_folder.should == '/path/to/backup/mails'
|
65
|
+
|
66
|
+
notifier.on_success.should == true
|
67
|
+
notifier.on_warning.should == true
|
68
|
+
notifier.on_failure.should == true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should use default values if none are given' do
|
72
|
+
notifier = Backup::Notifier::Mail.new(model)
|
73
|
+
notifier.delivery_method.should be_nil
|
74
|
+
notifier.from.should be_nil
|
75
|
+
notifier.to.should be_nil
|
76
|
+
notifier.address.should be_nil
|
77
|
+
notifier.port.should be_nil
|
78
|
+
notifier.domain.should be_nil
|
79
|
+
notifier.user_name.should be_nil
|
80
|
+
notifier.password.should be_nil
|
81
|
+
notifier.authentication.should be_nil
|
82
|
+
notifier.enable_starttls_auto.should be_nil
|
83
|
+
|
84
|
+
notifier.sendmail.should be_nil
|
85
|
+
notifier.sendmail_args.should be_nil
|
86
|
+
notifier.exim.should be_nil
|
87
|
+
notifier.exim_args.should be_nil
|
88
|
+
|
89
|
+
notifier.mail_folder.should be_nil
|
90
|
+
|
91
|
+
notifier.on_success.should == true
|
92
|
+
notifier.on_warning.should == true
|
93
|
+
notifier.on_failure.should == true
|
94
|
+
end
|
95
|
+
end # context 'when no pre-configured defaults have been set'
|
96
|
+
|
97
|
+
context 'when pre-configured defaults have been set' do
|
98
|
+
before do
|
99
|
+
Backup::Notifier::Mail.defaults do |n|
|
100
|
+
n.delivery_method = :file
|
101
|
+
n.from = 'default.sender@domain.com'
|
102
|
+
n.to = 'some.receiver@domain.com'
|
103
|
+
n.on_success = false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should use pre-configured defaults' do
|
108
|
+
notifier = Backup::Notifier::Mail.new(model)
|
109
|
+
notifier.delivery_method.should == :file
|
110
|
+
notifier.from.should == 'default.sender@domain.com'
|
111
|
+
notifier.to.should == 'some.receiver@domain.com'
|
112
|
+
notifier.address.should be_nil
|
113
|
+
notifier.port.should be_nil
|
114
|
+
notifier.domain.should be_nil
|
115
|
+
notifier.user_name.should be_nil
|
116
|
+
notifier.password.should be_nil
|
117
|
+
notifier.authentication.should be_nil
|
118
|
+
notifier.enable_starttls_auto.should be_nil
|
119
|
+
|
120
|
+
notifier.sendmail.should be_nil
|
121
|
+
notifier.sendmail_args.should be_nil
|
122
|
+
notifier.exim.should be_nil
|
123
|
+
notifier.exim_args.should be_nil
|
124
|
+
|
125
|
+
notifier.mail_folder.should be_nil
|
126
|
+
|
127
|
+
notifier.on_success.should == false
|
128
|
+
notifier.on_warning.should == true
|
129
|
+
notifier.on_failure.should == true
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should override pre-configured defaults' do
|
133
|
+
notifier = Backup::Notifier::Mail.new(model) do |n|
|
134
|
+
n.delivery_method = :sendmail
|
135
|
+
n.from = 'new.sender@domain.com'
|
136
|
+
n.to = 'new.receiver@domain.com'
|
137
|
+
n.port = 123
|
138
|
+
n.on_warning = false
|
139
|
+
end
|
140
|
+
|
141
|
+
notifier.delivery_method.should == :sendmail
|
142
|
+
notifier.from.should == 'new.sender@domain.com'
|
143
|
+
notifier.to.should == 'new.receiver@domain.com'
|
144
|
+
notifier.port.should == 123
|
145
|
+
|
146
|
+
notifier.on_success.should == false
|
147
|
+
notifier.on_warning.should == false
|
148
|
+
notifier.on_failure.should == true
|
149
|
+
end
|
150
|
+
end # context 'when pre-configured defaults have been set'
|
151
|
+
end # describe '#initialize'
|
152
|
+
|
153
|
+
describe '#notify!' do
|
154
|
+
let(:template) { mock }
|
155
|
+
let(:message) { '[Backup::%s] test label (test_trigger)' }
|
156
|
+
|
157
|
+
before do
|
158
|
+
notifier.instance_variable_set(:@template, template)
|
159
|
+
notifier.delivery_method = :test
|
160
|
+
::Mail::TestMailer.deliveries.clear
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when status is :success' do
|
164
|
+
it 'should send a Success email with no attachments' do
|
165
|
+
template.expects(:result).
|
166
|
+
with('notifier/mail/success.erb').
|
167
|
+
returns('message body')
|
168
|
+
|
169
|
+
notifier.send(:notify!, :success)
|
170
|
+
|
171
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
172
|
+
sent_message.subject.should == message % 'Success'
|
173
|
+
sent_message.multipart?.should be_false
|
174
|
+
sent_message.body.should == 'message body'
|
175
|
+
sent_message.has_attachments?.should be_false
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'when status is :warning' do
|
180
|
+
before do
|
181
|
+
Backup::Logger.stubs(:has_warnings?).returns(true)
|
182
|
+
Backup::Logger.stubs(:messages).returns(['line 1', 'line 2', 'line 3'])
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should send a Warning email with an attached log' do
|
186
|
+
template.expects(:result).
|
187
|
+
with('notifier/mail/warning.erb').
|
188
|
+
returns('message body')
|
189
|
+
|
190
|
+
notifier.send(:notify!, :warning)
|
191
|
+
|
192
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
193
|
+
sent_message.subject.should == message % 'Warning'
|
194
|
+
sent_message.body.multipart?.should be_true
|
195
|
+
sent_message.text_part.decoded.should == 'message body'
|
196
|
+
sent_message.attachments["#{model.time}.#{model.trigger}.log"].
|
197
|
+
read.should == "line 1\nline 2\nline 3"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'when status is :failure' do
|
202
|
+
before do
|
203
|
+
Backup::Logger.stubs(:messages).returns(['line 1', 'line 2', 'line 3'])
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should send a Failure email with an attached log' do
|
207
|
+
template.expects(:result).
|
208
|
+
with('notifier/mail/failure.erb').
|
209
|
+
returns('message body')
|
210
|
+
|
211
|
+
notifier.send(:notify!, :failure)
|
212
|
+
|
213
|
+
sent_message = ::Mail::TestMailer.deliveries.first
|
214
|
+
sent_message.subject.should == message % 'Failure'
|
215
|
+
sent_message.body.multipart?.should be_true
|
216
|
+
sent_message.text_part.decoded.should == 'message body'
|
217
|
+
sent_message.attachments["#{model.time}.#{model.trigger}.log"].
|
218
|
+
read.should == "line 1\nline 2\nline 3"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end # describe '#notify!'
|
222
|
+
|
223
|
+
describe '#new_email' do
|
224
|
+
context 'when no delivery_method is set' do
|
225
|
+
before { notifier.delivery_method = nil }
|
226
|
+
it 'should default to :smtp' do
|
227
|
+
email = notifier.send(:new_email)
|
228
|
+
email.should be_an_instance_of ::Mail::Message
|
229
|
+
email.delivery_method.should be_an_instance_of ::Mail::SMTP
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'when delivery_method is :smtp' do
|
234
|
+
before { notifier.delivery_method = :smtp }
|
235
|
+
|
236
|
+
it 'should return an email using SMTP' do
|
237
|
+
email = notifier.send(:new_email)
|
238
|
+
email.delivery_method.should be_an_instance_of ::Mail::SMTP
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'should set the proper options' do
|
242
|
+
email = notifier.send(:new_email)
|
243
|
+
|
244
|
+
email.to.should == ['my.receiver.email@gmail.com']
|
245
|
+
email.from.should == ['my.sender.email@gmail.com']
|
246
|
+
|
247
|
+
settings = email.delivery_method.settings
|
248
|
+
settings[:address].should == 'smtp.gmail.com'
|
249
|
+
settings[:port].should == 587
|
250
|
+
settings[:domain].should == 'your.host.name'
|
251
|
+
settings[:user_name].should == 'user'
|
252
|
+
settings[:password].should == 'secret'
|
253
|
+
settings[:authentication].should == 'plain'
|
254
|
+
settings[:enable_starttls_auto].should == true
|
255
|
+
settings[:openssl_verify_mode].should be_nil
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when delivery_method is :sendmail' do
|
260
|
+
before { notifier.delivery_method = :sendmail }
|
261
|
+
it 'should return an email using Sendmail' do
|
262
|
+
email = notifier.send(:new_email)
|
263
|
+
email.delivery_method.should be_an_instance_of ::Mail::Sendmail
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'should set the proper options' do
|
267
|
+
email = notifier.send(:new_email)
|
268
|
+
|
269
|
+
email.to.should == ['my.receiver.email@gmail.com']
|
270
|
+
email.from.should == ['my.sender.email@gmail.com']
|
271
|
+
|
272
|
+
settings = email.delivery_method.settings
|
273
|
+
settings[:location].should == '/path/to/sendmail'
|
274
|
+
settings[:arguments].should == '-i -t -X/tmp/traffic.log'
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context 'when delivery_method is :exim' do
|
279
|
+
before { notifier.delivery_method = :exim }
|
280
|
+
it 'should return an email using Exim' do
|
281
|
+
email = notifier.send(:new_email)
|
282
|
+
email.delivery_method.should be_an_instance_of ::Mail::Exim
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should set the proper options' do
|
286
|
+
email = notifier.send(:new_email)
|
287
|
+
|
288
|
+
email.to.should == ['my.receiver.email@gmail.com']
|
289
|
+
email.from.should == ['my.sender.email@gmail.com']
|
290
|
+
|
291
|
+
settings = email.delivery_method.settings
|
292
|
+
settings[:location].should == '/path/to/exim'
|
293
|
+
settings[:arguments].should == '-i -t -X/tmp/traffic.log'
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'when delivery_method is :file' do
|
298
|
+
before { notifier.delivery_method = :file }
|
299
|
+
it 'should return an email using FileDelievery' do
|
300
|
+
email = notifier.send(:new_email)
|
301
|
+
email.delivery_method.should be_an_instance_of ::Mail::FileDelivery
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'should set the proper options' do
|
305
|
+
email = notifier.send(:new_email)
|
306
|
+
|
307
|
+
email.to.should == ['my.receiver.email@gmail.com']
|
308
|
+
email.from.should == ['my.sender.email@gmail.com']
|
309
|
+
|
310
|
+
settings = email.delivery_method.settings
|
311
|
+
settings[:location].should == '/path/to/backup/mails'
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end # describe '#new_email'
|
315
|
+
|
316
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Notifier::Prowl do
|
6
|
+
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
+
let(:notifier) do
|
8
|
+
Backup::Notifier::Prowl.new(model) do |prowl|
|
9
|
+
prowl.application = 'application'
|
10
|
+
prowl.api_key = 'api_key'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should be a subclass of Notifier::Base' do
|
15
|
+
Backup::Notifier::Prowl.
|
16
|
+
superclass.should == Backup::Notifier::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#initialize' do
|
20
|
+
after { Backup::Notifier::Prowl.clear_defaults! }
|
21
|
+
|
22
|
+
it 'should load pre-configured defaults through Base' do
|
23
|
+
Backup::Notifier::Prowl.any_instance.expects(:load_defaults!)
|
24
|
+
notifier
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should pass the model reference to Base' do
|
28
|
+
notifier.instance_variable_get(:@model).should == model
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when no pre-configured defaults have been set' do
|
32
|
+
it 'should use the values given' do
|
33
|
+
notifier.application.should == 'application'
|
34
|
+
notifier.api_key.should == 'api_key'
|
35
|
+
|
36
|
+
notifier.on_success.should == true
|
37
|
+
notifier.on_warning.should == true
|
38
|
+
notifier.on_failure.should == true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should use default values if none are given' do
|
42
|
+
notifier = Backup::Notifier::Prowl.new(model)
|
43
|
+
notifier.application.should be_nil
|
44
|
+
notifier.api_key.should be_nil
|
45
|
+
|
46
|
+
notifier.on_success.should == true
|
47
|
+
notifier.on_warning.should == true
|
48
|
+
notifier.on_failure.should == true
|
49
|
+
end
|
50
|
+
end # context 'when no pre-configured defaults have been set'
|
51
|
+
|
52
|
+
context 'when pre-configured defaults have been set' do
|
53
|
+
before do
|
54
|
+
Backup::Notifier::Prowl.defaults do |n|
|
55
|
+
n.application = 'default_app'
|
56
|
+
n.api_key = 'default_api_key'
|
57
|
+
|
58
|
+
n.on_success = false
|
59
|
+
n.on_warning = false
|
60
|
+
n.on_failure = false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should use pre-configured defaults' do
|
65
|
+
notifier = Backup::Notifier::Prowl.new(model)
|
66
|
+
notifier.application.should == 'default_app'
|
67
|
+
notifier.api_key.should == 'default_api_key'
|
68
|
+
|
69
|
+
notifier.on_success.should == false
|
70
|
+
notifier.on_warning.should == false
|
71
|
+
notifier.on_failure.should == false
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should override pre-configured defaults' do
|
75
|
+
notifier = Backup::Notifier::Prowl.new(model) do |n|
|
76
|
+
n.application = 'new_app'
|
77
|
+
n.api_key = 'new_api_key'
|
78
|
+
|
79
|
+
n.on_success = false
|
80
|
+
n.on_warning = true
|
81
|
+
n.on_failure = true
|
82
|
+
end
|
83
|
+
|
84
|
+
notifier.application.should == 'new_app'
|
85
|
+
notifier.api_key.should == 'new_api_key'
|
86
|
+
|
87
|
+
notifier.on_success.should == false
|
88
|
+
notifier.on_warning.should == true
|
89
|
+
notifier.on_failure.should == true
|
90
|
+
end
|
91
|
+
end # context 'when pre-configured defaults have been set'
|
92
|
+
end # describe '#initialize'
|
93
|
+
|
94
|
+
describe '#notify!' do
|
95
|
+
context 'when status is :success' do
|
96
|
+
it 'should send Success message' do
|
97
|
+
notifier.expects(:send_message).with(
|
98
|
+
'[Backup::Success]'
|
99
|
+
)
|
100
|
+
notifier.send(:notify!, :success)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when status is :warning' do
|
105
|
+
it 'should send Warning message' do
|
106
|
+
notifier.expects(:send_message).with(
|
107
|
+
'[Backup::Warning]'
|
108
|
+
)
|
109
|
+
notifier.send(:notify!, :warning)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when status is :failure' do
|
114
|
+
it 'should send Failure message' do
|
115
|
+
notifier.expects(:send_message).with(
|
116
|
+
'[Backup::Failure]'
|
117
|
+
)
|
118
|
+
notifier.send(:notify!, :failure)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end # describe '#notify!'
|
122
|
+
|
123
|
+
describe '#send_message' do
|
124
|
+
it 'should send the given message' do
|
125
|
+
client = mock
|
126
|
+
Prowler.expects(:new).with(
|
127
|
+
:application => 'application', :api_key => 'api_key'
|
128
|
+
).returns(client)
|
129
|
+
client.expects(:notify).with(
|
130
|
+
'a message',
|
131
|
+
'test label (test_trigger)'
|
132
|
+
)
|
133
|
+
|
134
|
+
notifier.send(:send_message, 'a message')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|