backup 3.0.23 → 3.0.24
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +42 -45
- data/Guardfile +7 -4
- data/README.md +10 -7
- data/backup.gemspec +2 -2
- data/lib/backup.rb +27 -97
- data/lib/backup/archive.rb +14 -6
- data/lib/backup/cli/helpers.rb +52 -49
- data/lib/backup/cli/utility.rb +9 -1
- data/lib/backup/compressor/base.rb +10 -4
- data/lib/backup/compressor/bzip2.rb +22 -26
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +22 -23
- data/lib/backup/compressor/lzma.rb +15 -13
- data/lib/backup/compressor/pbzip2.rb +20 -17
- data/lib/backup/config.rb +6 -3
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +114 -28
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +0 -6
- data/lib/backup/database/mongodb.rb +27 -11
- data/lib/backup/database/mysql.rb +19 -14
- data/lib/backup/database/postgresql.rb +16 -11
- data/lib/backup/database/redis.rb +7 -11
- data/lib/backup/database/riak.rb +3 -6
- data/lib/backup/dependency.rb +5 -11
- data/lib/backup/model.rb +14 -5
- data/lib/backup/notifier/campfire.rb +3 -16
- data/lib/backup/notifier/hipchat.rb +1 -7
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/packager.rb +29 -19
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/storage/dropbox.rb +4 -7
- data/lib/backup/syncer/base.rb +8 -4
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +1 -4
- data/lib/backup/syncer/rsync/local.rb +9 -5
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +10 -5
- data/lib/backup/version.rb +1 -1
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +153 -0
- data/spec-live/backups/config.yml.template +43 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/notifier/mail_spec.rb +85 -0
- data/spec-live/spec_helper.rb +85 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +86 -31
- data/spec/cleaner_spec.rb +8 -0
- data/spec/cli/helpers_spec.rb +200 -75
- data/spec/cli/utility_spec.rb +11 -3
- data/spec/compressor/base_spec.rb +31 -10
- data/spec/compressor/bzip2_spec.rb +212 -57
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +212 -57
- data/spec/compressor/lzma_spec.rb +75 -35
- data/spec/compressor/pbzip2_spec.rb +93 -52
- data/spec/configuration/helpers_spec.rb +406 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +19 -10
- data/spec/database/mongodb_spec.rb +195 -70
- data/spec/database/mysql_spec.rb +183 -64
- data/spec/database/postgresql_spec.rb +167 -53
- data/spec/database/redis_spec.rb +121 -46
- data/spec/database/riak_spec.rb +96 -27
- data/spec/dependency_spec.rb +2 -0
- data/spec/encryptor/base_spec.rb +10 -0
- data/spec/encryptor/gpg_spec.rb +29 -13
- data/spec/encryptor/open_ssl_spec.rb +40 -21
- data/spec/logger_spec.rb +4 -0
- data/spec/model_spec.rb +19 -2
- data/spec/notifier/base_spec.rb +32 -17
- data/spec/notifier/campfire_spec.rb +63 -45
- data/spec/notifier/hipchat_spec.rb +79 -56
- data/spec/notifier/mail_spec.rb +82 -46
- data/spec/notifier/prowl_spec.rb +53 -32
- data/spec/notifier/twitter_spec.rb +62 -41
- data/spec/packager_spec.rb +95 -36
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +6 -5
- data/spec/storage/base_spec.rb +61 -41
- data/spec/storage/cloudfiles_spec.rb +69 -45
- data/spec/storage/dropbox_spec.rb +158 -36
- data/spec/storage/ftp_spec.rb +69 -45
- data/spec/storage/local_spec.rb +47 -23
- data/spec/storage/ninefold_spec.rb +55 -31
- data/spec/storage/rsync_spec.rb +67 -50
- data/spec/storage/s3_spec.rb +65 -41
- data/spec/storage/scp_spec.rb +65 -41
- data/spec/storage/sftp_spec.rb +65 -41
- data/spec/syncer/base_spec.rb +91 -4
- data/spec/syncer/cloud/base_spec.rb +511 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +46 -66
- data/spec/syncer/rsync/local_spec.rb +55 -26
- data/spec/syncer/rsync/pull_spec.rb +15 -4
- data/spec/syncer/rsync/push_spec.rb +59 -52
- data/templates/cli/utility/compressor/bzip2 +1 -4
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +1 -4
- data/templates/cli/utility/compressor/lzma +3 -0
- data/templates/cli/utility/compressor/pbzip2 +3 -0
- data/templates/cli/utility/database/mysql +4 -1
- data/templates/cli/utility/syncer/cloud_files +17 -19
- data/templates/cli/utility/syncer/s3 +18 -20
- metadata +38 -92
- data/lib/backup/configuration/base.rb +0 -15
- data/lib/backup/configuration/compressor/base.rb +0 -9
- data/lib/backup/configuration/compressor/bzip2.rb +0 -23
- data/lib/backup/configuration/compressor/gzip.rb +0 -23
- data/lib/backup/configuration/compressor/lzma.rb +0 -23
- data/lib/backup/configuration/compressor/pbzip2.rb +0 -28
- data/lib/backup/configuration/database/base.rb +0 -19
- data/lib/backup/configuration/database/mongodb.rb +0 -49
- data/lib/backup/configuration/database/mysql.rb +0 -42
- data/lib/backup/configuration/database/postgresql.rb +0 -41
- data/lib/backup/configuration/database/redis.rb +0 -39
- data/lib/backup/configuration/database/riak.rb +0 -29
- data/lib/backup/configuration/encryptor/base.rb +0 -9
- data/lib/backup/configuration/encryptor/gpg.rb +0 -17
- data/lib/backup/configuration/encryptor/open_ssl.rb +0 -32
- data/lib/backup/configuration/notifier/base.rb +0 -28
- data/lib/backup/configuration/notifier/campfire.rb +0 -25
- data/lib/backup/configuration/notifier/hipchat.rb +0 -41
- data/lib/backup/configuration/notifier/mail.rb +0 -112
- data/lib/backup/configuration/notifier/presently.rb +0 -25
- data/lib/backup/configuration/notifier/prowl.rb +0 -23
- data/lib/backup/configuration/notifier/twitter.rb +0 -21
- data/lib/backup/configuration/storage/base.rb +0 -18
- data/lib/backup/configuration/storage/cloudfiles.rb +0 -25
- data/lib/backup/configuration/storage/dropbox.rb +0 -58
- data/lib/backup/configuration/storage/ftp.rb +0 -29
- data/lib/backup/configuration/storage/local.rb +0 -17
- data/lib/backup/configuration/storage/ninefold.rb +0 -20
- data/lib/backup/configuration/storage/rsync.rb +0 -29
- data/lib/backup/configuration/storage/s3.rb +0 -25
- data/lib/backup/configuration/storage/scp.rb +0 -25
- data/lib/backup/configuration/storage/sftp.rb +0 -25
- data/lib/backup/configuration/syncer/base.rb +0 -10
- data/lib/backup/configuration/syncer/cloud.rb +0 -23
- data/lib/backup/configuration/syncer/cloud_files.rb +0 -30
- data/lib/backup/configuration/syncer/rsync/base.rb +0 -28
- data/lib/backup/configuration/syncer/rsync/local.rb +0 -11
- data/lib/backup/configuration/syncer/rsync/pull.rb +0 -11
- data/lib/backup/configuration/syncer/rsync/push.rb +0 -31
- data/lib/backup/configuration/syncer/s3.rb +0 -23
- data/lib/backup/notifier/presently.rb +0 -88
- data/lib/backup/syncer/cloud.rb +0 -187
- data/lib/backup/syncer/cloud_files.rb +0 -56
- data/lib/backup/syncer/s3.rb +0 -47
- data/spec/configuration/base_spec.rb +0 -35
- data/spec/configuration/compressor/bzip2_spec.rb +0 -29
- data/spec/configuration/compressor/gzip_spec.rb +0 -29
- data/spec/configuration/compressor/lzma_spec.rb +0 -29
- data/spec/configuration/compressor/pbzip2_spec.rb +0 -32
- data/spec/configuration/database/base_spec.rb +0 -17
- data/spec/configuration/database/mongodb_spec.rb +0 -56
- data/spec/configuration/database/mysql_spec.rb +0 -53
- data/spec/configuration/database/postgresql_spec.rb +0 -53
- data/spec/configuration/database/redis_spec.rb +0 -50
- data/spec/configuration/database/riak_spec.rb +0 -35
- data/spec/configuration/encryptor/gpg_spec.rb +0 -26
- data/spec/configuration/encryptor/open_ssl_spec.rb +0 -35
- data/spec/configuration/notifier/base_spec.rb +0 -32
- data/spec/configuration/notifier/campfire_spec.rb +0 -32
- data/spec/configuration/notifier/hipchat_spec.rb +0 -44
- data/spec/configuration/notifier/mail_spec.rb +0 -71
- data/spec/configuration/notifier/presently_spec.rb +0 -35
- data/spec/configuration/notifier/prowl_spec.rb +0 -29
- data/spec/configuration/notifier/twitter_spec.rb +0 -35
- data/spec/configuration/storage/cloudfiles_spec.rb +0 -41
- data/spec/configuration/storage/dropbox_spec.rb +0 -38
- data/spec/configuration/storage/ftp_spec.rb +0 -44
- data/spec/configuration/storage/local_spec.rb +0 -29
- data/spec/configuration/storage/ninefold_spec.rb +0 -32
- data/spec/configuration/storage/rsync_spec.rb +0 -41
- data/spec/configuration/storage/s3_spec.rb +0 -38
- data/spec/configuration/storage/scp_spec.rb +0 -41
- data/spec/configuration/storage/sftp_spec.rb +0 -41
- data/spec/configuration/syncer/cloud_files_spec.rb +0 -44
- data/spec/configuration/syncer/rsync/base_spec.rb +0 -33
- data/spec/configuration/syncer/rsync/local_spec.rb +0 -10
- data/spec/configuration/syncer/rsync/pull_spec.rb +0 -10
- data/spec/configuration/syncer/rsync/push_spec.rb +0 -43
- data/spec/configuration/syncer/s3_spec.rb +0 -38
- data/spec/notifier/presently_spec.rb +0 -181
- data/spec/syncer/cloud_files_spec.rb +0 -192
- data/spec/syncer/s3_spec.rb +0 -192
- data/templates/cli/utility/notifier/presently +0 -13
@@ -0,0 +1,406 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Configuration::Helpers' do
|
6
|
+
|
7
|
+
before do
|
8
|
+
module Backup
|
9
|
+
class Foo
|
10
|
+
include Backup::Configuration::Helpers
|
11
|
+
attr_accessor :accessor
|
12
|
+
attr_reader :reader
|
13
|
+
attr_deprecate :removed,
|
14
|
+
:version => '1.1'
|
15
|
+
attr_deprecate :replaced,
|
16
|
+
:version => '1.2',
|
17
|
+
:replacement => :accessor
|
18
|
+
attr_deprecate :replaced_with_value,
|
19
|
+
: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,
|
27
|
+
:version => '1.4',
|
28
|
+
:replacement => :accessor,
|
29
|
+
:value => Proc.new {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
Backup.send(:remove_const, 'Foo')
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.defaults' do
|
39
|
+
let(:configuration) { mock }
|
40
|
+
|
41
|
+
before do
|
42
|
+
Backup::Configuration::Store.expects(:new).once.returns(configuration)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return the Configuration::Store for the class' do
|
46
|
+
Backup::Foo.defaults.should be(configuration)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should yield the Configuration::Store for the class' do
|
50
|
+
Backup::Foo.defaults do |config|
|
51
|
+
config.should be(configuration)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should cache the Configuration::Store for the class' do
|
56
|
+
Backup::Foo.instance_variable_get(:@configuration).should be_nil
|
57
|
+
Backup::Foo.defaults.should be(configuration)
|
58
|
+
Backup::Foo.instance_variable_get(:@configuration).should be(configuration)
|
59
|
+
Backup::Foo.defaults.should be(configuration)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.clear_defaults!' do
|
64
|
+
it 'should clear all defaults set' do
|
65
|
+
Backup::Foo.defaults do |config|
|
66
|
+
config.accessor = 'foo'
|
67
|
+
end
|
68
|
+
Backup::Foo.defaults.accessor.should == 'foo'
|
69
|
+
|
70
|
+
Backup::Foo.clear_defaults!
|
71
|
+
Backup::Foo.defaults.accessor.should be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '.deprecations' do
|
76
|
+
it 'should return @deprecations' do
|
77
|
+
Backup::Foo.deprecations.should be_a(Hash)
|
78
|
+
Backup::Foo.deprecations.keys.count.should be(5)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should set @deprecations to an empty hash if not set' do
|
82
|
+
Backup::Foo.send(:remove_instance_variable, :@deprecations)
|
83
|
+
Backup::Foo.deprecations.should == {}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.attr_deprecate' do
|
88
|
+
before do
|
89
|
+
Backup::Foo.send(:remove_instance_variable, :@deprecations)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should add deprected attributes' do
|
93
|
+
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)
|
96
|
+
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')
|
102
|
+
|
103
|
+
Backup::Foo.deprecations.should == {
|
104
|
+
: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' }
|
119
|
+
}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.log_deprecation_warning' do
|
124
|
+
context 'when a replacement is specified' do
|
125
|
+
it 'should log a warning that the attribute has been removed' do
|
126
|
+
Backup::Logger.expects(:warn).with do |err|
|
127
|
+
err.message.should ==
|
128
|
+
"ConfigurationError: [DEPRECATION WARNING]\n" +
|
129
|
+
" Backup::Foo.removed has been deprecated as of backup v.1.1"
|
130
|
+
end
|
131
|
+
|
132
|
+
deprecation = Backup::Foo.deprecations[:removed]
|
133
|
+
Backup::Foo.log_deprecation_warning(:removed, deprecation)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when no replacement is specified' do
|
138
|
+
it 'should log a warning that the attribute has been replaced' do
|
139
|
+
Backup::Logger.expects(:warn).with do |err|
|
140
|
+
err.message.should ==
|
141
|
+
"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"
|
145
|
+
end
|
146
|
+
|
147
|
+
deprecation = Backup::Foo.deprecations[:replaced]
|
148
|
+
Backup::Foo.log_deprecation_warning(:replaced, deprecation)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '#load_defaults!' do
|
154
|
+
let(:klass) { Backup::Foo.new }
|
155
|
+
|
156
|
+
it 'should load default values set for the class' do
|
157
|
+
Backup::Foo.defaults do |config|
|
158
|
+
config.accessor = 'foo'
|
159
|
+
end
|
160
|
+
|
161
|
+
klass.send(:load_defaults!)
|
162
|
+
klass.accessor.should == 'foo'
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should raise an error if defaults are set for attribute readers' do
|
166
|
+
Backup::Foo.defaults do |config|
|
167
|
+
config.reader = 'foo'
|
168
|
+
end
|
169
|
+
|
170
|
+
expect do
|
171
|
+
klass.send(:load_defaults!)
|
172
|
+
end.to raise_error(NoMethodError, /Backup::Foo/)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should raise an error if defaults were set for invalid accessors' do
|
176
|
+
Backup::Foo.defaults do |config|
|
177
|
+
config.foobar = 'foo'
|
178
|
+
end
|
179
|
+
|
180
|
+
expect do
|
181
|
+
klass.send(:load_defaults!)
|
182
|
+
end.to raise_error(NoMethodError, /Backup::Foo/)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
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
|
284
|
+
|
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
|
290
|
+
|
291
|
+
Backup::Logger.expects(:warn).never
|
292
|
+
|
293
|
+
klass = Backup::Foo.new
|
294
|
+
expect do
|
295
|
+
klass.send(:load_defaults!)
|
296
|
+
end.to raise_error(NoMethodError)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
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
|
+
|
381
|
+
context 'and the method is not a deprecated method' do
|
382
|
+
it 'should raise a NoMethodError' do
|
383
|
+
Backup::Logger.expects(:warn).never
|
384
|
+
|
385
|
+
klass = Backup::Foo.new
|
386
|
+
expect do
|
387
|
+
klass.foobar = 'attr_value'
|
388
|
+
end.to raise_error(NoMethodError)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
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
|
396
|
+
|
397
|
+
klass = Backup::Foo.new
|
398
|
+
expect do
|
399
|
+
klass.removed
|
400
|
+
end.to raise_error(NoMethodError)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end # describe 'instantiating a new class and directly setting values'
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Configuration::Store' do
|
6
|
+
let(:store) { Backup::Configuration::Store.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
store.foo = 'one'
|
10
|
+
store.bar = 'two'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should be a subclass of OpenStruct' do
|
14
|
+
Backup::Configuration::Store.superclass.should == OpenStruct
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return nil for unset attributes' do
|
18
|
+
store.foobar.should be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#_attribues' do
|
22
|
+
it 'should return an array of attribute names' do
|
23
|
+
store._attributes.should be_an Array
|
24
|
+
store._attributes.count.should be(2)
|
25
|
+
store._attributes.should include(:foo, :bar)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#reset!' do
|
30
|
+
it 'should clear all attributes set' do
|
31
|
+
store.reset!
|
32
|
+
store._attributes.should be_an Array
|
33
|
+
store._attributes.should be_empty
|
34
|
+
store.foo.should be_nil
|
35
|
+
store.bar.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe 'Backup::Configuration' do
|
6
|
+
|
7
|
+
after do
|
8
|
+
Backup::Configuration.send(:remove_const, 'Foo')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should create modules for missing constants' do
|
12
|
+
Backup::Configuration::Foo.class.should == Module
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'a generated module' do
|
16
|
+
|
17
|
+
before do
|
18
|
+
module Backup
|
19
|
+
class Foo; end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
Backup.send(:remove_const, 'Foo')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create modules for missing constants' do
|
28
|
+
Backup::Configuration::Foo::A::B.class.should == Module
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should pass calls to .defaults to the proper class' do
|
32
|
+
Backup::Logger.expects(:warn)
|
33
|
+
Backup::Foo.expects(:defaults)
|
34
|
+
Backup::Configuration::Foo.defaults
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should pass a given block to .defaults to the proper class' do
|
38
|
+
Backup::Logger.expects(:warn)
|
39
|
+
configuration = mock
|
40
|
+
Backup::Foo.expects(:defaults).yields(configuration)
|
41
|
+
configuration.expects(:foo=).with('bar')
|
42
|
+
|
43
|
+
Backup::Configuration::Foo.defaults do |config|
|
44
|
+
config.foo = 'bar'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should log a deprecation warning' do
|
49
|
+
Backup::Foo.stubs(:defaults)
|
50
|
+
Backup::Logger.expects(:warn).with do |err|
|
51
|
+
err.message.should ==
|
52
|
+
"ConfigurationError: [DEPRECATION WARNING]\n" +
|
53
|
+
" Backup::Configuration::Foo.defaults is being deprecated.\n" +
|
54
|
+
" To set pre-configured defaults for Backup::Foo, use:\n" +
|
55
|
+
" Backup::Foo.defaults"
|
56
|
+
end
|
57
|
+
Backup::Configuration::Foo.defaults
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|