backup 3.0.23 → 3.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/Gemfile.lock +42 -45
  2. data/Guardfile +7 -4
  3. data/README.md +10 -7
  4. data/backup.gemspec +2 -2
  5. data/lib/backup.rb +27 -97
  6. data/lib/backup/archive.rb +14 -6
  7. data/lib/backup/cli/helpers.rb +52 -49
  8. data/lib/backup/cli/utility.rb +9 -1
  9. data/lib/backup/compressor/base.rb +10 -4
  10. data/lib/backup/compressor/bzip2.rb +22 -26
  11. data/lib/backup/compressor/custom.rb +53 -0
  12. data/lib/backup/compressor/gzip.rb +22 -23
  13. data/lib/backup/compressor/lzma.rb +15 -13
  14. data/lib/backup/compressor/pbzip2.rb +20 -17
  15. data/lib/backup/config.rb +6 -3
  16. data/lib/backup/configuration.rb +33 -0
  17. data/lib/backup/configuration/helpers.rb +114 -28
  18. data/lib/backup/configuration/store.rb +24 -0
  19. data/lib/backup/database/base.rb +0 -6
  20. data/lib/backup/database/mongodb.rb +27 -11
  21. data/lib/backup/database/mysql.rb +19 -14
  22. data/lib/backup/database/postgresql.rb +16 -11
  23. data/lib/backup/database/redis.rb +7 -11
  24. data/lib/backup/database/riak.rb +3 -6
  25. data/lib/backup/dependency.rb +5 -11
  26. data/lib/backup/model.rb +14 -5
  27. data/lib/backup/notifier/campfire.rb +3 -16
  28. data/lib/backup/notifier/hipchat.rb +1 -7
  29. data/lib/backup/notifier/mail.rb +1 -1
  30. data/lib/backup/packager.rb +29 -19
  31. data/lib/backup/pipeline.rb +110 -0
  32. data/lib/backup/storage/dropbox.rb +4 -7
  33. data/lib/backup/syncer/base.rb +8 -4
  34. data/lib/backup/syncer/cloud/base.rb +247 -0
  35. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  36. data/lib/backup/syncer/cloud/s3.rb +68 -0
  37. data/lib/backup/syncer/rsync/base.rb +1 -4
  38. data/lib/backup/syncer/rsync/local.rb +9 -5
  39. data/lib/backup/syncer/rsync/pull.rb +1 -1
  40. data/lib/backup/syncer/rsync/push.rb +10 -5
  41. data/lib/backup/version.rb +1 -1
  42. data/spec-live/.gitignore +6 -0
  43. data/spec-live/README +7 -0
  44. data/spec-live/backups/config.rb +153 -0
  45. data/spec-live/backups/config.yml.template +43 -0
  46. data/spec-live/compressor/custom_spec.rb +30 -0
  47. data/spec-live/compressor/gzip_spec.rb +30 -0
  48. data/spec-live/notifier/mail_spec.rb +85 -0
  49. data/spec-live/spec_helper.rb +85 -0
  50. data/spec-live/storage/dropbox_spec.rb +151 -0
  51. data/spec-live/storage/local_spec.rb +83 -0
  52. data/spec-live/storage/scp_spec.rb +193 -0
  53. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  54. data/spec/archive_spec.rb +86 -31
  55. data/spec/cleaner_spec.rb +8 -0
  56. data/spec/cli/helpers_spec.rb +200 -75
  57. data/spec/cli/utility_spec.rb +11 -3
  58. data/spec/compressor/base_spec.rb +31 -10
  59. data/spec/compressor/bzip2_spec.rb +212 -57
  60. data/spec/compressor/custom_spec.rb +106 -0
  61. data/spec/compressor/gzip_spec.rb +212 -57
  62. data/spec/compressor/lzma_spec.rb +75 -35
  63. data/spec/compressor/pbzip2_spec.rb +93 -52
  64. data/spec/configuration/helpers_spec.rb +406 -0
  65. data/spec/configuration/store_spec.rb +39 -0
  66. data/spec/configuration_spec.rb +62 -0
  67. data/spec/database/base_spec.rb +19 -10
  68. data/spec/database/mongodb_spec.rb +195 -70
  69. data/spec/database/mysql_spec.rb +183 -64
  70. data/spec/database/postgresql_spec.rb +167 -53
  71. data/spec/database/redis_spec.rb +121 -46
  72. data/spec/database/riak_spec.rb +96 -27
  73. data/spec/dependency_spec.rb +2 -0
  74. data/spec/encryptor/base_spec.rb +10 -0
  75. data/spec/encryptor/gpg_spec.rb +29 -13
  76. data/spec/encryptor/open_ssl_spec.rb +40 -21
  77. data/spec/logger_spec.rb +4 -0
  78. data/spec/model_spec.rb +19 -2
  79. data/spec/notifier/base_spec.rb +32 -17
  80. data/spec/notifier/campfire_spec.rb +63 -45
  81. data/spec/notifier/hipchat_spec.rb +79 -56
  82. data/spec/notifier/mail_spec.rb +82 -46
  83. data/spec/notifier/prowl_spec.rb +53 -32
  84. data/spec/notifier/twitter_spec.rb +62 -41
  85. data/spec/packager_spec.rb +95 -36
  86. data/spec/pipeline_spec.rb +259 -0
  87. data/spec/spec_helper.rb +6 -5
  88. data/spec/storage/base_spec.rb +61 -41
  89. data/spec/storage/cloudfiles_spec.rb +69 -45
  90. data/spec/storage/dropbox_spec.rb +158 -36
  91. data/spec/storage/ftp_spec.rb +69 -45
  92. data/spec/storage/local_spec.rb +47 -23
  93. data/spec/storage/ninefold_spec.rb +55 -31
  94. data/spec/storage/rsync_spec.rb +67 -50
  95. data/spec/storage/s3_spec.rb +65 -41
  96. data/spec/storage/scp_spec.rb +65 -41
  97. data/spec/storage/sftp_spec.rb +65 -41
  98. data/spec/syncer/base_spec.rb +91 -4
  99. data/spec/syncer/cloud/base_spec.rb +511 -0
  100. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  101. data/spec/syncer/cloud/s3_spec.rb +174 -0
  102. data/spec/syncer/rsync/base_spec.rb +46 -66
  103. data/spec/syncer/rsync/local_spec.rb +55 -26
  104. data/spec/syncer/rsync/pull_spec.rb +15 -4
  105. data/spec/syncer/rsync/push_spec.rb +59 -52
  106. data/templates/cli/utility/compressor/bzip2 +1 -4
  107. data/templates/cli/utility/compressor/custom +11 -0
  108. data/templates/cli/utility/compressor/gzip +1 -4
  109. data/templates/cli/utility/compressor/lzma +3 -0
  110. data/templates/cli/utility/compressor/pbzip2 +3 -0
  111. data/templates/cli/utility/database/mysql +4 -1
  112. data/templates/cli/utility/syncer/cloud_files +17 -19
  113. data/templates/cli/utility/syncer/s3 +18 -20
  114. metadata +38 -92
  115. data/lib/backup/configuration/base.rb +0 -15
  116. data/lib/backup/configuration/compressor/base.rb +0 -9
  117. data/lib/backup/configuration/compressor/bzip2.rb +0 -23
  118. data/lib/backup/configuration/compressor/gzip.rb +0 -23
  119. data/lib/backup/configuration/compressor/lzma.rb +0 -23
  120. data/lib/backup/configuration/compressor/pbzip2.rb +0 -28
  121. data/lib/backup/configuration/database/base.rb +0 -19
  122. data/lib/backup/configuration/database/mongodb.rb +0 -49
  123. data/lib/backup/configuration/database/mysql.rb +0 -42
  124. data/lib/backup/configuration/database/postgresql.rb +0 -41
  125. data/lib/backup/configuration/database/redis.rb +0 -39
  126. data/lib/backup/configuration/database/riak.rb +0 -29
  127. data/lib/backup/configuration/encryptor/base.rb +0 -9
  128. data/lib/backup/configuration/encryptor/gpg.rb +0 -17
  129. data/lib/backup/configuration/encryptor/open_ssl.rb +0 -32
  130. data/lib/backup/configuration/notifier/base.rb +0 -28
  131. data/lib/backup/configuration/notifier/campfire.rb +0 -25
  132. data/lib/backup/configuration/notifier/hipchat.rb +0 -41
  133. data/lib/backup/configuration/notifier/mail.rb +0 -112
  134. data/lib/backup/configuration/notifier/presently.rb +0 -25
  135. data/lib/backup/configuration/notifier/prowl.rb +0 -23
  136. data/lib/backup/configuration/notifier/twitter.rb +0 -21
  137. data/lib/backup/configuration/storage/base.rb +0 -18
  138. data/lib/backup/configuration/storage/cloudfiles.rb +0 -25
  139. data/lib/backup/configuration/storage/dropbox.rb +0 -58
  140. data/lib/backup/configuration/storage/ftp.rb +0 -29
  141. data/lib/backup/configuration/storage/local.rb +0 -17
  142. data/lib/backup/configuration/storage/ninefold.rb +0 -20
  143. data/lib/backup/configuration/storage/rsync.rb +0 -29
  144. data/lib/backup/configuration/storage/s3.rb +0 -25
  145. data/lib/backup/configuration/storage/scp.rb +0 -25
  146. data/lib/backup/configuration/storage/sftp.rb +0 -25
  147. data/lib/backup/configuration/syncer/base.rb +0 -10
  148. data/lib/backup/configuration/syncer/cloud.rb +0 -23
  149. data/lib/backup/configuration/syncer/cloud_files.rb +0 -30
  150. data/lib/backup/configuration/syncer/rsync/base.rb +0 -28
  151. data/lib/backup/configuration/syncer/rsync/local.rb +0 -11
  152. data/lib/backup/configuration/syncer/rsync/pull.rb +0 -11
  153. data/lib/backup/configuration/syncer/rsync/push.rb +0 -31
  154. data/lib/backup/configuration/syncer/s3.rb +0 -23
  155. data/lib/backup/notifier/presently.rb +0 -88
  156. data/lib/backup/syncer/cloud.rb +0 -187
  157. data/lib/backup/syncer/cloud_files.rb +0 -56
  158. data/lib/backup/syncer/s3.rb +0 -47
  159. data/spec/configuration/base_spec.rb +0 -35
  160. data/spec/configuration/compressor/bzip2_spec.rb +0 -29
  161. data/spec/configuration/compressor/gzip_spec.rb +0 -29
  162. data/spec/configuration/compressor/lzma_spec.rb +0 -29
  163. data/spec/configuration/compressor/pbzip2_spec.rb +0 -32
  164. data/spec/configuration/database/base_spec.rb +0 -17
  165. data/spec/configuration/database/mongodb_spec.rb +0 -56
  166. data/spec/configuration/database/mysql_spec.rb +0 -53
  167. data/spec/configuration/database/postgresql_spec.rb +0 -53
  168. data/spec/configuration/database/redis_spec.rb +0 -50
  169. data/spec/configuration/database/riak_spec.rb +0 -35
  170. data/spec/configuration/encryptor/gpg_spec.rb +0 -26
  171. data/spec/configuration/encryptor/open_ssl_spec.rb +0 -35
  172. data/spec/configuration/notifier/base_spec.rb +0 -32
  173. data/spec/configuration/notifier/campfire_spec.rb +0 -32
  174. data/spec/configuration/notifier/hipchat_spec.rb +0 -44
  175. data/spec/configuration/notifier/mail_spec.rb +0 -71
  176. data/spec/configuration/notifier/presently_spec.rb +0 -35
  177. data/spec/configuration/notifier/prowl_spec.rb +0 -29
  178. data/spec/configuration/notifier/twitter_spec.rb +0 -35
  179. data/spec/configuration/storage/cloudfiles_spec.rb +0 -41
  180. data/spec/configuration/storage/dropbox_spec.rb +0 -38
  181. data/spec/configuration/storage/ftp_spec.rb +0 -44
  182. data/spec/configuration/storage/local_spec.rb +0 -29
  183. data/spec/configuration/storage/ninefold_spec.rb +0 -32
  184. data/spec/configuration/storage/rsync_spec.rb +0 -41
  185. data/spec/configuration/storage/s3_spec.rb +0 -38
  186. data/spec/configuration/storage/scp_spec.rb +0 -41
  187. data/spec/configuration/storage/sftp_spec.rb +0 -41
  188. data/spec/configuration/syncer/cloud_files_spec.rb +0 -44
  189. data/spec/configuration/syncer/rsync/base_spec.rb +0 -33
  190. data/spec/configuration/syncer/rsync/local_spec.rb +0 -10
  191. data/spec/configuration/syncer/rsync/pull_spec.rb +0 -10
  192. data/spec/configuration/syncer/rsync/push_spec.rb +0 -43
  193. data/spec/configuration/syncer/s3_spec.rb +0 -38
  194. data/spec/notifier/presently_spec.rb +0 -181
  195. data/spec/syncer/cloud_files_spec.rb +0 -192
  196. data/spec/syncer/s3_spec.rb +0 -192
  197. data/templates/cli/utility/notifier/presently +0 -13
