backup 3.0.26 → 3.0.27

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.
@@ -8,25 +8,30 @@ describe 'Backup::Configuration::Helpers' do
8
8
  module Backup
9
9
  class Foo
10
10
  include Backup::Configuration::Helpers
11
- attr_accessor :accessor
11
+ attr_accessor :accessor, :accessor_two
12
12
  attr_reader :reader
13
+
13
14
  attr_deprecate :removed,
14
15
  :version => '1.1'
15
- attr_deprecate :replaced,
16
+
17
+ attr_deprecate :removed_with_message,
16
18
  :version => '1.2',
17
- :replacement => :accessor
18
- attr_deprecate :replaced_with_value,
19
+ :message => 'This has no replacement.'
20
+
21
+ attr_deprecate :removed_with_action,
19
22
  :version => '1.3',
20
- :replacement => :accessor,
21
- :value => 'new_value'
22
- attr_deprecate :replaced_with_lambda,
23
- :version => '1.4',
24
- :replacement => :accessor,
25
- :value => lambda {|val| val ? '1' : '0' }
26
- attr_deprecate :replaced_with_lambda_nil,
23
+ :action => lambda {|klass, val|
24
+ klass.accessor = val ? '1' : '0'
25
+ klass.accessor_two = 'updated'
26
+ }
27
+
28
+ attr_deprecate :removed_with_action_and_message,
27
29
  :version => '1.4',
28
- :replacement => :accessor,
29
- :value => Proc.new {}
30
+ :message => "Updating accessors.",
31
+ :action => lambda {|klass, val|
32
+ klass.accessor = val ? '1' : '0'
33
+ klass.accessor_two = 'updated'
34
+ }
30
35
  end
31
36
  end
32
37
  end
@@ -55,7 +60,8 @@ describe 'Backup::Configuration::Helpers' do
55
60
  it 'should cache the Configuration::Store for the class' do
56
61
  Backup::Foo.instance_variable_get(:@configuration).should be_nil
57
62
  Backup::Foo.defaults.should be(configuration)
58
- Backup::Foo.instance_variable_get(:@configuration).should be(configuration)
63
+ Backup::Foo.instance_variable_get(
64
+ :@configuration).should be(configuration)
59
65
  Backup::Foo.defaults.should be(configuration)
60
66
  end
61
67
  end
@@ -75,7 +81,7 @@ describe 'Backup::Configuration::Helpers' do
75
81
  describe '.deprecations' do
76
82
  it 'should return @deprecations' do
77
83
  Backup::Foo.deprecations.should be_a(Hash)
78
- Backup::Foo.deprecations.keys.count.should be(5)
84
+ Backup::Foo.deprecations.keys.count.should be(4)
79
85
  end
80
86
 
81
87
  it 'should set @deprecations to an empty hash if not set' do
@@ -91,42 +97,40 @@ describe 'Backup::Configuration::Helpers' do
91
97
 
92
98
  it 'should add deprected attributes' do
93
99
  Backup::Foo.send(:attr_deprecate, :attr1)
94
- Backup::Foo.send(:attr_deprecate, :attr2, :version => '1.3')
95
- Backup::Foo.send(:attr_deprecate, :attr3, :replacement => :new_attr3)
100
+ Backup::Foo.send(:attr_deprecate, :attr2,
101
+ :version => '2')
102
+ Backup::Foo.send(:attr_deprecate, :attr3,
103
+ :version => '3',
104
+ :message => 'attr3 message')
96
105
  Backup::Foo.send(:attr_deprecate, :attr4,
97
- :version => '1.4', :replacement => :new_attr4)
98
- Backup::Foo.send(:attr_deprecate, :attr5,
99
- :version => '1.5',
100
- :replacement => :new_attr5,
101
- :value => 'new_value')
106
+ :version => '4',
107
+ :message => 'attr4 message',
108
+ :action => 'attr4 action')
102
109
 
