backup 3.0.19 → 3.0.20

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 (188) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +9 -8
  3. data/Gemfile.lock +19 -1
  4. data/Guardfile +13 -9
  5. data/README.md +93 -31
  6. data/backup.gemspec +3 -3
  7. data/bin/backup +6 -283
  8. data/lib/backup.rb +101 -72
  9. data/lib/backup/archive.rb +21 -9
  10. data/lib/backup/binder.rb +22 -0
  11. data/lib/backup/cleaner.rb +36 -0
  12. data/lib/backup/cli/helpers.rb +103 -0
  13. data/lib/backup/cli/utility.rb +308 -0
  14. data/lib/backup/compressor/base.rb +2 -2
  15. data/lib/backup/compressor/pbzip2.rb +76 -0
  16. data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
  17. data/lib/backup/configuration/database/riak.rb +25 -0
  18. data/lib/backup/configuration/encryptor/open_ssl.rb +6 -0
  19. data/lib/backup/configuration/helpers.rb +5 -18
  20. data/lib/backup/configuration/notifier/base.rb +13 -0
  21. data/lib/backup/configuration/notifier/hipchat.rb +41 -0
  22. data/lib/backup/configuration/notifier/mail.rb +38 -0
  23. data/lib/backup/configuration/notifier/prowl.rb +23 -0
  24. data/lib/backup/configuration/storage/cloudfiles.rb +4 -0
  25. data/lib/backup/configuration/storage/dropbox.rb +8 -4
  26. data/lib/backup/database/base.rb +10 -2
  27. data/lib/backup/database/mongodb.rb +16 -19
  28. data/lib/backup/database/mysql.rb +2 -2
  29. data/lib/backup/database/postgresql.rb +2 -2
  30. data/lib/backup/database/redis.rb +15 -7
  31. data/lib/backup/database/riak.rb +45 -0
  32. data/lib/backup/dependency.rb +21 -7
  33. data/lib/backup/encryptor/base.rb +1 -1
  34. data/lib/backup/encryptor/open_ssl.rb +20 -5
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/finder.rb +11 -3
  37. data/lib/backup/logger.rb +121 -82
  38. data/lib/backup/model.rb +103 -44
  39. data/lib/backup/notifier/base.rb +50 -0
  40. data/lib/backup/notifier/campfire.rb +32 -52
  41. data/lib/backup/notifier/hipchat.rb +99 -0
  42. data/lib/backup/notifier/mail.rb +100 -61
  43. data/lib/backup/notifier/presently.rb +31 -40
  44. data/lib/backup/notifier/prowl.rb +73 -0
  45. data/lib/backup/notifier/twitter.rb +29 -39
  46. data/lib/backup/packager.rb +25 -0
  47. data/lib/backup/splitter.rb +62 -0
  48. data/lib/backup/storage/base.rb +178 -18
  49. data/lib/backup/storage/cloudfiles.rb +34 -28
  50. data/lib/backup/storage/dropbox.rb +64 -67
  51. data/lib/backup/storage/ftp.rb +48 -40
  52. data/lib/backup/storage/local.rb +33 -28
  53. data/lib/backup/storage/ninefold.rb +40 -26
  54. data/lib/backup/storage/object.rb +8 -6
  55. data/lib/backup/storage/rsync.rb +61 -51
  56. data/lib/backup/storage/s3.rb +29 -27
  57. data/lib/backup/storage/scp.rb +56 -36
  58. data/lib/backup/storage/sftp.rb +49 -33
  59. data/lib/backup/syncer/base.rb +1 -1
  60. data/lib/backup/syncer/rsync.rb +1 -1
  61. data/lib/backup/template.rb +46 -0
  62. data/lib/backup/version.rb +1 -1
  63. data/spec/archive_spec.rb +34 -9
  64. data/spec/backup_spec.rb +1 -1
  65. data/spec/cli/helpers_spec.rb +35 -0
  66. data/spec/cli/utility_spec.rb +38 -0
  67. data/spec/compressor/bzip2_spec.rb +1 -1
  68. data/spec/compressor/gzip_spec.rb +1 -1
  69. data/spec/compressor/lzma_spec.rb +1 -1
  70. data/spec/compressor/pbzip2_spec.rb +63 -0
  71. data/spec/configuration/base_spec.rb +1 -1
  72. data/spec/configuration/compressor/bzip2_spec.rb +1 -1
  73. data/spec/configuration/compressor/gzip_spec.rb +1 -1
  74. data/spec/configuration/compressor/lzma_spec.rb +1 -1
  75. data/spec/configuration/database/base_spec.rb +1 -1
  76. data/spec/configuration/database/mongodb_spec.rb +1 -1
  77. data/spec/configuration/database/mysql_spec.rb +1 -1
  78. data/spec/configuration/database/postgresql_spec.rb +1 -1
  79. data/spec/configuration/database/redis_spec.rb +1 -1
  80. data/spec/configuration/database/riak_spec.rb +31 -0
  81. data/spec/configuration/encryptor/gpg_spec.rb +1 -1
  82. data/spec/configuration/encryptor/open_ssl_spec.rb +4 -1
  83. data/spec/configuration/notifier/campfire_spec.rb +1 -1
  84. data/spec/configuration/notifier/hipchat_spec.rb +43 -0
  85. data/spec/configuration/notifier/mail_spec.rb +34 -22
  86. data/spec/configuration/notifier/presently_spec.rb +1 -1
  87. data/spec/configuration/notifier/prowl_spec.rb +28 -0
  88. data/spec/configuration/notifier/twitter_spec.rb +1 -1
  89. data/spec/configuration/storage/cloudfiles_spec.rb +19 -16
  90. data/spec/configuration/storage/dropbox_spec.rb +1 -1
  91. data/spec/configuration/storage/ftp_spec.rb +1 -1
  92. data/spec/configuration/storage/local_spec.rb +1 -1
  93. data/spec/configuration/storage/ninefold_spec.rb +1 -1
  94. data/spec/configuration/storage/rsync_spec.rb +1 -1
  95. data/spec/configuration/storage/s3_spec.rb +1 -1
  96. data/spec/configuration/storage/scp_spec.rb +1 -1
  97. data/spec/configuration/storage/sftp_spec.rb +1 -1
  98. data/spec/configuration/syncer/rsync_spec.rb +1 -1
  99. data/spec/configuration/syncer/s3_spec.rb +1 -1
  100. data/spec/database/base_spec.rb +10 -1
  101. data/spec/database/mongodb_spec.rb +34 -7
  102. data/spec/database/mysql_spec.rb +8 -7
  103. data/spec/database/postgresql_spec.rb +8 -7
  104. data/spec/database/redis_spec.rb +39 -9
  105. data/spec/database/riak_spec.rb +50 -0
  106. data/spec/encryptor/gpg_spec.rb +1 -1
  107. data/spec/encryptor/open_ssl_spec.rb +77 -20
  108. data/spec/errors_spec.rb +306 -0
  109. data/spec/finder_spec.rb +91 -0
  110. data/spec/logger_spec.rb +254 -33
  111. data/spec/model_spec.rb +120 -15
  112. data/spec/notifier/campfire_spec.rb +127 -52
  113. data/spec/notifier/hipchat_spec.rb +193 -0
  114. data/spec/notifier/mail_spec.rb +290 -74
  115. data/spec/notifier/presently_spec.rb +290 -73
  116. data/spec/notifier/prowl_spec.rb +149 -0
  117. data/spec/notifier/twitter_spec.rb +106 -41
  118. data/spec/spec_helper.rb +8 -2
  119. data/spec/splitter_spec.rb +71 -0
  120. data/spec/storage/base_spec.rb +280 -19
  121. data/spec/storage/cloudfiles_spec.rb +38 -22
  122. data/spec/storage/dropbox_spec.rb +17 -13
  123. data/spec/storage/ftp_spec.rb +145 -55
  124. data/spec/storage/local_spec.rb +6 -6
  125. data/spec/storage/ninefold_spec.rb +70 -29
  126. data/spec/storage/object_spec.rb +44 -44
  127. data/spec/storage/rsync_spec.rb +186 -63
  128. data/spec/storage/s3_spec.rb +23 -24
  129. data/spec/storage/scp_spec.rb +116 -41
  130. data/spec/storage/sftp_spec.rb +124 -46
  131. data/spec/syncer/rsync_spec.rb +3 -3
  132. data/spec/syncer/s3_spec.rb +1 -1
  133. data/spec/version_spec.rb +1 -1
  134. data/templates/cli/utility/archive +13 -0
  135. data/{lib/templates → templates/cli/utility}/compressor/bzip2 +1 -1
  136. data/{lib/templates → templates/cli/utility}/compressor/gzip +1 -1
  137. data/{lib/templates → templates/cli/utility}/compressor/lzma +0 -0
  138. data/templates/cli/utility/compressor/pbzip2 +7 -0
  139. data/templates/cli/utility/config +31 -0
  140. data/{lib/templates → templates/cli/utility}/database/mongodb +1 -1
  141. data/{lib/templates → templates/cli/utility}/database/mysql +1 -1
  142. data/{lib/templates → templates/cli/utility}/database/postgresql +1 -1
  143. data/{lib/templates → templates/cli/utility}/database/redis +1 -1
  144. data/templates/cli/utility/database/riak +8 -0
  145. data/{lib/templates → templates/cli/utility}/encryptor/gpg +1 -1
  146. data/templates/cli/utility/encryptor/openssl +9 -0
  147. data/templates/cli/utility/model.erb +23 -0
  148. data/{lib/templates → templates/cli/utility}/notifier/campfire +2 -1
  149. data/templates/cli/utility/notifier/hipchat +15 -0
  150. data/{lib/templates → templates/cli/utility}/notifier/mail +6 -1
  151. data/{lib/templates → templates/cli/utility}/notifier/presently +1 -0
  152. data/templates/cli/utility/notifier/prowl +11 -0
  153. data/{lib/templates → templates/cli/utility}/notifier/twitter +2 -1
  154. data/templates/cli/utility/splitter +7 -0
  155. data/templates/cli/utility/storage/cloudfiles +12 -0
  156. data/{lib/templates → templates/cli/utility}/storage/dropbox +1 -1
  157. data/{lib/templates → templates/cli/utility}/storage/ftp +0 -0
  158. data/templates/cli/utility/storage/local +7 -0
  159. data/{lib/templates → templates/cli/utility}/storage/ninefold +1 -1
  160. data/templates/cli/utility/storage/rsync +11 -0
  161. data/{lib/templates → templates/cli/utility}/storage/s3 +0 -2
  162. data/templates/cli/utility/storage/scp +11 -0
  163. data/templates/cli/utility/storage/sftp +11 -0
  164. data/{lib/templates → templates/cli/utility}/syncer/rsync +1 -1
  165. data/{lib/templates → templates/cli/utility}/syncer/s3 +1 -1
  166. data/templates/general/links +11 -0
  167. data/templates/general/version.erb +2 -0
  168. data/templates/notifier/mail/failure.erb +9 -0
  169. data/templates/notifier/mail/success.erb +7 -0
  170. data/templates/notifier/mail/warning.erb +9 -0
  171. data/templates/storage/dropbox/authorization_url.erb +6 -0
  172. data/templates/storage/dropbox/authorized.erb +4 -0
  173. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  174. metadata +81 -45
  175. data/lib/backup/cli.rb +0 -110
  176. data/lib/backup/exception/command_failed.rb +0 -8
  177. data/lib/backup/exception/command_not_found.rb +0 -8
  178. data/lib/backup/notifier/binder.rb +0 -32
  179. data/lib/backup/notifier/templates/notify_failure.erb +0 -33
  180. data/lib/backup/notifier/templates/notify_success.erb +0 -16
  181. data/lib/templates/archive +0 -7
  182. data/lib/templates/encryptor/openssl +0 -8
  183. data/lib/templates/readme +0 -15
  184. data/lib/templates/storage/cloudfiles +0 -11
  185. data/lib/templates/storage/local +0 -7
  186. data/lib/templates/storage/rsync +0 -11
  187. data/lib/templates/storage/scp +0 -11
  188. data/lib/templates/storage/sftp +0 -11