@@ -20,49 +20,66 @@ describe Backup::Database::PostgreSQL do
20
20
  end
21
21
  end
22
22
 
23
+ it 'should be a subclass of Database::Base' do
24
+ Backup::Database::PostgreSQL.superclass.
25
+ should == Backup::Database::Base
26
+ end
27
+
23
28
  describe '#initialize' do
24
- it 'should read the adapter details correctly' do
25
- db.name.should == 'mydatabase'
26
- db.username.should == 'someuser'
27
- db.password.should == 'secret'
28
- db.host.should == 'localhost'
29
- db.port.should == '123'
30
- db.socket.should == '/pgsql.sock'
31
29
 
32
- db.skip_tables.should == ['logs', 'profiles']
33
- db.only_tables.should == ['users', 'pirates']
34
- db.additional_options.should == ['--single-transaction', '--quick']
35
- db.pg_dump_utility.should == '/path/to/pg_dump'
30
+ it 'should load pre-configured defaults through Base' do
31
+ Backup::Database::PostgreSQL.any_instance.expects(:load_defaults!)
32
+ db
36
33
  end
37
34
 
38
- context 'when options are not set' do
39
- before do
40
- Backup::Database::PostgreSQL.any_instance.expects(:utility).
41
- with(:pg_dump).returns('/real/pg_dump')
35
+ it 'should pass the model reference to Base' do
36
+ db.instance_variable_get(:@model).should == model
37
+ end
38
+
39
+ context 'when no pre-configured defaults have been set' do
40
+ context 'when options are specified' do
41
+ it 'should use the given values' do
42
+ db.name.should == 'mydatabase'
43
+ db.username.should == 'someuser'
44
+ db.password.should == 'secret'
45
+ db.host.should == 'localhost'
46
+ db.port.should == '123'
47
+ db.socket.should == '/pgsql.sock'
48
+
49
+ db.skip_tables.should == ['logs', 'profiles']
50
+ db.only_tables.should == ['users', 'pirates']
51
+ db.additional_options.should == ['--single-transaction', '--quick']
52
+ db.pg_dump_utility.should == '/path/to/pg_dump'
53
+ end
42
54
  end