103
110
  Backup::Foo.deprecations.should == {
104
111
  :attr1 => { :version => nil,
105
- :replacement => nil,
106
- :value => nil },
107
- :attr2 => { :version => '1.3',
108
- :replacement => nil,
109
- :value => nil },
110
- :attr3 => { :version => nil,
111
- :replacement => :new_attr3,
112
- :value => nil },
113
- :attr4 => { :version => '1.4',
114
- :replacement => :new_attr4,
115
- :value => nil },
116
- :attr5 => { :version => '1.5',
117
- :replacement => :new_attr5,
118
- :value => 'new_value' }
112
+ :message => nil,
113
+ :action => nil },
114
+ :attr2 => { :version => '2',
115
+ :message => nil,
116
+ :action => nil },
117
+ :attr3 => { :version => '3',
118
+ :message => 'attr3 message',
119
+ :action => nil },
120
+ :attr4 => { :version => '4',
121
+ :message => 'attr4 message',
122
+ :action => 'attr4 action' }
119
123
  }
120
124
  end
121
125
  end
122
126
 
123
127
  describe '.log_deprecation_warning' do
124
- context 'when a replacement is specified' do
128
+ context 'when no message given' do
125
129
  it 'should log a warning that the attribute has been removed' do
126
130
  Backup::Logger.expects(:warn).with do |err|
127
131
  err.message.should ==
128
132
  "ConfigurationError: [DEPRECATION WARNING]\n" +
129
- " Backup::Foo.removed has been deprecated as of backup v.1.1"
133
+ " Backup::Foo#removed has been deprecated as of backup v.1.1"
130
134
  end
131
135
 
132
136
  deprecation = Backup::Foo.deprecations[:removed]
@@ -134,21 +138,22 @@ describe 'Backup::Configuration::Helpers' do
134
138
  end
135
139
  end
136
140
 
137
- context 'when no replacement is specified' do
138
- it 'should log a warning that the attribute has been replaced' do
141
+ context 'when a message is given' do
142
+ it 'should log warning with the message' do
139
143
  Backup::Logger.expects(:warn).with do |err|
140
144
  err.message.should ==
141
145
  "ConfigurationError: [DEPRECATION WARNING]\n" +
142
- " Backup::Foo.replaced has been deprecated as of backup v.1.2\n" +
143
- " This setting has been replaced with:\n" +
144
- " Backup::Foo.accessor"
146
+ " Backup::Foo#removed_with_message has been deprecated " +
147
+ "as of backup v.1.2\n" +
148
+ " This has no replacement."
145
149
  end
146
150
 
147
- deprecation = Backup::Foo.deprecations[:replaced]
148
- Backup::Foo.log_deprecation_warning(:replaced, deprecation)
151
+ deprecation = Backup::Foo.deprecations[:removed_with_message]
152
+ Backup::Foo.log_deprecation_warning(:removed_with_message, deprecation)
153
+
149
154
  end
150
155
  end
151
- end
156
+ end # describe '.log_deprecation_warning'
152
157
 
153
158
  describe '#load_defaults!' do
154
159
  let(:klass) { Backup::Foo.new }
@@ -183,224 +188,60 @@ describe 'Backup::Configuration::Helpers' do
183
188
  end
184
189
  end
185
190
 