@@ -1,99 +1,316 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/../spec_helper'
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Notifier::Presently do
6
- let(:notifier) do
7
- Backup::Notifier::Presently.new do |presently|
8
- presently.user_name = 'user_name'
9
- presently.subdomain = 'subdomain'
10
- presently.password = 'password'
11
- presently.group_id = 'group_id'
6
+
7
+ describe '#initialize' do
8
+ let(:notifier) do
9
+ Backup::Notifier::Presently.new do |presently|
10
+ presently.user_name = 'user_name'
11
+ presently.subdomain = 'subdomain'
12
+ presently.password = 'password'
13
+ presently.group_id = 'group_id'
14
+ end
12
15
  end
13
- end
14
-
15
- it do
16
- notifier.user_name.should == 'user_name'
17
- notifier.subdomain.should == 'subdomain'
18
- notifier.password.should == 'password'
19
- notifier.group_id.should == 'group_id'
20
-
21
- notifier.on_success.should == true
22
- notifier.on_failure.should == true
23
- end
24
-
25
- describe 'defaults' do
26
- it do
27
- Backup::Configuration::Notifier::Presently.defaults do |presently|
28
- presently.user_name = 'old_user_name'
29
- presently.on_success = false
30
- presently.on_failure = true
16
+
17
+ it 'sets the correct defaults' 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
+ it 'uses and overrides configuration defaults' do
29
+ Backup::Configuration::Notifier::Presently.defaults do |notifier|
30
+ notifier.user_name = 'old_user_name'
31
+ notifier.on_success = false
32
+ notifier.on_failure = true
31
33
  end
