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