43
55
 
44
- it 'should use default values' do
45
- db = Backup::Database::PostgreSQL.new(model)
56
+ context 'when options are not specified' do
57
+ before do
58
+ Backup::Database::PostgreSQL.any_instance.expects(:utility).
59
+ with(:pg_dump).returns('/real/pg_dump')
60
+ end
46
61
 
47
- db.name.should be_nil
48
- db.username.should be_nil
49
- db.password.should be_nil
50
- db.host.should be_nil
51
- db.port.should be_nil
52
- db.socket.should be_nil
62
+ it 'should provide default values' do
63
+ db = Backup::Database::PostgreSQL.new(model)
53
64
 
54
- db.skip_tables.should == []
55
- db.only_tables.should == []
56
- db.additional_options.should == []
57
- db.pg_dump_utility.should == '/real/pg_dump'
58
- end
59
- end
65
+ db.name.should be_nil
66
+ db.username.should be_nil
67
+ db.password.should be_nil
68
+ db.host.should be_nil
69
+ db.port.should be_nil
70
+ db.socket.should be_nil
60
71
 
61
- context 'when configuration defaults have been set' do
62
- after { Backup::Configuration::Database::PostgreSQL.clear_defaults! }
72
+ db.skip_tables.should == []
73
+ db.only_tables.should == []
74
+ db.additional_options.should == []
75
+ db.pg_dump_utility.should == '/real/pg_dump'
76
+ end
77
+ end
78
+ end # context 'when no pre-configured defaults have been set'
63
79
 
