backup_checksum 3.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Gemfile.lock +130 -0
  5. data/Guardfile +21 -0
  6. data/LICENSE.md +24 -0
  7. data/README.md +476 -0
  8. data/backup_checksum.gemspec +32 -0
  9. data/bin/backup +11 -0
  10. data/lib/backup.rb +217 -0
  11. data/lib/backup/archive.rb +117 -0
  12. data/lib/backup/binder.rb +22 -0
  13. data/lib/backup/checksum/base.rb +44 -0
  14. data/lib/backup/checksum/shasum.rb +16 -0
  15. data/lib/backup/cleaner.rb +121 -0
  16. data/lib/backup/cli/helpers.rb +88 -0
  17. data/lib/backup/cli/utility.rb +247 -0
  18. data/lib/backup/compressor/base.rb +29 -0
  19. data/lib/backup/compressor/bzip2.rb +50 -0
  20. data/lib/backup/compressor/gzip.rb +47 -0
  21. data/lib/backup/compressor/lzma.rb +50 -0
  22. data/lib/backup/compressor/pbzip2.rb +56 -0
  23. data/lib/backup/config.rb +173 -0
  24. data/lib/backup/configuration/base.rb +15 -0
  25. data/lib/backup/configuration/checksum/base.rb +9 -0
  26. data/lib/backup/configuration/checksum/shasum.rb +9 -0
  27. data/lib/backup/configuration/compressor/base.rb +9 -0
  28. data/lib/backup/configuration/compressor/bzip2.rb +23 -0
  29. data/lib/backup/configuration/compressor/gzip.rb +23 -0
  30. data/lib/backup/configuration/compressor/lzma.rb +23 -0
  31. data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
  32. data/lib/backup/configuration/database/base.rb +19 -0
  33. data/lib/backup/configuration/database/mongodb.rb +49 -0
  34. data/lib/backup/configuration/database/mysql.rb +42 -0
  35. data/lib/backup/configuration/database/postgresql.rb +41 -0
  36. data/lib/backup/configuration/database/redis.rb +39 -0
  37. data/lib/backup/configuration/database/riak.rb +29 -0
  38. data/lib/backup/configuration/encryptor/base.rb +9 -0
  39. data/lib/backup/configuration/encryptor/gpg.rb +17 -0
  40. data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
  41. data/lib/backup/configuration/helpers.rb +52 -0
  42. data/lib/backup/configuration/notifier/base.rb +28 -0
  43. data/lib/backup/configuration/notifier/campfire.rb +25 -0
  44. data/lib/backup/configuration/notifier/hipchat.rb +41 -0
  45. data/lib/backup/configuration/notifier/mail.rb +112 -0
  46. data/lib/backup/configuration/notifier/presently.rb +25 -0
  47. data/lib/backup/configuration/notifier/prowl.rb +23 -0
  48. data/lib/backup/configuration/notifier/twitter.rb +21 -0
  49. data/lib/backup/configuration/storage/base.rb +18 -0
  50. data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
  51. data/lib/backup/configuration/storage/dropbox.rb +58 -0
  52. data/lib/backup/configuration/storage/ftp.rb +29 -0
  53. data/lib/backup/configuration/storage/local.rb +17 -0
  54. data/lib/backup/configuration/storage/ninefold.rb +20 -0
  55. data/lib/backup/configuration/storage/rsync.rb +29 -0
  56. data/lib/backup/configuration/storage/s3.rb +25 -0
  57. data/lib/backup/configuration/storage/scp.rb +25 -0
  58. data/lib/backup/configuration/storage/sftp.rb +25 -0
  59. data/lib/backup/configuration/syncer/base.rb +10 -0
  60. data/lib/backup/configuration/syncer/cloud.rb +23 -0
  61. data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
  62. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  63. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  64. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  65. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  66. data/lib/backup/configuration/syncer/s3.rb +23 -0
  67. data/lib/backup/database/base.rb +59 -0
  68. data/lib/backup/database/mongodb.rb +232 -0
  69. data/lib/backup/database/mysql.rb +163 -0
  70. data/lib/backup/database/postgresql.rb +146 -0
  71. data/lib/backup/database/redis.rb +139 -0
  72. data/lib/backup/database/riak.rb +69 -0
  73. data/lib/backup/dependency.rb +114 -0
  74. data/lib/backup/encryptor/base.rb +29 -0
  75. data/lib/backup/encryptor/gpg.rb +80 -0
  76. data/lib/backup/encryptor/open_ssl.rb +72 -0
  77. data/lib/backup/errors.rb +124 -0
  78. data/lib/backup/logger.rb +152 -0
  79. data/lib/backup/model.rb +386 -0
  80. data/lib/backup/notifier/base.rb +81 -0
  81. data/lib/backup/notifier/campfire.rb +168 -0
  82. data/lib/backup/notifier/hipchat.rb +99 -0
  83. data/lib/backup/notifier/mail.rb +206 -0
  84. data/lib/backup/notifier/presently.rb +88 -0
  85. data/lib/backup/notifier/prowl.rb +65 -0
  86. data/lib/backup/notifier/twitter.rb +70 -0
  87. data/lib/backup/package.rb +51 -0
  88. data/lib/backup/packager.rb +108 -0
  89. data/lib/backup/pipeline.rb +107 -0
  90. data/lib/backup/splitter.rb +75 -0
  91. data/lib/backup/storage/base.rb +119 -0
  92. data/lib/backup/storage/cloudfiles.rb +87 -0
  93. data/lib/backup/storage/cycler.rb +117 -0
  94. data/lib/backup/storage/dropbox.rb +181 -0
  95. data/lib/backup/storage/ftp.rb +119 -0
  96. data/lib/backup/storage/local.rb +82 -0
  97. data/lib/backup/storage/ninefold.rb +116 -0
  98. data/lib/backup/storage/rsync.rb +149 -0
  99. data/lib/backup/storage/s3.rb +94 -0
  100. data/lib/backup/storage/scp.rb +99 -0
  101. data/lib/backup/storage/sftp.rb +108 -0
  102. data/lib/backup/syncer/base.rb +42 -0
  103. data/lib/backup/syncer/cloud.rb +190 -0
  104. data/lib/backup/syncer/cloud_files.rb +56 -0
  105. data/lib/backup/syncer/rsync/base.rb +52 -0
  106. data/lib/backup/syncer/rsync/local.rb +53 -0
  107. data/lib/backup/syncer/rsync/pull.rb +38 -0
  108. data/lib/backup/syncer/rsync/push.rb +113 -0
  109. data/lib/backup/syncer/s3.rb +47 -0
  110. data/lib/backup/template.rb +46 -0
  111. data/lib/backup/version.rb +43 -0
  112. data/spec/archive_spec.rb +335 -0
  113. data/spec/cleaner_spec.rb +304 -0
  114. data/spec/cli/helpers_spec.rb +176 -0
  115. data/spec/cli/utility_spec.rb +363 -0
  116. data/spec/compressor/base_spec.rb +31 -0
  117. data/spec/compressor/bzip2_spec.rb +83 -0
  118. data/spec/compressor/gzip_spec.rb +83 -0
  119. data/spec/compressor/lzma_spec.rb +83 -0
  120. data/spec/compressor/pbzip2_spec.rb +124 -0
  121. data/spec/config_spec.rb +321 -0
  122. data/spec/configuration/base_spec.rb +35 -0
  123. data/spec/configuration/compressor/bzip2_spec.rb +29 -0
  124. data/spec/configuration/compressor/gzip_spec.rb +29 -0
  125. data/spec/configuration/compressor/lzma_spec.rb +29 -0
  126. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  127. data/spec/configuration/database/base_spec.rb +17 -0
  128. data/spec/configuration/database/mongodb_spec.rb +56 -0
  129. data/spec/configuration/database/mysql_spec.rb +53 -0
  130. data/spec/configuration/database/postgresql_spec.rb +53 -0
  131. data/spec/configuration/database/redis_spec.rb +50 -0
  132. data/spec/configuration/database/riak_spec.rb +35 -0
  133. data/spec/configuration/encryptor/gpg_spec.rb +26 -0
  134. data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
  135. data/spec/configuration/notifier/base_spec.rb +32 -0
  136. data/spec/configuration/notifier/campfire_spec.rb +32 -0
  137. data/spec/configuration/notifier/hipchat_spec.rb +44 -0
  138. data/spec/configuration/notifier/mail_spec.rb +71 -0
  139. data/spec/configuration/notifier/presently_spec.rb +35 -0
  140. data/spec/configuration/notifier/prowl_spec.rb +29 -0
  141. data/spec/configuration/notifier/twitter_spec.rb +35 -0
  142. data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
  143. data/spec/configuration/storage/dropbox_spec.rb +38 -0
  144. data/spec/configuration/storage/ftp_spec.rb +44 -0
  145. data/spec/configuration/storage/local_spec.rb +29 -0
  146. data/spec/configuration/storage/ninefold_spec.rb +32 -0
  147. data/spec/configuration/storage/rsync_spec.rb +41 -0
  148. data/spec/configuration/storage/s3_spec.rb +38 -0
  149. data/spec/configuration/storage/scp_spec.rb +41 -0
  150. data/spec/configuration/storage/sftp_spec.rb +41 -0
  151. data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
  152. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  153. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  154. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  155. data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
  156. data/spec/configuration/syncer/s3_spec.rb +38 -0
  157. data/spec/database/base_spec.rb +54 -0
  158. data/spec/database/mongodb_spec.rb +428 -0
  159. data/spec/database/mysql_spec.rb +335 -0
  160. data/spec/database/postgresql_spec.rb +278 -0
  161. data/spec/database/redis_spec.rb +260 -0
  162. data/spec/database/riak_spec.rb +108 -0
  163. data/spec/dependency_spec.rb +49 -0
  164. data/spec/encryptor/base_spec.rb +30 -0
  165. data/spec/encryptor/gpg_spec.rb +134 -0
  166. data/spec/encryptor/open_ssl_spec.rb +129 -0
  167. data/spec/errors_spec.rb +306 -0
  168. data/spec/logger_spec.rb +363 -0
  169. data/spec/model_spec.rb +649 -0
  170. data/spec/notifier/base_spec.rb +89 -0
  171. data/spec/notifier/campfire_spec.rb +199 -0
  172. data/spec/notifier/hipchat_spec.rb +188 -0
  173. data/spec/notifier/mail_spec.rb +280 -0
  174. data/spec/notifier/presently_spec.rb +181 -0
  175. data/spec/notifier/prowl_spec.rb +117 -0
  176. data/spec/notifier/twitter_spec.rb +132 -0
  177. data/spec/package_spec.rb +61 -0
  178. data/spec/packager_spec.rb +225 -0
  179. data/spec/pipeline_spec.rb +257 -0
  180. data/spec/spec_helper.rb +59 -0
  181. data/spec/splitter_spec.rb +120 -0
  182. data/spec/storage/base_spec.rb +160 -0
  183. data/spec/storage/cloudfiles_spec.rb +230 -0
  184. data/spec/storage/cycler_spec.rb +239 -0
  185. data/spec/storage/dropbox_spec.rb +370 -0
  186. data/spec/storage/ftp_spec.rb +247 -0
  187. data/spec/storage/local_spec.rb +235 -0
  188. data/spec/storage/ninefold_spec.rb +319 -0
  189. data/spec/storage/rsync_spec.rb +345 -0
  190. data/spec/storage/s3_spec.rb +221 -0
  191. data/spec/storage/scp_spec.rb +209 -0
  192. data/spec/storage/sftp_spec.rb +220 -0
  193. data/spec/syncer/base_spec.rb +22 -0
  194. data/spec/syncer/cloud_files_spec.rb +192 -0
  195. data/spec/syncer/rsync/base_spec.rb +118 -0
  196. data/spec/syncer/rsync/local_spec.rb +121 -0
  197. data/spec/syncer/rsync/pull_spec.rb +90 -0
  198. data/spec/syncer/rsync/push_spec.rb +327 -0
  199. data/spec/syncer/s3_spec.rb +192 -0
  200. data/spec/version_spec.rb +21 -0
  201. data/templates/cli/utility/archive +25 -0
  202. data/templates/cli/utility/compressor/bzip2 +7 -0
  203. data/templates/cli/utility/compressor/gzip +7 -0
  204. data/templates/cli/utility/compressor/lzma +7 -0
  205. data/templates/cli/utility/compressor/pbzip2 +7 -0
  206. data/templates/cli/utility/config +31 -0
  207. data/templates/cli/utility/database/mongodb +18 -0
  208. data/templates/cli/utility/database/mysql +21 -0
  209. data/templates/cli/utility/database/postgresql +17 -0
  210. data/templates/cli/utility/database/redis +16 -0
  211. data/templates/cli/utility/database/riak +11 -0
  212. data/templates/cli/utility/encryptor/gpg +12 -0
  213. data/templates/cli/utility/encryptor/openssl +9 -0
  214. data/templates/cli/utility/model.erb +23 -0
  215. data/templates/cli/utility/notifier/campfire +12 -0
  216. data/templates/cli/utility/notifier/hipchat +15 -0
  217. data/templates/cli/utility/notifier/mail +22 -0
  218. data/templates/cli/utility/notifier/presently +13 -0
  219. data/templates/cli/utility/notifier/prowl +11 -0
  220. data/templates/cli/utility/notifier/twitter +13 -0
  221. data/templates/cli/utility/splitter +7 -0
  222. data/templates/cli/utility/storage/cloud_files +22 -0
  223. data/templates/cli/utility/storage/dropbox +20 -0
  224. data/templates/cli/utility/storage/ftp +12 -0
  225. data/templates/cli/utility/storage/local +7 -0
  226. data/templates/cli/utility/storage/ninefold +9 -0
  227. data/templates/cli/utility/storage/rsync +11 -0
  228. data/templates/cli/utility/storage/s3 +19 -0
  229. data/templates/cli/utility/storage/scp +11 -0
  230. data/templates/cli/utility/storage/sftp +11 -0
  231. data/templates/cli/utility/syncer/cloud_files +48 -0
  232. data/templates/cli/utility/syncer/rsync_local +12 -0
  233. data/templates/cli/utility/syncer/rsync_pull +17 -0
  234. data/templates/cli/utility/syncer/rsync_push +17 -0
  235. data/templates/cli/utility/syncer/s3 +45 -0
  236. data/templates/general/links +11 -0
  237. data/templates/general/version.erb +2 -0
  238. data/templates/notifier/mail/failure.erb +9 -0
  239. data/templates/notifier/mail/success.erb +7 -0
  240. data/templates/notifier/mail/warning.erb +9 -0
  241. data/templates/storage/dropbox/authorization_url.erb +6 -0
  242. data/templates/storage/dropbox/authorized.erb +4 -0
  243. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  244. metadata +311 -0
