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
@@ -86,6 +86,10 @@ describe 'Backup::CLI::Utility' do
86
86
  FileUtils.unstub(:touch)
87
87
  end
88
88
 
89
+ after do
90
+ Backup::Config.send(:reset!)
91
+ end
92
+
89
93
  context 'when given a config_path' do
90
94
  context 'when no config file exists' do
91
95
  it 'should create both a config and a model under the given path' do
@@ -190,8 +194,8 @@ describe 'Backup::CLI::Utility' do
190
194
  [--storages=STORAGES] # (cloud_files, dropbox, ftp, local, ninefold, rsync, s3, scp, sftp)
191
195
  [--syncers=SYNCERS] # (cloud_files, rsync_local, rsync_pull, rsync_push, s3)
192
196
  [--encryptors=ENCRYPTORS] # (gpg, openssl)
193
- [--compressors=COMPRESSORS] # (bzip2, gzip, lzma, pbzip2)
194
- [--notifiers=NOTIFIERS] # (campfire, hipchat, mail, presently, prowl, twitter)
197
+ [--compressors=COMPRESSORS] # (bzip2, custom, gzip, lzma, pbzip2)
198
+ [--notifiers=NOTIFIERS] # (campfire, hipchat, mail, prowl, twitter)
195
199
  [--archives]
196
200
  [--splitter] # use `--no-splitter` to disable
197
201
  # Default: true
@@ -213,7 +217,7 @@ describe 'Backup::CLI::Utility' do
213
217
 
214
218
  output_lines.sort.should == expected_lines.sort
215
219
  end
216
- end
220
+ end # describe '#generate:model'
217
221
 
218
222
  describe '#generate:config' do
219
223
  before do
@@ -221,6 +225,10 @@ describe 'Backup::CLI::Utility' do
221
225
  FileUtils.unstub(:touch)
222
226
  end
223
227
 
228
+ after do
229
+ Backup::Config.send(:reset!)
230
+ end
231
+
224
232
  context 'when given a config_path' do
225
233
  it 'should create a config file in the given path' do
226
234
  Dir.mktmpdir do |path|
@@ -3,29 +3,50 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Compressor::Base do
6
- let(:base) { Backup::Compressor::Base.new }
6
+ let(:compressor) { Backup::Compressor::Base.new }
7
7
 
8
- describe '#initialize' do
9
- it 'should load defaults' do
10
- Backup::Compressor::Base.any_instance.expects(:load_defaults!)
11
- base
8
+ it 'should include CLI::Helpers' do
9
+ Backup::Compressor::Base.
10
+ include?(Backup::CLI::Helpers).should be_true
11
+ end
12
+
13
+ it 'should include Configuration::Helpers' do
14
+ Backup::Compressor::Base.
15
+ include?(Backup::Configuration::Helpers).should be_true
16
+ end
17
+
18
+ describe '#compress_with' do
19
+ it 'should yield the compressor command and extension' do
20
+ compressor.instance_variable_set(:@cmd, 'compressor command')
21
+ compressor.instance_variable_set(:@ext, 'compressor extension')
22
+
23
+ compressor.expects(:log!)
24
+
25
+ compressor.compress_with do |cmd, ext|
26
+ cmd.should == 'compressor command'
27
+ ext.should == 'compressor extension'
28
+ end
12
29
  end
13
30
  end
14
31
 
15
32
  describe '#compressor_name' do
16
33
  it 'should return class name with Backup namespace removed' do
17
- base.send(:compressor_name).should == 'Compressor::Base'
34
+ compressor.send(:compressor_name).should == 'Compressor::Base'
18
35
  end
19
36
  end
20
37
 
21
38
  describe '#log!' do
22
39
  it 'should log a message' do
23
- base.expects(:compressor_name).returns('Compressor Name')
40
+ compressor.instance_variable_set(:@cmd, 'compressor command')
41
+ compressor.instance_variable_set(:@ext, 'compressor extension')
42
+ compressor.expects(:compressor_name).returns('Compressor Name')
43
+
24
44
  Backup::Logger.expects(:message).with(
25
- 'Using Compressor Name for compression.'
45
+ "Using Compressor Name for compression.\n" +
46
+ " Command: 'compressor command'\n" +
47
+ " Ext: 'compressor extension'"
26
48
  )
27
- base.send(:log!)
49
+ compressor.send(:log!)
28
50
  end
29
51
  end
30
-
31
52
  end
@@ -3,81 +3,236 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Compressor::Bzip2 do
6
- let(:compressor) { Backup::Compressor::Bzip2.new }
6
+ before do
7
+ Backup::Compressor::Bzip2.any_instance.stubs(:utility).returns('bzip2')
8
+ end
7
9
 