64
- it 'should use configuration defaults' do
65
- Backup::Configuration::Database::PostgreSQL.defaults do |db|
80
+ context 'when pre-configured defaults have been set' do
81
+ before do
82
+ Backup::Database::PostgreSQL.defaults do |db|
66
83
  db.name = 'db_name'
67
84
  db.username = 'db_username'
68
85
  db.password = 'db_password'
@@ -73,27 +90,52 @@ describe Backup::Database::PostgreSQL do
73
90
  db.skip_tables = ['skip', 'tables']
74
91
  db.only_tables = ['only', 'tables']
75
92
  db.additional_options = ['--add', '--opts']
76
- db.pg_dump_utility = '/default/path/to/pg_dump'
93
+ db.pg_dump_utility = '/default/path/to/pg_dump'
77
94
  end
95
+ end
78
96
 
79
- db = Backup::Database::PostgreSQL.new(model)
80
- db.name.should == 'db_name'
81
- db.username.should == 'db_username'
82
- db.password.should == 'db_password'
83
- db.host.should == 'db_host'
84
- db.port.should == 789
85
- db.socket.should == '/foo.sock'
97
+ after { Backup::Database::PostgreSQL.clear_defaults! }
98
+
99
+ context 'when options are specified' do
100
+ it 'should override the pre-configured defaults' do
101
+ db.name.should == 'mydatabase'
102
+ db.username.should == 'someuser'
103
+ db.password.should == 'secret'
104
+ db.host.should == 'localhost'
105
+ db.port.should == '123'
106
+ db.socket.should == '/pgsql.sock'
107
+
108
+ db.skip_tables.should == ['logs', 'profiles']
109
+ db.only_tables.should == ['users', 'pirates']
110
+ db.additional_options.should == ['--single-transaction', '--quick']
111
+ db.pg_dump_utility.should == '/path/to/pg_dump'
112
+ end
113
+ end
86
114
 