32
- notifier = Backup::Notifier::Presently.new do |presently|
33
- presently.user_name = 'new_user_name'
34
+ presently = Backup::Notifier::Presently.new do |notifier|
35
+ notifier.user_name = 'new_user_name'
34
36
  end
35
37
 
36
- notifier.user_name.should == 'new_user_name'
37
- notifier.on_success.should == false
38
- notifier.on_failure.should == true
38
+ presently.user_name.should == 'new_user_name'
39
+ presently.on_success.should == false
40
+ presently.on_warning.should == true
41
+ presently.on_failure.should == true
39
42
  end
40
- end
41
43
 
42
- describe '#initialize' do
43
- it do
44
- Backup::Notifier::Presently.any_instance.expects(:set_defaults!)
45
- Backup::Notifier::Presently.new
44
+ it 'creates a Presently::Client (using HTTParty)' do
45
+ client = notifier.presently_client
46
+ client.should be_an_instance_of Backup::Notifier::Presently::Client
47
+ client.subdomain.should == notifier.subdomain
48
+ client.user_name.should == notifier.user_name
49
+ client.password.should == notifier.password
50
+ client.group_id.should == notifier.group_id
51
+ client.class.base_uri.
52
+ should == "https://#{notifier.subdomain}.presently.com"
53
+ client.class.default_options.should have_key(:basic_auth)
54
+ client.class.default_options[:basic_auth][:username].
55
+ should == notifier.user_name
56
+ client.class.default_options[:basic_auth][:password].
57
+ should == notifier.password
46
58
  end