8
- describe 'setting configuration defaults' do
9
- after { Backup::Configuration::Compressor::Bzip2.clear_defaults! }
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Bzip2.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
10
14
 
11
- it 'uses and overrides configuration defaults' do
12
- Backup::Configuration::Compressor::Bzip2.best.should be_false
13
- Backup::Configuration::Compressor::Bzip2.fast.should be_false
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Bzip2.new }
14
17
 
15
- compressor = Backup::Compressor::Bzip2.new
16
- compressor.best.should be_false
17
- compressor.fast.should be_false
18
+ after { Backup::Compressor::Bzip2.clear_defaults! }
18
19
 
19
- Backup::Configuration::Compressor::Bzip2.defaults do |c|
20
- c.best = true
21
- c.fast = true
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Compressor::Bzip2.any_instance.expects(:load_defaults!)
22
+ compressor
23
+ end
24
+
25
+ context 'when no pre-configured defaults have been set' do
26
+ it 'should use default values' do
27
+ compressor.level.should be_false
28
+
29
+ compressor.instance_variable_get(:@cmd).should == 'bzip2'
30
+ compressor.instance_variable_get(:@ext).should == '.bz2'
22
31
  end
23
- Backup::Configuration::Compressor::Bzip2.best.should be_true
24
- Backup::Configuration::Compressor::Bzip2.fast.should be_true
25
32
 
26
- compressor = Backup::Compressor::Bzip2.new
27
- compressor.best.should be_true
28
- compressor.fast.should be_true
33
+ it 'should use the values given' do
34
+ compressor = Backup::Compressor::Bzip2.new do |c|
35
+ c.level = 5
36
+ end
37
+ compressor.level.should == 5
29
38
 
30
- compressor = Backup::Compressor::Bzip2.new do |c|
31
- c.best = false
39
+ compressor.instance_variable_get(:@cmd).should == 'bzip2 -5'
40
+ compressor.instance_variable_get(:@ext).should == '.bz2'
32
41
  end
33
- compressor.best.should be_false
34
- compressor.fast.should be_true
42
+ end # context 'when no pre-configured defaults have been set'
35
43
 
36
- compressor = Backup::Compressor::Bzip2.new do |c|
37
- c.fast = false
44
+ context 'when pre-configured defaults have been set' do
45
+ before do
46
+ Backup::Compressor::Bzip2.defaults do |c|
47
+ c.level = 7
48
+ end
38
49
  end
39
- compressor.best.should be_true
40
- compressor.fast.should be_false
41
- end
42
- end # describe 'setting configuration defaults'
43
50
 
44
- describe '#compress_with' do
45
- before do
46
- compressor.expects(:log!)
47
- compressor.expects(:utility).with(:bzip2).returns('bzip2')
48
- end
51
+ it 'should use pre-configured defaults' do
52
+ compressor.level.should == 7
49
53
 
50
- it 'should yield with the --best option' do
51
- compressor.best = true
52
- compressor.compress_with do |cmd, ext|
53
- cmd.should == 'bzip2 --best'
54
- ext.should == '.bz2'
54
+ compressor.instance_variable_get(:@cmd).should == 'bzip2 -7'
55
+ compressor.instance_variable_get(:@ext).should == '.bz2'
55
56
  end
56
- end
57
57
 
58
- it 'should yield with the --fast option' do
59
- compressor.fast = true
60
- compressor.compress_with do |cmd, ext|
61
- cmd.should == 'bzip2 --fast'
62
- ext.should == '.bz2'
58
+ it 'should override pre-configured defaults' do
59
+ compressor = Backup::Compressor::Bzip2.new do |c|
60
+ c.level = 6
61
+ end
62
+ compressor.level.should == 6
63
+
64
+ compressor.instance_variable_get(:@cmd).should == 'bzip2 -6'
65
+ compressor.instance_variable_get(:@ext).should == '.bz2'
63
66
  end
64
- end
67
+ end # context 'when pre-configured defaults have been set'
68
+ end # describe '#initialize'
69
+
70
+ describe 'deprecations' do
71
+ describe 'fast and best options' do
72
+ context 'when only the fast option is used' do
73
+ before do
74
+ Backup::Logger.expects(:warn).with(
75
+ instance_of(Backup::Errors::ConfigurationError)
76
+ )
77
+ end
65
78
 