87
- db.skip_tables.should == ['skip', 'tables']
88
- db.only_tables.should == ['only', 'tables']
89
- db.additional_options.should == ['--add', '--opts']
90
- db.pg_dump_utility.should == '/default/path/to/pg_dump'
115
+ context 'when options are not specified' do
116
+ it 'should use the pre-configured defaults' do
117
+ db = Backup::Database::PostgreSQL.new(model)
118
+
119
+ db.name.should == 'db_name'
120
+ db.username.should == 'db_username'
121
+ db.password.should == 'db_password'
122
+ db.host.should == 'db_host'
123
+ db.port.should == 789
124
+ db.socket.should == '/foo.sock'
125
+
126
+ db.skip_tables.should == ['skip', 'tables']
127
+ db.only_tables.should == ['only', 'tables']
128
+ db.additional_options.should == ['--add', '--opts']
129
+ db.pg_dump_utility.should == '/default/path/to/pg_dump'
130
+ end
91
131
  end
92
- end
132
+ end # context 'when no pre-configured defaults have been set'
93
133
  end # describe '#initialize'
94
134
 
95
135
  describe '#perform!' do
96
136
  let(:s) { sequence '' }
137
+ let(:pipeline) { mock }
138
+
97
139
  before do
98
140
  # superclass actions
99
141
  db.expects(:prepare!).in_sequence(s)
@@ -101,17 +143,25 @@ describe Backup::Database::PostgreSQL do
101
143
  db.instance_variable_set(:@dump_path, '/dump/path')
102
144
 
103
145
  db.stubs(:pgdump).returns('pgdump_command')
146
+ Backup::Pipeline.expects(:new).returns(pipeline)
104
147
  end
105
148
 
106
149
  context 'when no compressor is configured' do
107
150
  before do
108
- model.expects(:compressor).in_sequence(s).returns(nil)
151
+ model.expects(:compressor).returns(nil)
109
152
  end
110
153
 
111
154
  it 'should run pgdump without compression' do
