backup 3.0.20 → 3.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -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
- context 'specifying the delivery_method' do
10
-
11
- it 'creates a new notifier using Mail::SMTP' do
12
- notifier = Backup::Notifier::Mail.new do |mail|
13
- mail.delivery_method = :smtp
14
- mail.from = 'my.sender.email@gmail.com'
15
- mail.to = 'my.receiver.email@gmail.com'
16
- mail.address = 'smtp.gmail.com'
17
- mail.port = 587
18
- mail.domain = 'your.host.name'
19
- mail.user_name = 'user'
20
- mail.password = 'secret'
21
- mail.authentication = 'plain'
22
- mail.enable_starttls_auto = true
23
- end
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
- notifier.mail.delivery_method.should
26
- be_an_instance_of ::Mail::SMTP
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 'creates a new notifier using Mail::Sendmail' do
49
- notifier = Backup::Notifier::Mail.new do |mail|
50
- mail.delivery_method = :sendmail
51
- mail.from = 'my.sender.email@gmail.com'
52
- mail.to = 'my.receiver.email@gmail.com'
53
- mail.sendmail = '/path/to/sendmail'
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.mail.delivery_method.should
58
- be_an_instance_of ::Mail::Sendmail
59
-
60
- notifier.delivery_method.should == 'sendmail'
61
- notifier.from.should == 'my.sender.email@gmail.com'
62
- notifier.to.should == 'my.receiver.email@gmail.com'
63
- notifier.address.should be_nil
64
- notifier.port.should be_nil
65
- notifier.domain.should be_nil
66
- notifier.user_name.should be_nil
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
- it 'creates a new notifier using Mail::FileDelivery' do
81
- notifier = Backup::Notifier::Mail.new do |mail|
82
- mail.delivery_method = :file
83
- mail.from = 'my.sender.email@gmail.com'
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.mail.delivery_method.should
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
- end # context 'specifying the delivery_method'
112
-
113
- context 'without specifying the delivery_method' do
114
-
115
- it 'uses Mail::SMTP by default' do
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
- config.delivery_method.should == :file
144
- config.to.should == 'some.receiver.email@gmail.com'
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 == 'file'
155
- notifier.mail_folder = '/my/backup/mails'
156
- notifier.to.should == 'some.receiver.email@gmail.com'
157
- notifier.from.should == 'my.sender.email@gmail.com'
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 # describe 'setting configuration defaults'
107
+ end # context 'when using configuration defaults'
165
108
 
166
109
  end # describe '#initialize'
167
110
 
168
- describe '#perform!' do
169
- let(:model) { Backup::Model.new('trigger', 'label') {} }
170
- let(:message) { '[Backup::%s] label (trigger)' }
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.on_success = false
179
- notifier.on_warning = false
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
- context 'when Notifier#on_success is true' do
187
- before { notifier.on_success = true }
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
- it 'sends the notification without an attached backup log' do
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
- notifier.perform!(model)
196
- sent_message = ::Mail::TestMailer.deliveries.first
197
- sent_message.subject.should == message % 'Success'
198
- sent_message.multipart?.should be_false
199
- sent_message.body.should == 'message body'
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
- context 'when Notifier#on_success is false' do
205
- it 'does not send the notification' do
206
- notifier.expects(:log!).never
207
- notifier.expects(:notify!).never
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
- end # context 'success'
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
- context 'warning' do
217
- let(:log_messages){ ['line 1', 'line 2', 'line 3'] }
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(:has_warnings?).returns(true)
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
- context 'when Notifier#on_warning is true' do
225
- before { notifier.on_warning = true }
226
-
227
- it 'sends the notification with an attached backup log' do
228
- notifier.expects(:log!)
229
- Backup::Template.any_instance.expects(:result).
230
- with('notifier/mail/warning.erb').
231
- returns('message body')
232
-
233
- notifier.perform!(model)
234
- sent_message = ::Mail::TestMailer.deliveries.first
235
- sent_message.subject.should == message % 'Warning'
236
- sent_message.body.multipart?.should be_true
237
- sent_message.text_part.decoded.should == 'message body'
238
- sent_message.attachments["#{model.time}.#{model.trigger}.log"].
239
- read.should == "line 1\nline 2\nline 3"
240
- end
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
- context 'when Notifier#on_success is true' do
244
- before { notifier.on_success = true }
245
-
246
- it 'sends the notification with an attched backup log' do
247
- notifier.expects(:log!)
248
- Backup::Template.any_instance.expects(:result).
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
- context 'when Notifier#on_warning and Notifier#on_success are false' do
263
- it 'does not send the notification' do
264
- notifier.expects(:log!).never
265
- notifier.expects(:notify!).never
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
- notifier.perform!(model)
268
- ::Mail::TestMailer.deliveries.should be_empty
269
- end
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
- end # context 'warning'
224
+ it 'should set the proper options' do
225
+ email = notifier.send(:new_email)
273
226
 
274
- context 'failure' do
275
- let(:log_messages){ ['line 1', 'line 2', 'line 3'] }
227
+ email.to.should == ['my.receiver.email@gmail.com']
228
+ email.from.should == ['my.sender.email@gmail.com']
276
229
 
277
- before do
278
- Backup::Logger.stubs(:messages).returns(log_messages)
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
- context 'when Notifier#on_failure is true' do
282
- before { notifier.on_failure = true }
283
-
284
- it 'sends the notification with an attached backup log' do
285
- notifier.expects(:log!)
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
- context 'when Notifier#on_failure is false' do
301
- it 'does not send the notification' do
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
- notifier.perform!(model, Exception.new)
306
- ::Mail::TestMailer.deliveries.should be_empty
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
- end # context 'failure'
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