66
- it 'should yield with the --best and --fast options' do
67
- compressor.best = true
68
- compressor.fast = true
69
- compressor.compress_with do |cmd, ext|
70
- cmd.should == 'bzip2 --best --fast'
71
- ext.should == '.bz2'
79
+ context 'when set to true' do
80
+ it 'should log a warning and set `level` to 1' do
81
+ Backup::Logger.expects(:warn).with(
82
+ "Backup::Compressor::Bzip2.level is being set to '1'"
83
+ )
84
+ compressor = Backup::Compressor::Bzip2.new do |c|
85
+ c.fast = true
86
+ end
87
+ compressor.level.should be(1)
88
+ end
89
+ end
90
+
91
+ context 'when set to false' do
92
+ it 'should only log a warning' do
93
+ compressor = Backup::Compressor::Bzip2.new do |c|
94
+ c.fast = false
95
+ end
96
+ compressor.level.should be_false
97
+ end
98
+ end
72
99
  end
73
- end
74
100
 
75
- it 'should yield with no options' do
76
- compressor.compress_with do |cmd, ext|
77
- cmd.should == 'bzip2'
78
- ext.should == '.bz2'
101
+ context 'when only the best option is used' do
102
+ before do
103
+ Backup::Logger.expects(:warn).with(
104
+ instance_of(Backup::Errors::ConfigurationError)
105
+ )
106
+ end
107
+
108
+ context 'when set to true' do
109
+ it 'should log a warning and set `level` to 1' do
110
+ Backup::Logger.expects(:warn).with(
111
+ "Backup::Compressor::Bzip2.level is being set to '9'"
112
+ )
113
+ compressor = Backup::Compressor::Bzip2.new do |c|
114
+ c.best = true
115
+ end
116
+ compressor.level.should be(9)
117
+ end
118
+ end
119
+
120
+ context 'when set to false' do
121
+ it 'should only log a warning' do
122
+ compressor = Backup::Compressor::Bzip2.new do |c|
123
+ c.best = false
124
+ end
125
+ compressor.level.should be_false
126
+ end
127
+ end
128
+
79
129
  end
80
- end
81
- end # describe '#compress_with'
82
130
 
131
+ context 'when both fast and best options are used' do
132
+ before do
133
+ Backup::Logger.expects(:warn).twice.with(
134
+ instance_of(Backup::Errors::ConfigurationError)
135
+ )
136
+ end
137
+
138
+ context 'when both are set true' do
139
+ context 'when fast is set first' do
140
+ it 'should cause the best option to be set' do
141
+ Backup::Logger.expects(:warn).with(
142
+ "Backup::Compressor::Bzip2.level is being set to '1'"
143
+ )
144
+ Backup::Logger.expects(:warn).with(
145
+ "Backup::Compressor::Bzip2.level is being set to '9'"
146
+ )
147
+ compressor = Backup::Compressor::Bzip2.new do |c|
148
+ c.fast = true
149
+ c.best = true
150
+ end
151
+ compressor.level.should == 9
152
+ end
153
+ end
154
+
155
+ context 'when best is set first' do
156
+ it 'should cause the fast option to be set' do
157
+ Backup::Logger.expects(:warn).with(
158
+ "Backup::Compressor::Bzip2.level is being set to '1'"
159
+ )
160
+ Backup::Logger.expects(:warn).with(
161
+ "Backup::Compressor::Bzip2.level is being set to '9'"
162
+ )
163
+ compressor = Backup::Compressor::Bzip2.new do |c|
164
+ c.best = true
165
+ c.fast = true
166
+ end
167
+ compressor.level.should == 1
168
+ end
169
+ end
170
+ end
171
+
172
+ context 'when only one is set true' do
173
+ context 'when fast is set true before best' do
174
+ it 'should cause the fast option to be set' do
175
+ Backup::Logger.expects(:warn).with(
176
+ "Backup::Compressor::Bzip2.level is being set to '1'"
177
+ )
178
+ compressor = Backup::Compressor::Bzip2.new do |c|
179
+ c.fast = true
180
+ c.best = false
181
+ end
182
+ compressor.level.should == 1
183
+ end
184
+ end
185
+
186
+ context 'when fast is set true after best' do
187
+ it 'should cause the fast option to be set' do
188
+ Backup::Logger.expects(:warn).with(
189
+ "Backup::Compressor::Bzip2.level is being set to '1'"
190
+ )
191
+ compressor = Backup::Compressor::Bzip2.new do |c|
192
+ c.best = false
193
+ c.fast = true
194
+ end
195
+ compressor.level.should == 1
196
+ end
197
+ end
198
+
199
+ context 'when best is set true before fast' do
200
+ it 'should cause the best option to be set' do
201
+ Backup::Logger.expects(:warn).with(
202
+ "Backup::Compressor::Bzip2.level is being set to '9'"
203
+ )
204
+ compressor = Backup::Compressor::Bzip2.new do |c|
205
+ c.best = true
206
+ c.fast = false
207
+ end
208
+ compressor.level.should == 9
209
+ end
210
+ end
211
+
212
+ context 'when best is set true after fast' do
213
+ it 'should cause the best option to be set' do
214
+ Backup::Logger.expects(:warn).with(
215
+ "Backup::Compressor::Bzip2.level is being set to '9'"
216
+ )
217
+ compressor = Backup::Compressor::Bzip2.new do |c|
218
+ c.fast = false
219
+ c.best = true
220
+ end
221
+ compressor.level.should == 9
222
+ end
223
+ end
224
+ end
225
+
226
+ context 'when both are set false' do
227
+ it 'should only issue the two warnings' do
228
+ compressor = Backup::Compressor::Bzip2.new do |c|
229
+ c.fast = false
230
+ c.best = false
231
+ end
232
+ compressor.level.should be_false
233
+ end
234
+ end
235
+ end
236
+ end # describe 'fast and best options'
237
+ end # describe 'deprecations'
83
238
  end