@@ -0,0 +1,280 @@
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
+ describe '#initialize' do
30
+
31
+ it 'should set the correct values' do
32
+ notifier.delivery_method.should == :smtp
33
+ notifier.from.should == 'my.sender.email@gmail.com'
34
+ notifier.to.should == 'my.receiver.email@gmail.com'
35
+ notifier.address.should == 'smtp.gmail.com'
36
+ notifier.port.should == 587
37
+ notifier.domain.should == 'your.host.name'
38
+ notifier.user_name.should == 'user'
39
+ notifier.password.should == 'secret'
40
+ notifier.authentication.should == 'plain'
41
+ notifier.enable_starttls_auto.should == true
42
+
43
+ notifier.sendmail.should == '/path/to/sendmail'
44
+ notifier.sendmail_args.should == '-i -t -X/tmp/traffic.log'
45
+ notifier.exim.should == '/path/to/exim'
46
+ notifier.exim_args.should == '-i -t -X/tmp/traffic.log'
47
+
48
+ notifier.mail_folder.should == '/path/to/backup/mails'
49
+
50
+ notifier.on_success.should == true
51
+ notifier.on_warning.should == true
52
+ notifier.on_failure.should == true
53
+ end
54
+
55
+ context 'when using configuration defaults' do
56
+ after { Backup::Configuration::Notifier::Mail.clear_defaults! }
57
+
58
+ it 'should use configuration defaults' do
59
+ Backup::Configuration::Notifier::Mail.defaults do |mail|
60
+ mail.delivery_method = :file
61
+ mail.from = 'default.sender@domain.com'
62
+ mail.to = 'some.receiver@domain.com'
63
+ mail.on_success = false
64
+ end
65
+ notifier = Backup::Notifier::Mail.new(model)
66
+
67
+ notifier.delivery_method.should == :file
68
+ notifier.from.should == 'default.sender@domain.com'
69
+ notifier.to.should == 'some.receiver@domain.com'
70
+ notifier.address.should be_nil
71
+ notifier.port.should be_nil
72
+ notifier.domain.should be_nil
73
+ notifier.user_name.should be_nil
74
+ notifier.password.should be_nil
75
+ notifier.authentication.should be_nil
76
+ notifier.enable_starttls_auto.should be_nil
77
+
78
+ notifier.sendmail.should be_nil
79
+ notifier.sendmail_args.should be_nil
80
+ notifier.exim.should be_nil
81
+ notifier.exim_args.should be_nil
82
+
83
+ notifier.mail_folder.should be_nil
84
+
85
+ notifier.on_success.should == false
86
+ notifier.on_warning.should == true
87
+ notifier.on_failure.should == true
88
+ end
89
+
90
+ it 'should override configuration defaults' do
91
+ Backup::Configuration::Notifier::Mail.defaults do |mail|
92
+ mail.from = 'old.sender@domain.com'
93
+ mail.to = 'old.receiver@domain.com'
94
+ mail.port = 123
95
+ mail.on_success = false
96
+ end
97
+ notifier = Backup::Notifier::Mail.new(model) do |mail|
98
+ mail.from = 'new.sender@domain.com'
99
+ mail.to = 'new.receiver@domain.com'
100
+ mail.on_warning = false
101
+ end
102
+
103
+ notifier.delivery_method.should be_nil
104
+ notifier.from.should == 'new.sender@domain.com'
105
+ notifier.to.should == 'new.receiver@domain.com'
106
+ notifier.port.should == 123
107
+
108
+ notifier.on_success.should == false
109
+ notifier.on_warning.should == false
110
+ notifier.on_failure.should == true
111
+ end
112
+
113
+ end # context 'when using configuration defaults'
114
+
115
+ end # describe '#initialize'
116
+
117
+ describe '#notify!' do
118
+ let(:template) { mock }
119
+ let(:message) { '[Backup::%s] test label (test_trigger)' }
120
+
121
+ before do
122
+ notifier.instance_variable_set(:@template, template)
123
+ notifier.delivery_method = :test
124
+ ::Mail::TestMailer.deliveries.clear
125
+ end
126
+
127
+ context 'when status is :success' do
128
+ it 'should send a Success email with no attachments' do
129
+ template.expects(:result).
130
+ with('notifier/mail/success.erb').
131
+ returns('message body')
132
+
133
+ notifier.send(:notify!, :success)
134
+
135
+ sent_message = ::Mail::TestMailer.deliveries.first
136
+ sent_message.subject.should == message % 'Success'
137
+ sent_message.multipart?.should be_false
138
+ sent_message.body.should == 'message body'
139
+ sent_message.has_attachments?.should be_false
140
+ end
141
+ end
142
+
143
+ context 'when status is :warning' do
144
+ before do
145
+ Backup::Logger.stubs(:has_warnings?).returns(true)
146
+ Backup::Logger.stubs(:messages).returns(['line 1', 'line 2', 'line 3'])
147
+ end
148
+
149
+ it 'should send a Warning email with an attached log' do
150
+ template.expects(:result).
151
+ with('notifier/mail/warning.erb').
152
+ returns('message body')
153
+
154
+ notifier.send(:notify!, :warning)
155
+
156
+ sent_message = ::Mail::TestMailer.deliveries.first
157
+ sent_message.subject.should == message % 'Warning'
158
+ sent_message.body.multipart?.should be_true
159
+ sent_message.text_part.decoded.should == 'message body'
160
+ sent_message.attachments["#{model.time}.#{model.trigger}.log"].
161
+ read.should == "line 1\nline 2\nline 3"
162
+ end
163
+ end
164
+
165
+ context 'when status is :failure' do
166
+ before do
167
+ Backup::Logger.stubs(:messages).returns(['line 1', 'line 2', 'line 3'])
168
+ end
169
+
170
+ it 'should send a Failure email with an attached log' do
171
+ template.expects(:result).
172
+ with('notifier/mail/failure.erb').
173
+ returns('message body')
174
+
175
+ notifier.send(:notify!, :failure)
176
+
177
+ sent_message = ::Mail::TestMailer.deliveries.first
178
+ sent_message.subject.should == message % 'Failure'
179
+ sent_message.body.multipart?.should be_true
180
+ sent_message.text_part.decoded.should == 'message body'
181
+ sent_message.attachments["#{model.time}.#{model.trigger}.log"].
182
+ read.should == "line 1\nline 2\nline 3"
183
+ end
184
+ end
185
+ end # describe '#notify!'
186
+
187
+ describe '#new_email' do
188
+ context 'when no delivery_method is set' do
189
+ before { notifier.delivery_method = nil }
190
+ it 'should default to :smtp' do
191
+ email = notifier.send(:new_email)
192
+ email.should be_an_instance_of ::Mail::Message
193
+ email.delivery_method.should be_an_instance_of ::Mail::SMTP
194
+ end
195
+ end
196
+
197
+ context 'when delivery_method is :smtp' do
198
+ before { notifier.delivery_method = :smtp }
199
+
200
+ it 'should return an email using SMTP' do
201
+ email = notifier.send(:new_email)
202
+ email.delivery_method.should be_an_instance_of ::Mail::SMTP
203
+ end
204
+
205
+ it 'should set the proper options' do
206
+ email = notifier.send(:new_email)
207
+
208
+ email.to.should == ['my.receiver.email@gmail.com']
209
+ email.from.should == ['my.sender.email@gmail.com']
210
+
211
+ settings = email.delivery_method.settings
212
+ settings[:address].should == 'smtp.gmail.com'
213
+ settings[:port].should == 587
214
+ settings[:domain].should == 'your.host.name'
215
+ settings[:user_name].should == 'user'
216
+ settings[:password].should == 'secret'
217
+ settings[:authentication].should == 'plain'
218
+ settings[:enable_starttls_auto].should == true
219
+ settings[:openssl_verify_mode].should be_nil
220
+ end
221
+ end
222
+
223
+ context 'when delivery_method is :sendmail' do
224
+ before { notifier.delivery_method = :sendmail }
225
+ it 'should return an email using Sendmail' do
226
+ email = notifier.send(:new_email)
227
+ email.delivery_method.should be_an_instance_of ::Mail::Sendmail
228
+ end
229
+
230
+ it 'should set the proper options' do
231
+ email = notifier.send(:new_email)
232
+
233
+ email.to.should == ['my.receiver.email@gmail.com']
234
+ email.from.should == ['my.sender.email@gmail.com']
235
+
236
+ settings = email.delivery_method.settings
237
+ settings[:location].should == '/path/to/sendmail'
238
+ settings[:arguments].should == '-i -t -X/tmp/traffic.log'
239
+ end
240
+ end
241
+
242
+ context 'when delivery_method is :exim' do
243
+ before { notifier.delivery_method = :exim }
244
+ it 'should return an email using Exim' do
245
+ email = notifier.send(:new_email)
246
+ email.delivery_method.should be_an_instance_of ::Mail::Exim
247
+ end
248
+
249
+ it 'should set the proper options' do
250
+ email = notifier.send(:new_email)
251
+
252
+ email.to.should == ['my.receiver.email@gmail.com']
253
+ email.from.should == ['my.sender.email@gmail.com']
254
+
255
+ settings = email.delivery_method.settings
256
+ settings[:location].should == '/path/to/exim'
257
+ settings[:arguments].should == '-i -t -X/tmp/traffic.log'
258
+ end
259
+ end
260
+
261
+ context 'when delivery_method is :file' do
262
+ before { notifier.delivery_method = :file }
263
+ it 'should return an email using FileDelievery' do
264
+ email = notifier.send(:new_email)
265
+ email.delivery_method.should be_an_instance_of ::Mail::FileDelivery
266
+ end
267
+
268
+ it 'should set the proper options' do
269
+ email = notifier.send(:new_email)
270
+
271
+ email.to.should == ['my.receiver.email@gmail.com']
272
+ email.from.should == ['my.sender.email@gmail.com']
273
+
274
+ settings = email.delivery_method.settings
275
+ settings[:location].should == '/path/to/backup/mails'
276
+ end
277
+ end
278
+ end # describe '#new_email'
279
+
280
+ end
@@ -0,0 +1,181 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Notifier::Presently do
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:notifier) do
8
+ Backup::Notifier::Presently.new(model) do |presently|
9
+ presently.user_name = 'user_name'
10
+ presently.subdomain = 'subdomain'
11
+ presently.password = 'password'
12
+ presently.group_id = 'group_id'
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+ it 'should sets the correct values' do
18
+ notifier.user_name.should == 'user_name'
19
+ notifier.subdomain.should == 'subdomain'
20
+ notifier.password.should == 'password'
21
+ notifier.group_id.should == 'group_id'
22
+
23
+ notifier.on_success.should == true
24
+ notifier.on_warning.should == true
25
+ notifier.on_failure.should == true
26
+ end
27
+
28
+ context 'when using configuration defaults' do
29
+ after { Backup::Configuration::Notifier::Presently.clear_defaults! }
30
+
31
+ it 'should use the configuration defaults' do
32
+ Backup::Configuration::Notifier::Presently.defaults do |presently|
33
+ presently.user_name = 'some_user_name'
34
+ presently.subdomain = 'some_subdomain'
35
+ presently.password = 'some_password'
36
+ presently.group_id = 'some_group_id'
37
+
38
+ presently.on_success = false
39
+ presently.on_warning = false
40
+ presently.on_failure = false
41
+ end
42
+ notifier = Backup::Notifier::Presently.new(model)
43
+ notifier.user_name.should == 'some_user_name'
44
+ notifier.subdomain.should == 'some_subdomain'
45
+ notifier.password.should == 'some_password'
46
+ notifier.group_id.should == 'some_group_id'
47
+
48
+ notifier.on_success.should == false
49
+ notifier.on_warning.should == false
50
+ notifier.on_failure.should == false
51
+ end
52
+
53
+ it 'should override the configuration defaults' do
54
+ Backup::Configuration::Notifier::Presently.defaults do |presently|
55
+ presently.user_name = 'old_user_name'
56
+ presently.subdomain = 'old_subdomain'
57
+ presently.password = 'old_password'
58
+ presently.group_id = 'old_group_id'
59
+
60
+ presently.on_success = true
61
+ presently.on_warning = false
62
+ presently.on_failure = false
63
+ end
64
+ notifier = Backup::Notifier::Presently.new(model) do |presently|
65
+ presently.user_name = 'new_user_name'
66
+ presently.subdomain = 'new_subdomain'
67
+ presently.password = 'new_password'
68
+ presently.group_id = 'new_group_id'
69
+
70
+ presently.on_success = false
71
+ presently.on_warning = true
72
+ presently.on_failure = true
73
+ end
74
+
75
+ notifier.user_name.should == 'new_user_name'
76
+ notifier.subdomain.should == 'new_subdomain'
77
+ notifier.password.should == 'new_password'
78
+ notifier.group_id.should == 'new_group_id'
79
+
80
+ notifier.on_success.should == false
81
+ notifier.on_warning.should == true
82
+ notifier.on_failure.should == true
83
+ end
84
+ end # context 'when using configuration defaults'
85
+ end
86
+
87
+ describe '#notify!' do
88
+ context 'when status is :success' do
89
+ it 'should send Success message' do
90
+ notifier.expects(:send_message).with(
91
+ '[Backup::Success] test label (test_trigger)'
92
+ )
93
+ notifier.send(:notify!, :success)
94
+ end
95
+ end
96
+
97
+ context 'when status is :warning' do
98
+ it 'should send Warning message' do
99
+ notifier.expects(:send_message).with(
100
+ '[Backup::Warning] test label (test_trigger)'
101
+ )
102
+ notifier.send(:notify!, :warning)
103
+ end
104
+ end
105
+
106
+ context 'when status is :failure' do
107
+ it 'should send Failure message' do
108
+ notifier.expects(:send_message).with(
109
+ '[Backup::Failure] test label (test_trigger)'
110
+ )
111
+ notifier.send(:notify!, :failure)
112
+ end
113
+ end
114
+ end # describe '#notify!'
115
+
116
+ describe '#send_message' do
117
+ it 'should send a message' do
118
+ client = mock
119
+ Backup::Notifier::Presently::Client.expects(:new).
120
+ with('subdomain', 'user_name', 'password', 'group_id').
121
+ returns(client)
122
+ client.expects(:update).with('a message')
123
+
124
+ notifier.send(:send_message, 'a message')
125
+ end
126
+ end
127
+ end
128
+
129
+ describe Backup::Notifier::Presently::Client do
130
+ let(:client) do
131
+ Backup::Notifier::Presently::Client.new(
132
+ 'subdomain', 'user_name', 'password', 'group_id'
133
+ )
134
+ end
135
+
136
+ it 'should include HTTParty' do
137
+ Backup::Notifier::Presently::Client.
138
+ included_modules.should include(HTTParty)
139
+ end
140
+
141
+ it 'should setup the proper values' do
142
+ client.subdomain.should == 'subdomain'
143
+ client.user_name.should == 'user_name'
144
+ client.password.should == 'password'
145
+ client.group_id.should == 'group_id'
146
+
147
+ Backup::Notifier::Presently::Client.base_uri.
148
+ should == 'https://subdomain.presently.com'
149
+ Backup::Notifier::Presently::Client.default_options[:basic_auth].
150
+ should == {:username => 'user_name', :password => 'password' }
151
+ end
152
+
153
+ describe '#update' do
154
+ context 'when a group_id is specified' do
155
+ it 'should post the given message with the specified group' do
156
+ Backup::Notifier::Presently::Client.expects(:post).with(
157
+ '/api/twitter/statuses/update.json',
158
+ :body => {
159
+ :status => 'd @group_id a message',
160
+ :source => 'Backup Notifier'
161
+ }
162
+ )
163
+ client.update('a message')
164
+ end
165
+ end
166
+
167
+ context 'when no group_id is specified' do
168
+ before { client.group_id = nil }
169
+ it 'should just post the given message' do
170
+ Backup::Notifier::Presently::Client.expects(:post).with(
171
+ '/api/twitter/statuses/update.json',
172
+ :body => {
173
+ :status => 'a message',
174
+ :source => 'Backup Notifier'
175
+ }
176
+ )
177
+ client.update('a message')
178
+ end
179
+ end
180
+ end
181
+ end