47
- end
59
+
60
+ end # describe '#initialize'
48
61
 
49
62
  describe '#perform!' do
50
- let(:model) { Backup::Model.new('blah', 'blah') {} }
51
- before do
52
- notifier.on_success = false
53
- notifier.on_failure = false
54
- end
63
+ let(:model) { Backup::Model.new('trigger', 'label') {} }
64
+ let(:post_uri) { '/api/twitter/statuses/update.json' }
65
+ let(:post_body) { { :status => nil, :source => 'Backup Notifier' } }
66
+ let(:message) { '[Backup::%s] label (trigger)' }
55
67
 
56
- context "when successful" do
57
- it do
58
- Backup::Logger.expects(:message).with("Backup::Notifier::Presently started notifying about the process.")
59
- notifier.expects("notify_success!")
60
- notifier.on_success = true
61
- notifier.perform!(model)
68
+ context 'with group_id' do
69
+ let(:notifier) do
70
+ Backup::Notifier::Presently.new do |presently|
71
+ presently.user_name = 'user_name'
72
+ presently.subdomain = 'subdomain'
73
+ presently.password = 'password'
74
+ presently.group_id = 'group_id'
75
+ end
62
76
  end
77
+ let(:client) { notifier.presently_client }
63
78
 
64
- it do
65
- notifier.expects("notify_success!").never
79
+ before do
66
80
  notifier.on_success = false