@@ -0,0 +1,106 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Compressor::Custom do
6
+ let(:compressor) { Backup::Compressor::Custom.new }
7
+
8
+ before(:all) do
9
+ # CLI::Helpers#utility will raise an error
10
+ # if the command is invalid or not set
11
+ Backup::Compressor::Custom.send(
12
+ :define_method, :utility,
13
+ lambda {|arg| arg.to_s.empty? ? 'error' : "/path/to/#{ arg }" }
14
+ )
15
+ end
16
+
17
+ it 'should be a subclass of Compressor::Base' do
18
+ Backup::Compressor::Custom.
19
+ superclass.should == Backup::Compressor::Base
20
+ end
21
+
22
+ describe '#initialize' do
23
+ let(:compressor) { Backup::Compressor::Custom.new }
24
+
25
+ after { Backup::Compressor::Custom.clear_defaults! }
26
+
27
+ it 'should load pre-configured defaults' do
28
+ Backup::Compressor::Custom.any_instance.expects(:load_defaults!)
29
+ compressor
30
+ end
31
+
32
+ it 'should call CLI::Helpers#utility to validate command' do
33
+ Backup::Compressor::Custom.any_instance.expects(:utility)
34
+ compressor
35
+ end
36
+
37
+ it 'should clean the command and extension for use with compress_with' do
38
+ compressor = Backup::Compressor::Custom.new do |c|
39
+ c.command = ' my_command --option foo '
40
+ c.extension = ' my_extension '
41
+ end
42
+
43
+ compressor.command.should == ' my_command --option foo '
44
+ compressor.extension.should == ' my_extension '
45
+
46
+ compressor.expects(:log!)
47
+ compressor.compress_with do |cmd, ext|
48
+ cmd.should == '/path/to/my_command --option foo'
49
+ ext.should == 'my_extension'
50
+ end
51
+ end
52
+
53
+ context 'when no pre-configured defaults have been set' do
54
+ it 'should use default values' do
55
+ compressor.command.should be_nil
56
+ compressor.extension.should be_nil
57
+
58
+ compressor.instance_variable_get(:@cmd).should == 'error'
59
+ compressor.instance_variable_get(:@ext).should == ''
60
+ end
61
+
62
+ it 'should use the values given' do
63
+ compressor = Backup::Compressor::Custom.new do |c|
64
+ c.command = 'my_command'
65
+ c.extension = 'my_extension'
66
+ end
67
+
68
+ compressor.command.should == 'my_command'
69
+ compressor.extension.should == 'my_extension'
70
+
71
+ compressor.instance_variable_get(:@cmd).should == '/path/to/my_command'
72
+ compressor.instance_variable_get(:@ext).should == 'my_extension'
73
+ end
74
+ end # context 'when no pre-configured defaults have been set'
75
+
76
+ context 'when pre-configured defaults have been set' do
77
+ before do
78
+ Backup::Compressor::Custom.defaults do |c|
79
+ c.command = 'default_command'
80
+ c.extension = 'default_extension'
81
+ end
82
+ end
83
+
84
+ it 'should use pre-configured defaults' do
85
+ compressor.command.should == 'default_command'
86
+ compressor.extension.should == 'default_extension'
87
+
88
+ compressor.instance_variable_get(:@cmd).should == '/path/to/default_command'
89
+ compressor.instance_variable_get(:@ext).should == 'default_extension'
90
+ end
91
+
92
+ it 'should override pre-configured defaults' do
93
+ compressor = Backup::Compressor::Custom.new do |c|
94
+ c.command = 'new_command'
95
+ c.extension = 'new_extension'
96
+ end
97
+
98
+ compressor.command.should == 'new_command'
99
+ compressor.extension.should == 'new_extension'
100
+
101
+ compressor.instance_variable_get(:@cmd).should == '/path/to/new_command'
102
+ compressor.instance_variable_get(:@ext).should == 'new_extension'
103
+ end
104
+ end # context 'when pre-configured defaults have been set'
105
+ end # describe '#initialize'
106
+ end