112
- db.expects(:run).in_sequence(s).with(
113
- "pgdump_command > '/dump/path/mydatabase.sql'"
155
+ pipeline.expects(:<<).in_sequence(s).with('pgdump_command')
156
+ pipeline.expects(:<<).in_sequence(s).with(
157
+ "cat > '/dump/path/mydatabase.sql'"
158
+ )
159
+ pipeline.expects(:run).in_sequence(s)
160
+ pipeline.expects(:success?).in_sequence(s).returns(true)
161
+ Backup::Logger.expects(:message).in_sequence(s).with(
162
+ 'Database::PostgreSQL Complete!'
114
163
  )
164
+
115
165
  db.perform!
116
166
  end
117
167
  end
@@ -119,18 +169,46 @@ describe Backup::Database::PostgreSQL do
119
169
  context 'when a compressor is configured' do
120
170
  before do
121
171
  compressor = mock
122
- model.expects(:compressor).twice.in_sequence(s).returns(compressor)
123
- compressor.expects(:compress_with).in_sequence(s).yields('gzip', '.gz')
172
+ model.expects(:compressor).twice.returns(compressor)
173
+ compressor.expects(:compress_with).yields('gzip', '.gz')
124
174
  end
125
175
 
126
176
  it 'should run pgdump with compression' do
127
- db.expects(:run).in_sequence(s).with(
128
- "pgdump_command | gzip > '/dump/path/mydatabase.sql.gz'"
177
+ pipeline.expects(:<<).in_sequence(s).with('pgdump_command')
178
+ pipeline.expects(:<<).in_sequence(s).with('gzip')
179
+ pipeline.expects(:<<).in_sequence(s).with(
180
+ "cat > '/dump/path/mydatabase.sql.gz'"
181
+ )
182
+ pipeline.expects(:run).in_sequence(s)
183
+ pipeline.expects(:success?).in_sequence(s).returns(true)
184
+ Backup::Logger.expects(:message).in_sequence(s).with(
185
+ 'Database::PostgreSQL Complete!'
129
186
  )
187
+
130
188
  db.perform!
131
189
  end
132
190
  end
133
191
 
192
+ context 'when pipeline command fails' do
193
+ before do
194
+ model.expects(:compressor).returns(nil)
195
+ pipeline.stubs(:<<)
196
+ pipeline.expects(:run)
197
+ pipeline.expects(:success?).returns(false)
198
+ pipeline.expects(:error_messages).returns('pipeline_errors')
199
+ end
200
+
201
+ it 'should raise an error' do
202
+ expect do
203
+ db.perform!
204
+ end.to raise_error(
205
+ Backup::Errors::Database::PipelineError,
206
+ "Database::PipelineError: Database::PostgreSQL Dump Failed!\n" +
207
+ " pipeline_errors"
208
+ )
209
+ end
210
+ end # context 'when pipeline command fails'
211
+
134
212
  end # describe '#perform!'
135
213
 
136
214
  describe '#pgdump' do
@@ -237,4 +315,40 @@ describe Backup::Database::PostgreSQL do
237
315
  end
238
316
  end
239
317
 
318
+ describe 'deprecations' do
319
+ after do
320
+ Backup::Database::PostgreSQL.clear_defaults!
321
+ end
322
+
323
+ describe '#utility_path' do
324
+ before do
325
+ Backup::Database::PostgreSQL.any_instance.stubs(:utility)
326
+ Backup::Logger.expects(:warn).with(
327
+ instance_of(Backup::Errors::ConfigurationError)
328
+ )
329
+ Backup::Logger.expects(:warn).with(
330
+ "Backup::Database::PostgreSQL.pg_dump_utility is being set to 'foo'"
331
+ )
332
+ end
333
+
334
+ context 'when set directly' do
335
+ it 'should issue a deprecation warning and set the replacement value' do
336
+ postgresql = Backup::Database::PostgreSQL.new(model) do |db|
337
+ db.utility_path = 'foo'
338
+ end
339
+ postgresql.pg_dump_utility.should == 'foo'
340
+ end
341
+ end
342
+
343
+ context 'when set as a default' do
344
+ it 'should issue a deprecation warning and set the replacement value' do
345
+ postgresql = Backup::Database::PostgreSQL.defaults do |db|
346
+ db.utility_path = 'foo'
347
+ end
348
+ postgresql = Backup::Database::PostgreSQL.new(model)
349
+ postgresql.pg_dump_utility.should == 'foo'
350
+ end
351
+ end
352
+ end # describe '#utility_path'
353
+ end
240
354
  end
@@ -19,47 +19,64 @@ describe Backup::Database::Redis do
19
19
  end
20
20
  end
21
21
 
22
+ it 'should be a subclass of Database::Base' do
23
+ Backup::Database::Redis.superclass.
24
+ should == Backup::Database::Base
25
+ end
26
+
22
27
  describe '#initialize' do
23
- it 'should read the adapter details correctly' do
24
- db.name.should == 'mydatabase'
25
- db.path.should == '/var/lib/redis/db/'
26
- db.password.should == 'secret'
27
- db.host.should == 'localhost'
28
- db.port.should == '123'
29
- db.socket.should == '/redis.sock'
30
- db.invoke_save.should == true
31
-
32
- db.additional_options.should == ['--query', '--foo']
33
- db.redis_cli_utility.should == '/path/to/redis-cli'
28
+
29
+ it 'should load pre-configured defaults through Base' do
30
+ Backup::Database::Redis.any_instance.expects(:load_defaults!)
31
+ db
34
32
  end
35
33
 
36
- context 'when options are not set' do
37
- before do
38
- Backup::Database::Redis.any_instance.expects(:utility).
39
- with('redis-cli').returns('/real/redis-cli')
34
+ it 'should pass the model reference to Base' do
35
+ db.instance_variable_get(:@model).should == model
36
+ end
37
+
38
+ context 'when no pre-configured defaults have been set' do
39
+ context 'when options are specified' do
40
+ it 'should use the given values' do
41
+ db.name.should == 'mydatabase'
42
+ db.path.should == '/var/lib/redis/db/'
43
+ db.password.should == 'secret'
44
+ db.host.should == 'localhost'
45
+ db.port.should == '123'
46
+ db.socket.should == '/redis.sock'
47
+ db.invoke_save.should == true
48
+
49
+ db.additional_options.should == ['--query', '--foo']
50
+ db.redis_cli_utility.should == '/path/to/redis-cli'
51
+ end
40
52
  end
41
53
 
42
- it 'should use default values' do
43
- db = Backup::Database::Redis.new(model)
54
+ context 'when options are not specified' do
55
+ before do
56
+ Backup::Database::Redis.any_instance.expects(:utility).
57
+ with('redis-cli').returns('/real/redis-cli')
58
+ end
44
59
 
45
- db.name.should == 'dump'
46
- db.path.should be_nil
47
- db.password.should be_nil
48
- db.host.should be_nil
49
- db.port.should be_nil
50
- db.socket.should be_nil
51
- db.invoke_save.should be_nil
60
+ it 'should provide default values' do
61
+ db = Backup::Database::Redis.new(model)
52
62
 
53
- db.additional_options.should == []
54
- db.redis_cli_utility.should == '/real/redis-cli'
55
- end
56
- end
63
+ db.name.should == 'dump'
64
+ db.path.should be_nil
65
+ db.password.should be_nil
66
+ db.host.should be_nil
67
+ db.port.should be_nil
68
+ db.socket.should be_nil
69
+ db.invoke_save.should be_nil
57
70
 
58
- context 'when configuration defaults have been set' do
59
- after { Backup::Configuration::Database::Redis.clear_defaults! }
71
+ db.additional_options.should == []
72
+ db.redis_cli_utility.should == '/real/redis-cli'
73
+ end
74
+ end
75
+ end # context 'when no pre-configured defaults have been set'
60
76
 
61
- it 'should use configuration defaults' do
62
- Backup::Configuration::Database::Redis.defaults do |db|
77
+ context 'when pre-configured defaults have been set' do
78
+ before do
79
+ Backup::Database::Redis.defaults do |db|
63
80
  db.name = 'db_name'
64
81
  db.path = 'db_path'
65
82
  db.password = 'db_password'
@@ -71,20 +88,42 @@ describe Backup::Database::Redis do
71
88
  db.additional_options = ['--add', '--opts']
72
89
  db.redis_cli_utility = '/default/path/to/redis-cli'
73
90
  end
91
+ end
74
92
 
75
- db = Backup::Database::Redis.new(model)
76
- db.name.should == 'db_name'
77
- db.path.should == 'db_path'
78
- db.password.should == 'db_password'
79
- db.host.should == 'db_host'
80
- db.port.should == 789
81
- db.socket.should == '/foo.sock'
82
- db.invoke_save.should == true
83
-
84
- db.additional_options.should == ['--add', '--opts']
85
- db.redis_cli_utility.should == '/default/path/to/redis-cli'
93
+ after { Backup::Database::Redis.clear_defaults! }
94
+
95
+ context 'when options are specified' do
96
+ it 'should override the pre-configured defaults' do
97
+ db.name.should == 'mydatabase'
98
+ db.path.should == '/var/lib/redis/db/'
99
+ db.password.should == 'secret'
100
+ db.host.should == 'localhost'
101
+ db.port.should == '123'
102
+ db.socket.should == '/redis.sock'
103
+ db.invoke_save.should == true
104
+
105
+ db.additional_options.should == ['--query', '--foo']
106
+ db.redis_cli_utility.should == '/path/to/redis-cli'
107
+ end
86
108
  end
87
- end
109
+
110
+ context 'when options are not specified' do
111
+ it 'should use the pre-configured defaults' do
112
+ db = Backup::Database::Redis.new(model)
113
+
114
+ db.name.should == 'db_name'
115
+ db.path.should == 'db_path'
116
+ db.password.should == 'db_password'
117
+ db.host.should == 'db_host'
118
+ db.port.should == 789
119
+ db.socket.should == '/foo.sock'
120
+ db.invoke_save.should == true
121
+
122
+ db.additional_options.should == ['--add', '--opts']
123
+ db.redis_cli_utility.should == '/default/path/to/redis-cli'
124
+ end
125
+ end
126
+ end # context 'when no pre-configured defaults have been set'
88
127
  end # describe '#initialize'
89
128
 
90
129
  describe '#perform!' do
@@ -197,11 +236,11 @@ describe Backup::Database::Redis do
197
236
  File.expects(:exist?).returns(false)
198
237
  expect do
199
238
  db.send(:copy!)
200
- end.to raise_error do |err|
239
+ end.to raise_error {|err|
201
240
  err.should be_an_instance_of Backup::Errors::Database::Redis::NotFoundError
202
241
  err.message.should match(/Redis database dump not found/)
203
242
  err.message.should match(/File path was #{src_path}/)
204
- end
243
+ }
205
244
  end
206
245
  end
207
246
  end # describe '#copy!'
@@ -257,4 +296,40 @@ describe Backup::Database::Redis do
257
296
  end
258
297
  end
259
298
 
299
+ describe 'deprecations' do
300
+ after do
301
+ Backup::Database::Redis.clear_defaults!
302
+ end
303
+
304
+ describe '#utility_path' do
305
+ before do
306
+ Backup::Database::Redis.any_instance.stubs(:utility)
307
+ Backup::Logger.expects(:warn).with(
308
+ instance_of(Backup::Errors::ConfigurationError)
309
+ )
310
+ Backup::Logger.expects(:warn).with(
311
+ "Backup::Database::Redis.redis_cli_utility is being set to 'foo'"
312
+ )
313
+ end
314
+
315
+ context 'when set directly' do
316
+ it 'should issue a deprecation warning and set the replacement value' do
317
+ redis = Backup::Database::Redis.new(model) do |db|
318
+ db.utility_path = 'foo'
319
+ end
320
+ redis.redis_cli_utility.should == 'foo'
321
+ end
322
+ end
323
+
324
+ context 'when set as a default' do
325
+ it 'should issue a deprecation warning and set the replacement value' do
326
+ redis = Backup::Database::Redis.defaults do |db|
327
+ db.utility_path = 'foo'
328
+ end
329
+ redis = Backup::Database::Redis.new(model)
330
+ redis.redis_cli_utility.should == 'foo'
331
+ end
332
+ end
333
+ end # describe '#utility_path'
334
+ end
260
335
  end