67
- notifier.perform!(model)
81
+ notifier.on_warning = false
82
+ notifier.on_failure = false
68
83
  end
69
- end
70
84
 
71
- context "when failed" do
72
- it do
73
- Backup::Logger.expects(:message).with("Backup::Notifier::Presently started notifying about the process.")
74
- notifier.expects("notify_failure!")
75
- notifier.on_failure = true
76
- notifier.perform!(model, Exception.new)
85
+ context 'success' do
86
+
87
+ context 'when on_success is true' do
88
+ before { notifier.on_success = true }
89
+
90
+ it 'sends success message' do
91
+ notifier.expects(:log!)
92
+ status = message % 'Success'
93
+ client.class.expects(:post).with(
94
+ post_uri, :body => post_body.merge(
95
+ { :status => "d @#{notifier.group_id} %s" % status }
96
+ )
97
+ )
98
+
99
+ notifier.perform!(model)
100
+ end
101
+ end
102
+
103
+ context 'when on_success is false' do
104
+ it 'sends no message' do
105
+ notifier.expects(:log!).never
106
+ notifier.expects(:notify!).never
107
+ client.expects(:update).never
108
+
109
+ notifier.perform!(model)
110
+ end
111
+ end
112
+
113
+ end # context 'success'
114
+
115
+ context 'warning' do
116
+ before { Backup::Logger.stubs(:has_warnings?).returns(true) }
117
+
118
+ context 'when on_success is true' do
119
+ before { notifier.on_success = true }
120
+
121
+ it 'sends warning message' do
122
+ notifier.expects(:log!)
123
+ status = message % 'Warning'
124
+ client.class.expects(:post).with(
125
+ post_uri, :body => post_body.merge(
126
+ { :status => "d @#{notifier.group_id} %s" % status }
127
+ )
128
+ )
129
+
130
+ notifier.perform!(model)
131
+ end
132
+ end
133
+
134
+ context 'when on_warning is true' do
135
+ before { notifier.on_warning = true }
136
+
137
+ it 'sends warning message' do
138
+ notifier.expects(:log!)
139
+ status = message % 'Warning'
140
+ client.class.expects(:post).with(
141
+ post_uri, :body => post_body.merge(
142
+ { :status => "d @#{notifier.group_id} %s" % status }
143
+ )
144
+ )
145
+
146
+ notifier.perform!(model)
147
+ end
148
+ end
149
+
150
+ context 'when on_success and on_warning are false' do
151
+ it 'sends no message' do
152
+ notifier.expects(:log!).never
153
+ notifier.expects(:notify!).never
154
+ client.expects(:update).never
155
+
156
+ notifier.perform!(model)
157
+ end
158
+ end
159
+
160
+ end # context 'warning'
161
+
162
+ context 'failure' do
163
+
164
+ context 'when on_failure is true' do
165
+ before { notifier.on_failure = true }
166
+
167
+ it 'sends failure message' do
168
+ notifier.expects(:log!)
169
+ status = message % 'Failure'
170
+ client.class.expects(:post).with(
171
+ post_uri, :body => post_body.merge(
172
+ { :status => "d @#{notifier.group_id} %s" % status }
173
+ )
174
+ )
175
+
176
+ notifier.perform!(model, Exception.new)
177
+ end
178
+ end
179
+
180
+ context 'when on_failure is false' do
181
+ it 'sends no message' do
182
+ notifier.expects(:log!).never
183
+ notifier.expects(:notify!).never
184
+ client.expects(:update).never
185
+
186
+ notifier.perform!(model, Exception.new)
187
+ end
188
+ end
189
+
190
+ end # context 'failure'
191
+
192
+ end # context 'with group_id'
193
+
194
+ context 'without group_id' do
195
+ let(:notifier) do
196
+ Backup::Notifier::Presently.new do |presently|
197
+ presently.user_name = 'user_name'
198
+ presently.subdomain = 'subdomain'
199
+ presently.password = 'password'
200
+ presently.group_id = nil
201
+ end
77
202
  end
203
+ let(:client) { notifier.presently_client }
78
204
 
79
- it do
80
- notifier.expects("notify_failure!").never
205
+ before do
206
+ notifier.on_success = false
207
+ notifier.on_warning = false
81
208
  notifier.on_failure = false