186
- describe '#missing_method' do
187
- describe 'instantiating a class when defaults have been set' do
188
- context 'when the missing method is an attribute set operator' do
189
- context 'and the method has been deprecated' do
190
- context 'and the deprecated method has a replacement' do
191
- context 'and a replacement value is specified' do
192
- it 'should set the the replacement value on the replacement' do
193
- Backup::Foo.defaults do |f|
194
- f.replaced_with_value = 'attr_value'
195
- end
196
-
197
- Backup::Logger.expects(:warn).with(
198
- instance_of(Backup::Errors::ConfigurationError)
199
- )
200
- Backup::Logger.expects(:warn).with(
201
- "Backup::Foo.accessor is being set to 'new_value'"
202
- )
203
-
204
- klass = Backup::Foo.new
205
- klass.send(:load_defaults!)
206
- klass.accessor.should == 'new_value'
207
- end
208
- end
209
-
210
- context 'and the replacement value is a lambda' do
211
- it 'should set replacement value using the lambda' do
212
- value = [true, false].shuffle.first
213
- new_value = value ? '1' : '0'
214
-
215
- Backup::Foo.defaults do |f|
216
- f.replaced_with_lambda = value
217
- end
218
-
219
- Backup::Logger.expects(:warn).with(
220
- instance_of(Backup::Errors::ConfigurationError)
221
- )
222
- Backup::Logger.expects(:warn).with(
223
- "Backup::Foo.accessor is being set to '#{ new_value }'"
224
- )
225
-
226
- klass = Backup::Foo.new
227
- klass.send(:load_defaults!)
228
- klass.accessor.should == new_value
229
- end
230
-
231
- it 'should not set the replacement if the lambda returns nil' do
232
- Backup::Foo.defaults do |f|
233
- f.replaced_with_lambda_nil = 'foo'
234
- end
235
-
236
- Backup::Foo.any_instance.expects(:accessor=).never
237
-
238
- Backup::Logger.expects(:warn).with(
239
- instance_of(Backup::Errors::ConfigurationError)
240
- )
241
-
242
- klass = Backup::Foo.new
243
- klass.send(:load_defaults!)
244
- klass.accessor.should be_nil
245
- end
246
- end
247
-
248
- context 'and no replacement value is specified' do
249
- it 'should set the original value on the replacement' do
250
- Backup::Foo.defaults do |f|
251
- f.replaced = 'attr_value'
252
- end
253
-
254
- Backup::Logger.expects(:warn).with(
255
- instance_of(Backup::Errors::ConfigurationError)
256
- )
257
- Backup::Logger.expects(:warn).with(
258
- "Backup::Foo.accessor is being set to 'attr_value'"
259
- )
260
-
261
- klass = Backup::Foo.new
262
- klass.send(:load_defaults!)
263
- klass.accessor.should == 'attr_value'
264
- end
265
- end
266
- end
267
-
268
- context 'and the deprecated method has no replacement' do
269
- it 'should only log a warning' do
270
- Backup::Foo.defaults do |f|
271
- f.removed = 'attr_value'
272
- end
273
-
274
- Backup::Logger.expects(:warn).with(
275
- instance_of(Backup::Errors::ConfigurationError)
276
- )
277
-
278
- klass = Backup::Foo.new
279
- klass.send(:load_defaults!)
280
- klass.accessor.should be_nil
281
- end
282
- end
283
- end
191
+ describe '#method_missing' do
192
+ context 'when the method is a deprecated method' do
193
+ before do
194
+ Backup::Logger.expects(:warn).with(
195
+ instance_of(Backup::Errors::ConfigurationError)
196
+ )
197
+ end
284
198
 
285
- context 'and the method is not a deprecated method' do
286
- it 'should raise a NoMethodError' do
287
- Backup::Foo.defaults do |f|
288
- f.foobar = 'attr_value'
289
- end
199
+ context 'when an :action is specified' do
200
+ it 'should call the :action' do
201
+ value = [true, false].shuffle.first
202
+ expected_value = value ? '1' : '0'
290
203
 
291
- Backup::Logger.expects(:warn).never
204
+ klass = Backup::Foo.new
205
+ klass.removed_with_action = value
292
206
 
293
- klass = Backup::Foo.new
294
- expect do
295
- klass.send(:load_defaults!)
296
- end.to raise_error(NoMethodError)
297
- end
207
+ klass.accessor.should == expected_value
208
+ # lambda additionally sets :accessor_two
209
+ klass.accessor_two.should == 'updated'
298
210
  end
299
211
  end
