backup-agoddard 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.
Files changed (190) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +10 -0
  3. data/Gemfile +28 -0
  4. data/Guardfile +23 -0
  5. data/LICENSE.md +24 -0
  6. data/README.md +478 -0
  7. data/backup.gemspec +32 -0
  8. data/bin/backup +11 -0
  9. data/lib/backup.rb +133 -0
  10. data/lib/backup/archive.rb +117 -0
  11. data/lib/backup/binder.rb +22 -0
  12. data/lib/backup/cleaner.rb +121 -0
  13. data/lib/backup/cli/helpers.rb +93 -0
  14. data/lib/backup/cli/utility.rb +255 -0
  15. data/lib/backup/compressor/base.rb +35 -0
  16. data/lib/backup/compressor/bzip2.rb +50 -0
  17. data/lib/backup/compressor/custom.rb +53 -0
  18. data/lib/backup/compressor/gzip.rb +50 -0
  19. data/lib/backup/compressor/lzma.rb +52 -0
  20. data/lib/backup/compressor/pbzip2.rb +59 -0
  21. data/lib/backup/config.rb +174 -0
  22. data/lib/backup/configuration.rb +33 -0
  23. data/lib/backup/configuration/helpers.rb +130 -0
  24. data/lib/backup/configuration/store.rb +24 -0
  25. data/lib/backup/database/base.rb +53 -0
  26. data/lib/backup/database/mongodb.rb +230 -0
  27. data/lib/backup/database/mysql.rb +160 -0
  28. data/lib/backup/database/postgresql.rb +144 -0
  29. data/lib/backup/database/redis.rb +136 -0
  30. data/lib/backup/database/riak.rb +67 -0
  31. data/lib/backup/dependency.rb +108 -0
  32. data/lib/backup/encryptor/base.rb +29 -0
  33. data/lib/backup/encryptor/gpg.rb +760 -0
  34. data/lib/backup/encryptor/open_ssl.rb +72 -0
  35. data/lib/backup/errors.rb +124 -0
  36. data/lib/backup/hooks.rb +68 -0
  37. data/lib/backup/logger.rb +152 -0
  38. data/lib/backup/model.rb +409 -0
  39. data/lib/backup/notifier/base.rb +81 -0
  40. data/lib/backup/notifier/campfire.rb +155 -0
  41. data/lib/backup/notifier/hipchat.rb +93 -0
  42. data/lib/backup/notifier/mail.rb +206 -0
  43. data/lib/backup/notifier/prowl.rb +65 -0
  44. data/lib/backup/notifier/pushover.rb +88 -0
  45. data/lib/backup/notifier/twitter.rb +70 -0
  46. data/lib/backup/package.rb +47 -0
  47. data/lib/backup/packager.rb +100 -0
  48. data/lib/backup/pipeline.rb +110 -0
  49. data/lib/backup/splitter.rb +75 -0
  50. data/lib/backup/storage/base.rb +99 -0
  51. data/lib/backup/storage/cloudfiles.rb +87 -0
  52. data/lib/backup/storage/cycler.rb +117 -0
  53. data/lib/backup/storage/dropbox.rb +178 -0
  54. data/lib/backup/storage/ftp.rb +119 -0
  55. data/lib/backup/storage/local.rb +82 -0
  56. data/lib/backup/storage/ninefold.rb +116 -0
  57. data/lib/backup/storage/rsync.rb +149 -0
  58. data/lib/backup/storage/s3.rb +94 -0
  59. data/lib/backup/storage/scp.rb +99 -0
  60. data/lib/backup/storage/sftp.rb +108 -0
  61. data/lib/backup/syncer/base.rb +46 -0
  62. data/lib/backup/syncer/cloud/base.rb +247 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
  64. data/lib/backup/syncer/cloud/s3.rb +68 -0
  65. data/lib/backup/syncer/rsync/base.rb +49 -0
  66. data/lib/backup/syncer/rsync/local.rb +55 -0
  67. data/lib/backup/syncer/rsync/pull.rb +36 -0
  68. data/lib/backup/syncer/rsync/push.rb +116 -0
  69. data/lib/backup/template.rb +46 -0
  70. data/lib/backup/version.rb +43 -0
  71. data/spec-live/.gitignore +6 -0
  72. data/spec-live/README +7 -0
  73. data/spec-live/backups/config.rb +83 -0
  74. data/spec-live/backups/config.yml.template +46 -0
  75. data/spec-live/backups/models.rb +184 -0
  76. data/spec-live/compressor/custom_spec.rb +30 -0
  77. data/spec-live/compressor/gzip_spec.rb +30 -0
  78. data/spec-live/encryptor/gpg_keys.rb +239 -0
  79. data/spec-live/encryptor/gpg_spec.rb +287 -0
  80. data/spec-live/notifier/mail_spec.rb +121 -0
  81. data/spec-live/spec_helper.rb +151 -0
  82. data/spec-live/storage/dropbox_spec.rb +151 -0
  83. data/spec-live/storage/local_spec.rb +83 -0
  84. data/spec-live/storage/scp_spec.rb +193 -0
  85. data/spec-live/syncer/cloud/s3_spec.rb +124 -0
  86. data/spec/archive_spec.rb +335 -0
  87. data/spec/cleaner_spec.rb +312 -0
  88. data/spec/cli/helpers_spec.rb +301 -0
  89. data/spec/cli/utility_spec.rb +411 -0
  90. data/spec/compressor/base_spec.rb +52 -0
  91. data/spec/compressor/bzip2_spec.rb +217 -0
  92. data/spec/compressor/custom_spec.rb +106 -0
  93. data/spec/compressor/gzip_spec.rb +217 -0
  94. data/spec/compressor/lzma_spec.rb +123 -0
  95. data/spec/compressor/pbzip2_spec.rb +165 -0
  96. data/spec/config_spec.rb +321 -0
  97. data/spec/configuration/helpers_spec.rb +247 -0
  98. data/spec/configuration/store_spec.rb +39 -0
  99. data/spec/configuration_spec.rb +62 -0
  100. data/spec/database/base_spec.rb +63 -0
  101. data/spec/database/mongodb_spec.rb +510 -0
  102. data/spec/database/mysql_spec.rb +411 -0
  103. data/spec/database/postgresql_spec.rb +353 -0
  104. data/spec/database/redis_spec.rb +334 -0
  105. data/spec/database/riak_spec.rb +176 -0
  106. data/spec/dependency_spec.rb +51 -0
  107. data/spec/encryptor/base_spec.rb +40 -0
  108. data/spec/encryptor/gpg_spec.rb +909 -0
  109. data/spec/encryptor/open_ssl_spec.rb +148 -0
  110. data/spec/errors_spec.rb +306 -0
  111. data/spec/hooks_spec.rb +35 -0
  112. data/spec/logger_spec.rb +367 -0
  113. data/spec/model_spec.rb +694 -0
  114. data/spec/notifier/base_spec.rb +104 -0
  115. data/spec/notifier/campfire_spec.rb +217 -0
  116. data/spec/notifier/hipchat_spec.rb +211 -0
  117. data/spec/notifier/mail_spec.rb +316 -0
  118. data/spec/notifier/prowl_spec.rb +138 -0
  119. data/spec/notifier/pushover_spec.rb +123 -0
  120. data/spec/notifier/twitter_spec.rb +153 -0
  121. data/spec/package_spec.rb +61 -0
  122. data/spec/packager_spec.rb +213 -0
  123. data/spec/pipeline_spec.rb +259 -0
  124. data/spec/spec_helper.rb +60 -0
  125. data/spec/splitter_spec.rb +120 -0
  126. data/spec/storage/base_spec.rb +166 -0
  127. data/spec/storage/cloudfiles_spec.rb +254 -0
  128. data/spec/storage/cycler_spec.rb +247 -0
  129. data/spec/storage/dropbox_spec.rb +480 -0
  130. data/spec/storage/ftp_spec.rb +271 -0
  131. data/spec/storage/local_spec.rb +259 -0
  132. data/spec/storage/ninefold_spec.rb +343 -0
  133. data/spec/storage/rsync_spec.rb +362 -0
  134. data/spec/storage/s3_spec.rb +245 -0
  135. data/spec/storage/scp_spec.rb +233 -0
  136. data/spec/storage/sftp_spec.rb +244 -0
  137. data/spec/syncer/base_spec.rb +109 -0
  138. data/spec/syncer/cloud/base_spec.rb +515 -0
  139. data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
  140. data/spec/syncer/cloud/s3_spec.rb +174 -0
  141. data/spec/syncer/rsync/base_spec.rb +98 -0
  142. data/spec/syncer/rsync/local_spec.rb +149 -0
  143. data/spec/syncer/rsync/pull_spec.rb +98 -0
  144. data/spec/syncer/rsync/push_spec.rb +333 -0
  145. data/spec/version_spec.rb +21 -0
  146. data/templates/cli/utility/archive +25 -0
  147. data/templates/cli/utility/compressor/bzip2 +4 -0
  148. data/templates/cli/utility/compressor/custom +11 -0
  149. data/templates/cli/utility/compressor/gzip +4 -0
  150. data/templates/cli/utility/compressor/lzma +10 -0
  151. data/templates/cli/utility/compressor/pbzip2 +10 -0
  152. data/templates/cli/utility/config +32 -0
  153. data/templates/cli/utility/database/mongodb +18 -0
  154. data/templates/cli/utility/database/mysql +21 -0
  155. data/templates/cli/utility/database/postgresql +17 -0
  156. data/templates/cli/utility/database/redis +16 -0
  157. data/templates/cli/utility/database/riak +11 -0
  158. data/templates/cli/utility/encryptor/gpg +27 -0
  159. data/templates/cli/utility/encryptor/openssl +9 -0
  160. data/templates/cli/utility/model.erb +23 -0
  161. data/templates/cli/utility/notifier/campfire +12 -0
  162. data/templates/cli/utility/notifier/hipchat +15 -0
  163. data/templates/cli/utility/notifier/mail +22 -0
  164. data/templates/cli/utility/notifier/prowl +11 -0
  165. data/templates/cli/utility/notifier/pushover +11 -0
  166. data/templates/cli/utility/notifier/twitter +13 -0
  167. data/templates/cli/utility/splitter +7 -0
  168. data/templates/cli/utility/storage/cloud_files +22 -0
  169. data/templates/cli/utility/storage/dropbox +20 -0
  170. data/templates/cli/utility/storage/ftp +12 -0
  171. data/templates/cli/utility/storage/local +7 -0
  172. data/templates/cli/utility/storage/ninefold +9 -0
  173. data/templates/cli/utility/storage/rsync +11 -0
  174. data/templates/cli/utility/storage/s3 +19 -0
  175. data/templates/cli/utility/storage/scp +11 -0
  176. data/templates/cli/utility/storage/sftp +11 -0
  177. data/templates/cli/utility/syncer/cloud_files +46 -0
  178. data/templates/cli/utility/syncer/rsync_local +12 -0
  179. data/templates/cli/utility/syncer/rsync_pull +17 -0
  180. data/templates/cli/utility/syncer/rsync_push +17 -0
  181. data/templates/cli/utility/syncer/s3 +43 -0
  182. data/templates/general/links +11 -0
  183. data/templates/general/version.erb +2 -0
  184. data/templates/notifier/mail/failure.erb +9 -0
  185. data/templates/notifier/mail/success.erb +7 -0
  186. data/templates/notifier/mail/warning.erb +9 -0
  187. data/templates/storage/dropbox/authorization_url.erb +6 -0
  188. data/templates/storage/dropbox/authorized.erb +4 -0
  189. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  190. metadata +277 -0
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Compressor::Base do
6
+ let(:compressor) { Backup::Compressor::Base.new }
7
+
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
29
+ end
30
+ end
31
+
32
+ describe '#compressor_name' do
33
+ it 'should return class name with Backup namespace removed' do
34
+ compressor.send(:compressor_name).should == 'Compressor::Base'
35
+ end
36
+ end
37
+
38
+ describe '#log!' do
39
+ it 'should log a message' do
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
+
44
+ Backup::Logger.expects(:message).with(
45
+ "Using Compressor Name for compression.\n" +
46
+ " Command: 'compressor command'\n" +
47
+ " Ext: 'compressor extension'"
48
+ )
49
+ compressor.send(:log!)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,217 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Compressor::Bzip2 do
6
+ before do
7
+ Backup::Compressor::Bzip2.any_instance.stubs(:utility).returns('bzip2')
8
+ end
9
+
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Bzip2.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
14
+
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Bzip2.new }
17
+
18
+ after { Backup::Compressor::Bzip2.clear_defaults! }
19
+
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'
31
+ end
32
+
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
38
+
39
+ compressor.instance_variable_get(:@cmd).should == 'bzip2 -5'
40
+ compressor.instance_variable_get(:@ext).should == '.bz2'
41
+ end
42
+ end # context 'when no pre-configured defaults have been set'
43
+
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
49
+ end
50
+
51
+ it 'should use pre-configured defaults' do
52
+ compressor.level.should == 7
53
+
54
+ compressor.instance_variable_get(:@cmd).should == 'bzip2 -7'
55
+ compressor.instance_variable_get(:@ext).should == '.bz2'
56
+ end
57
+
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'
66
+ 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 {|err|
75
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
76
+ err.message.should match(
77
+ /Use Bzip2#level instead/
78
+ )
79
+ }
80
+ end
81
+
82
+ context 'when set to true' do
83
+ it 'should log a warning and set `level` to 1' do
84
+ compressor = Backup::Compressor::Bzip2.new do |c|
85
+ c.fast = true
86
+ end
87
+ compressor.level.should == 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
99
+ end
100
+
101
+ context 'when only the best option is used' do
102
+ before do
103
+ Backup::Logger.expects(:warn).with {|err|
104
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
105
+ err.message.should match(
106
+ /Use Bzip2#level instead/
107
+ )
108
+ }
109
+ end
110
+
111
+ context 'when set to true' do
112
+ it 'should log a warning and set `level` to 1' do
113
+ compressor = Backup::Compressor::Bzip2.new do |c|
114
+ c.best = true
115
+ end
116
+ compressor.level.should == 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
+
129
+ end
130
+
131
+ context 'when both fast and best options are used' do
132
+ before do
133
+ Backup::Logger.expects(:warn).twice.with {|err|
134
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
135
+ err.message.should match(
136
+ /Use Bzip2#level instead/
137
+ )
138
+ }
139
+ end
140
+
141
+ context 'when both are set true' do
142
+ context 'when fast is set first' do
143
+ it 'should cause the best option to be set' do
144
+ compressor = Backup::Compressor::Bzip2.new do |c|
145
+ c.fast = true
146
+ c.best = true
147
+ end
148
+ compressor.level.should == 9
149
+ end
150
+ end
151
+
152
+ context 'when best is set first' do
153
+ it 'should cause the fast option to be set' do
154
+ compressor = Backup::Compressor::Bzip2.new do |c|
155
+ c.best = true
156
+ c.fast = true
157
+ end
158
+ compressor.level.should == 1
159
+ end
160
+ end
161
+ end
162
+
163
+ context 'when only one is set true' do
164
+ context 'when fast is set true before best' do
165
+ it 'should cause the fast option to be set' do
166
+ compressor = Backup::Compressor::Bzip2.new do |c|
167
+ c.fast = true
168
+ c.best = false
169
+ end
170
+ compressor.level.should == 1
171
+ end
172
+ end
173
+
174
+ context 'when fast is set true after best' do
175
+ it 'should cause the fast option to be set' do
176
+ compressor = Backup::Compressor::Bzip2.new do |c|
177
+ c.best = false
178
+ c.fast = true
179
+ end
180
+ compressor.level.should == 1
181
+ end
182
+ end
183
+
184
+ context 'when best is set true before fast' do
185
+ it 'should cause the best option to be set' do
186
+ compressor = Backup::Compressor::Bzip2.new do |c|
187
+ c.best = true
188
+ c.fast = false
189
+ end
190
+ compressor.level.should == 9
191
+ end
192
+ end
193
+
194
+ context 'when best is set true after fast' do
195
+ it 'should cause the best option to be set' do
196
+ compressor = Backup::Compressor::Bzip2.new do |c|
197
+ c.fast = false
198
+ c.best = true
199
+ end
200
+ compressor.level.should == 9
201
+ end
202
+ end
203
+ end
204
+
205
+ context 'when both are set false' do
206
+ it 'should only issue the two warnings' do
207
+ compressor = Backup::Compressor::Bzip2.new do |c|
208
+ c.fast = false
209
+ c.best = false
210
+ end
211
+ compressor.level.should be_false
212
+ end
213
+ end
214
+ end
215
+ end # describe 'fast and best options'
216
+ end # describe 'deprecations'
217
+ 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
@@ -0,0 +1,217 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Compressor::Gzip do
6
+ before do
7
+ Backup::Compressor::Gzip.any_instance.stubs(:utility).returns('gzip')
8
+ end
9
+
10
+ it 'should be a subclass of Compressor::Base' do
11
+ Backup::Compressor::Gzip.
12
+ superclass.should == Backup::Compressor::Base
13
+ end
14
+
15
+ describe '#initialize' do
16
+ let(:compressor) { Backup::Compressor::Gzip.new }
17
+
18
+ after { Backup::Compressor::Gzip.clear_defaults! }
19
+
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Compressor::Gzip.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 == 'gzip'
30
+ compressor.instance_variable_get(:@ext).should == '.gz'
31
+ end
32
+
33
+ it 'should use the values given' do
34
+ compressor = Backup::Compressor::Gzip.new do |c|
35
+ c.level = 5
36
+ end
37
+ compressor.level.should == 5
38
+
39
+ compressor.instance_variable_get(:@cmd).should == 'gzip -5'
40
+ compressor.instance_variable_get(:@ext).should == '.gz'
41
+ end
42
+ end # context 'when no pre-configured defaults have been set'
43
+
44
+ context 'when pre-configured defaults have been set' do
45
+ before do
46
+ Backup::Compressor::Gzip.defaults do |c|
47
+ c.level = 7
48
+ end
49
+ end
50
+
51
+ it 'should use pre-configured defaults' do
52
+ compressor.level.should == 7
53
+
54
+ compressor.instance_variable_get(:@cmd).should == 'gzip -7'
55
+ compressor.instance_variable_get(:@ext).should == '.gz'
56
+ end
57
+
58
+ it 'should override pre-configured defaults' do
59
+ compressor = Backup::Compressor::Gzip.new do |c|
60
+ c.level = 6
61
+ end
62
+ compressor.level.should == 6
63
+
64
+ compressor.instance_variable_get(:@cmd).should == 'gzip -6'
65
+ compressor.instance_variable_get(:@ext).should == '.gz'
66
+ 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 {|err|
75
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
76
+ err.message.should match(
77
+ /Use Gzip#level instead/
78
+ )
79
+ }
80
+ end
81
+
82
+ context 'when set to true' do
83
+ it 'should log a warning and set `level` to 1' do
84
+ compressor = Backup::Compressor::Gzip.new do |c|
85
+ c.fast = true
86
+ end
87
+ compressor.level.should == 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::Gzip.new do |c|
94
+ c.fast = false
95
+ end
96
+ compressor.level.should be_false
97
+ end
98
+ end
99
+ end
100
+
101
+ context 'when only the best option is used' do
102
+ before do
103
+ Backup::Logger.expects(:warn).with {|err|
104
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
105
+ err.message.should match(
106
+ /Use Gzip#level instead/
107
+ )
108
+ }
109
+ end
110
+
111
+ context 'when set to true' do
112
+ it 'should log a warning and set `level` to 1' do
113
+ compressor = Backup::Compressor::Gzip.new do |c|
114
+ c.best = true
115
+ end
116
+ compressor.level.should == 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::Gzip.new do |c|
123
+ c.best = false
124
+ end
125
+ compressor.level.should be_false
126
+ end
127
+ end
128
+
129
+ end
130
+
131
+ context 'when both fast and best options are used' do
132
+ before do
133
+ Backup::Logger.expects(:warn).twice.with {|err|
134
+ err.should be_an_instance_of Backup::Errors::ConfigurationError
135
+ err.message.should match(
136
+ /Use Gzip#level instead/
137
+ )
138
+ }
139
+ end
140
+
141
+ context 'when both are set true' do
142
+ context 'when fast is set first' do
143
+ it 'should cause the best option to be set' do
144
+ compressor = Backup::Compressor::Gzip.new do |c|
145
+ c.fast = true
146
+ c.best = true
147
+ end
148
+ compressor.level.should == 9
149
+ end
150
+ end
151
+
152
+ context 'when best is set first' do
153
+ it 'should cause the fast option to be set' do
154
+ compressor = Backup::Compressor::Gzip.new do |c|
155
+ c.best = true
156
+ c.fast = true
157
+ end
158
+ compressor.level.should == 1
159
+ end
160
+ end
161
+ end
162
+
163
+ context 'when only one is set true' do
164
+ context 'when fast is set true before best' do
165
+ it 'should cause the fast option to be set' do
166
+ compressor = Backup::Compressor::Gzip.new do |c|
167
+ c.fast = true
168
+ c.best = false
169
+ end
170
+ compressor.level.should == 1
171
+ end
172
+ end
173
+
174
+ context 'when fast is set true after best' do
175
+ it 'should cause the fast option to be set' do
176
+ compressor = Backup::Compressor::Gzip.new do |c|
177
+ c.best = false
178
+ c.fast = true
179
+ end
180
+ compressor.level.should == 1
181
+ end
182
+ end
183
+
184
+ context 'when best is set true before fast' do
185
+ it 'should cause the best option to be set' do
186
+ compressor = Backup::Compressor::Gzip.new do |c|
187
+ c.best = true
188
+ c.fast = false
189
+ end
190
+ compressor.level.should == 9
191
+ end
192
+ end
193
+
194
+ context 'when best is set true after fast' do
195
+ it 'should cause the best option to be set' do
196
+ compressor = Backup::Compressor::Gzip.new do |c|
197
+ c.fast = false
198
+ c.best = true
199
+ end
200
+ compressor.level.should == 9
201
+ end
202
+ end
203
+ end
204
+
205
+ context 'when both are set false' do
206
+ it 'should only issue the two warnings' do
207
+ compressor = Backup::Compressor::Gzip.new do |c|
208
+ c.fast = false
209
+ c.best = false
210
+ end
211
+ compressor.level.should be_false
212
+ end
213
+ end
214
+ end
215
+ end # describe 'fast and best options'
216
+ end # describe 'deprecations'
217
+ end