82
- notifier.perform!(model, Exception.new)
83
209
  end
84
- end
85
- end
86
210
 
87
- describe Backup::Notifier::Presently::Client do
88
- let(:client) do
89
- Backup::Notifier::Presently::Client.new('subdomain', 'user_name', 'password', 'group_id')
90
- end
211
+ context 'success' do
91
212
 
92
- it do
93
- client.user_name.should == 'user_name'
94
- client.subdomain.should == 'subdomain'
95
- client.password.should == 'password'
96
- client.group_id.should == 'group_id'
97
- end
98
- end
213
+ context 'when on_success is true' do
214
+ before { notifier.on_success = true }
215
+
216
+ it 'sends success message' do
217
+ notifier.expects(:log!)
218
+ client.class.expects(:post).with(
219
+ post_uri, :body => post_body.merge(
220
+ { :status => message % 'Success' }
221
+ )
222
+ )
223
+
224
+ notifier.perform!(model)
225
+ end
226
+ end
227
+
228
+ context 'when on_success is false' do
229
+ it 'sends no message' do
230
+ notifier.expects(:log!).never
231
+ notifier.expects(:notify!).never
232
+ client.expects(:update).never
233
+
234
+ notifier.perform!(model)
235
+ end
236
+ end
237
+
238
+ end # context 'success'
239
+
240
+ context 'warning' do
241
+ before { Backup::Logger.stubs(:has_warnings?).returns(true) }
242
+
243
+ context 'when on_success is true' do
244
+ before { notifier.on_success = true }
245
+
246
+ it 'sends warning message' do
247
+ notifier.expects(:log!)
248
+ client.class.expects(:post).with(
249
+ post_uri, :body => post_body.merge(
250
+ { :status => message % 'Warning' }
251
+ )
252
+ )
253
+
254
+ notifier.perform!(model)
255
+ end
256
+ end
257
+
258
+ context 'when on_warning is true' do
259
+ before { notifier.on_warning = true }
260
+
261
+ it 'sends warning message' do
262
+ notifier.expects(:log!)
263
+ client.class.expects(:post).with(
264
+ post_uri, :body => post_body.merge(
265
+ { :status => message % 'Warning' }
266
+ )
267
+ )
268
+
269
+ notifier.perform!(model)
270
+ end
271
+ end
272
+
273
+ context 'when on_success and on_warning are false' do
274
+ it 'sends no message' do
275
+ notifier.expects(:log!).never
276
+ notifier.expects(:notify!).never
277
+ client.expects(:update).never
278
+
279
+ notifier.perform!(model)
280
+ end
281
+ end
282
+
283
+ end # context 'warning'
284
+
285
+ context 'failure' do
286
+
287
+ context 'when on_failure is true' do
288
+ before { notifier.on_failure = true }
289
+
290
+ it 'sends failure message' do
291
+ notifier.expects(:log!)
292
+ client.class.expects(:post).with(
293
+ post_uri, :body => post_body.merge(
294
+ { :status => message % 'Failure' }
295
+ )
296
+ )
297
+
298
+ notifier.perform!(model, Exception.new)
299
+ end
300
+ end
301
+
302
+ context 'when on_failure is false' do
303
+ it 'sends no message' do
304
+ notifier.expects(:log!).never
305
+ notifier.expects(:notify!).never
306
+ client.expects(:update).never
307
+
308
+ notifier.perform!(model, Exception.new)
309
+ end
310
+ end
311
+
312
+ end # context 'failure'
313
+
314
+ end # context 'without group_id'
315
+ end # describe '#perform!'
99
316
  end