300
- end # describe 'instantiating a class when defaults have been set'
301
-
302
- describe 'instantiating a new class and directly setting values' do
303
- context 'when the missing method is an attribute set operator' do
304
- context 'and the method has been deprecated' do
305
- context 'and the deprecated method has a replacement' do
306
- context 'and a replacement value is specified' do
307
- it 'should set the the replacement value on the replacement' do
308
- Backup::Logger.expects(:warn).with(
309
- instance_of(Backup::Errors::ConfigurationError)
310
- )
311
- Backup::Logger.expects(:warn).with(
312
- "Backup::Foo.accessor is being set to 'new_value'"
313
- )
314
-
315
- klass = Backup::Foo.new
316
- klass.replaced_with_value = 'attr_value'
317
- klass.accessor.should == 'new_value'
318
- end
319
- end
320
-
321
- context 'and the replacement value is a lambda' do
322
- it 'should set replacement value using the lambda' do
323
- value = [true, false].shuffle.first
324
- new_value = value ? '1' : '0'
325
-
326
- Backup::Logger.expects(:warn).with(
327
- instance_of(Backup::Errors::ConfigurationError)
328
- )
329
- Backup::Logger.expects(:warn).with(
330
- "Backup::Foo.accessor is being set to '#{ new_value }'"
331
- )
332
-
333
- klass = Backup::Foo.new
334
- klass.replaced_with_lambda = value
335
- klass.accessor.should == new_value
336
- end
337
-
338
- it 'should not set the replacement if the lambda returns nil' do
339
- Backup::Foo.any_instance.expects(:accessor=).never
340
-
341
- Backup::Logger.expects(:warn).with(
342
- instance_of(Backup::Errors::ConfigurationError)
343
- )
344
-
345
- klass = Backup::Foo.new
346
- klass.replaced_with_lambda_nil = 'foo'
347
- klass.accessor.should be_nil
348
- end
349
- end
350
-
351
- context 'and no replacement value is specified' do
352
- it 'should set the original value on the replacement' do
353
- Backup::Logger.expects(:warn).with(
354
- instance_of(Backup::Errors::ConfigurationError)
355
- )
356
- Backup::Logger.expects(:warn).with(
357
- "Backup::Foo.accessor is being set to 'attr_value'"
358
- )
359
-
360
- klass = Backup::Foo.new
361
- klass.replaced = 'attr_value'
362
- klass.accessor.should == 'attr_value'
363
- end
364
- end
365
- end
366
-
367
-
368
- context 'and the deprecated method has no replacement' do
369
- it 'should only log a warning' do
370
- Backup::Logger.expects(:warn).with(
371
- instance_of(Backup::Errors::ConfigurationError)
372
- )
373
-
374
- klass = Backup::Foo.new
375
- klass.removed = 'attr_value'
376
- klass.accessor.should be_nil
377
- end
378
- end
379
- end
380
212
 
381
- context 'and the method is not a deprecated method' do
382
- it 'should raise a NoMethodError' do
383
- Backup::Logger.expects(:warn).never
213
+ context 'when no :action is specified' do
214
+ it 'should only log the warning' do
215
+ Backup::Foo.any_instance.expects(:accessor=).never
384
216
 
385
- klass = Backup::Foo.new
386
- expect do
387
- klass.foobar = 'attr_value'
388
- end.to raise_error(NoMethodError)
389
- end
217
+ klass = Backup::Foo.new
218
+ klass.removed = 'foo'
219
+
220
+ klass.accessor.should be_nil
390
221
  end
391
222
  end
223
+ end
392
224
 
393
- context 'when the missing method is not a set operation' do
394
- it 'should raise a NoMethodError' do
395
- Backup::Logger.expects(:warn).never
225
+ context 'when the method is not a deprecated method' do
226
+ it 'should raise a NoMethodError' do
227
+ Backup::Logger.expects(:warn).never
396
228
 
397
- klass = Backup::Foo.new
398
- expect do
399
- klass.removed
400
- end.to raise_error(NoMethodError)
401
- end
229
+ klass = Backup::Foo.new
230
+ expect do
231
+ klass.foobar = 'attr_value'
232
+ end.to raise_error(NoMethodError)
402
233
  end
403
- end # describe 'instantiating a new class and directly setting values'
404
- end
234
+ end
235
+
236
+ context 'when the method is not a set operation' do
237
+ it 'should raise a NoMethodError' do
238
+ Backup::Logger.expects(:warn).never
405
239
 
240
+ klass = Backup::Foo.new
241
+ expect do
242
+ klass.removed
243
+ end.to raise_error(NoMethodError)
244
+ end
245
+ end
246
+ end # describe '#method_missing'
406
247
  end
@@ -473,19 +473,18 @@ describe Backup::Database::MongoDB do
473
473
  end
474
474
 
475
475
  describe 'deprecations' do
476
- after do
477
- Backup::Database::MongoDB.clear_defaults!
478
- end
479
-
480
476
  describe '#utility_path' do
481
477
  before do
482
478
  Backup::Database::MongoDB.any_instance.stubs(:utility)
483
- Backup::Logger.expects(:warn).with(
484
- instance_of(Backup::Errors::ConfigurationError)
485
- )
486
- Backup::Logger.expects(:warn).with(
487
- "Backup::Database::MongoDB.mongodump_utility is being set to 'foo'"
488
- )
479
+ Backup::Logger.expects(:warn).with {|err|
480
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
481
+ err.message.should match(
482
+ /Use MongoDB#mongodump_utility instead/
483
+ )
484
+ }
485
+ end
486
+ after do
487
+ Backup::Database::MongoDB.clear_defaults!
489
488
  end
490
489
 
491
490
  context 'when set directly' do