@@ -0,0 +1,149 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Notifier::Prowl do
6
+ let(:notifier) do
7
+ Backup::Notifier::Prowl.new do |prowl|
8
+ prowl.application = 'application'
9
+ prowl.api_key = 'api_key'
10
+ end
11
+ end
12
+
13
+ describe '#initialize' do
14
+ it 'sets the correct defaults' do
15
+ notifier.application = 'application'
16
+ notifier.api_key = 'api_key'
17
+
18
+ notifier.on_success.should == true
19
+ notifier.on_warning.should == true
20
+ notifier.on_failure.should == true
21
+ end
22
+
23
+ it 'uses and overrides configuration defaults' do
24
+ Backup::Configuration::Notifier::Prowl.defaults do |notifier|
25
+ notifier.application = 'my_default_application'
26
+ notifier.on_success = false
27
+ end
28
+ prowl = Backup::Notifier::Prowl.new do |notifier|
29
+ notifier.api_key = 'my_own_api_key'
30
+ end
31
+
32
+ prowl.application.should == 'my_default_application'
33
+ prowl.api_key.should == 'my_own_api_key'
34
+ prowl.on_success.should == false
35
+ prowl.on_warning.should == true
36
+ prowl.on_failure.should == true
37
+ end
38
+
39
+ it 'creates a new Prowler::Application' do
40
+ notifier.prowl_client.should be_an_instance_of Prowler::Application
41
+ notifier.prowl_client.application.should == notifier.application
42
+ notifier.prowl_client.api_key.should == notifier.api_key
43
+ end
44
+ end
45
+
46
+ describe '#perform!' do
47
+ let(:model) { Backup::Model.new('trigger', 'label') {} }
48
+ let(:message_a) { '[Backup::%s]' }
49
+ let(:message_b) { 'label (trigger)' }
50
+
51
+ before do
52
+ notifier.on_success = false
53
+ notifier.on_warning = false
54
+ notifier.on_failure = false
55
+ end
56
+
57
+ context 'success' do
58
+
59
+ context 'when on_success is true' do
60
+ before { notifier.on_success = true }
61
+
62
+ it 'sends success message' do
63
+ notifier.expects(:log!)
64
+ notifier.prowl_client.expects(:notify).
65
+ with(message_a % 'Success', message_b)
66
+
67
+ notifier.perform!(model)
68
+ end
69
+ end
70
+
71
+ context 'when on_success is false' do
72
+ it 'sends no message' do
73
+ notifier.expects(:log!).never
74
+ notifier.expects(:notify!).never
75
+ notifier.prowl_client.expects(:notify).never
76
+
77
+ notifier.perform!(model)
78
+ end
79
+ end
80
+
81
+ end # context 'success'
82
+
83
+ context 'warning' do
84
+ before { Backup::Logger.stubs(:has_warnings?).returns(true) }
85
+
86
+ context 'when on_success is true' do
87
+ before { notifier.on_success = true }
88
+
89
+ it 'sends warning message' do
90
+ notifier.expects(:log!)
91
+ notifier.prowl_client.expects(:notify).
92
+ with(message_a % 'Warning', message_b)
93
+
94
+ notifier.perform!(model)
95
+ end
96
+ end
97
+
98
+ context 'when on_warning is true' do
99
+ before { notifier.on_warning = true }
100
+
101
+ it 'sends warning message' do
102
+ notifier.expects(:log!)
103
+ notifier.prowl_client.expects(:notify).
104
+ with(message_a % 'Warning', message_b)
105
+
106
+ notifier.perform!(model)
107
+ end
108
+ end
109
+
110
+ context 'when on_success and on_warning are false' do
111
+ it 'sends no message' do
112
+ notifier.expects(:log!).never
113
+ notifier.expects(:notify!).never
114
+ notifier.prowl_client.expects(:notify).never
115
+
116
+ notifier.perform!(model)
117
+ end
118
+ end
119
+
120
+ end # context 'warning'
121
+
122
+ context 'failure' do
123
+
124
+ context 'when on_failure is true' do
125
+ before { notifier.on_failure = true }
126
+
127
+ it 'sends failure message' do
128
+ notifier.expects(:log!)
129
+ notifier.prowl_client.expects(:notify).
130
+ with(message_a % 'Failure', message_b)
131
+
132
+ notifier.perform!(model, Exception.new)
133
+ end
134
+ end
135
+
136
+ context 'when on_failure is false' do
137
+ it 'sends no message' do
138
+ notifier.expects(:log!).never
139
+ notifier.expects(:notify!).never
140
+ notifier.prowl_client.expects(:notify).never
141
+
142
+ notifier.perform!(model, Exception.new)
143
+ end
144
+ end
145
+
146
+ end # context 'failure'
147
+
148
+ end # describe '#perform!'
149
+ end