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
@@ -13,48 +13,81 @@ describe Backup::Database::Riak do
13
13
  end
14
14
  end
15
15
 
16
+ it 'should be a subclass of Database::Base' do
17
+ Backup::Database::Riak.superclass.
18
+ should == Backup::Database::Base
19
+ end
20
+
16
21
  describe '#initialize' do
17
- it 'should read the adapter details correctly' do
18
- db.name.should == 'mydatabase'
19
- db.node.should == 'riak@localhost'
20
- db.cookie.should == 'riak'
21
- db.riak_admin_utility.should == '/path/to/riak-admin'
22
+
23
+ it 'should load pre-configured defaults through Base' do
24
+ Backup::Database::Riak.any_instance.expects(:load_defaults!)
25
+ db
22
26
  end
23
27
 
24
- context 'when options are not set' do
25
- before do
26
- Backup::Database::Riak.any_instance.expects(:utility).
27
- with('riak-admin').returns('/real/riak-admin')
28
+ it 'should pass the model reference to Base' do
29
+ db.instance_variable_get(:@model).should == model
30
+ end
31
+
32
+ context 'when no pre-configured defaults have been set' do
33
+ context 'when options are specified' do
34
+ it 'should use the given values' do
35
+ db.name.should == 'mydatabase'
36
+ db.node.should == 'riak@localhost'
37
+ db.cookie.should == 'riak'
38
+ db.riak_admin_utility.should == '/path/to/riak-admin'
39
+ end
28
40
  end
29
41
 
30
- it 'should use default values' do
31
- db = Backup::Database::Riak.new(model)
42
+ context 'when options are not specified' do
43
+ before do
44
+ Backup::Database::Riak.any_instance.expects(:utility).
45
+ with('riak-admin').returns('/real/riak-admin')
46
+ end
32
47
 
33
- db.name.should be_nil
34
- db.node.should be_nil
35
- db.cookie.should be_nil
36
- db.riak_admin_utility.should == '/real/riak-admin'
37
- end
38
- end
48
+ it 'should provide default values' do
49
+ db = Backup::Database::Riak.new(model)
39
50
 
40
- context 'when configuration defaults have been set' do
41
- after { Backup::Configuration::Database::Riak.clear_defaults! }
51
+ db.name.should be_nil
52
+ db.node.should be_nil
53
+ db.cookie.should be_nil
54
+ db.riak_admin_utility.should == '/real/riak-admin'
55
+ end
56
+ end
57
+ end # context 'when no pre-configured defaults have been set'
42
58
 
43
- it 'should use configuration defaults' do
44
- Backup::Configuration::Database::Riak.defaults do |db|
59
+ context 'when pre-configured defaults have been set' do
60
+ before do
61
+ Backup::Database::Riak.defaults do |db|
45
62
  db.name = 'db_name'
46
63
  db.node = 'db_node'
47
64
  db.cookie = 'db_cookie'
48
65
  db.riak_admin_utility = '/default/path/to/riak-admin'
49
66
  end
67
+ end
68
+
69
+ after { Backup::Database::Riak.clear_defaults! }
50
70
 
51
- db = Backup::Database::Riak.new(model)
52
- db.name.should == 'db_name'
53
- db.node.should == 'db_node'
54
- db.cookie.should == 'db_cookie'
55
- db.riak_admin_utility.should == '/default/path/to/riak-admin'
71
+ context 'when options are specified' do
72
+ it 'should override the pre-configured defaults' do
73
+ db.name.should == 'mydatabase'
74
+ db.node.should == 'riak@localhost'
75
+ db.cookie.should == 'riak'
76
+ db.riak_admin_utility.should == '/path/to/riak-admin'
77
+ end
56
78
  end
57
- end
79
+
80
+ context 'when options are not specified' do
81
+ it 'should use the pre-configured defaults' do
82
+ db = Backup::Database::Riak.new(model)
83
+
84
+ db.name.should == 'db_name'
85
+ db.node.should == 'db_node'
86
+ db.cookie.should == 'db_cookie'
87
+ db.riak_admin_utility.should == '/default/path/to/riak-admin'
88
+ end
89
+ end
90
+ end # context 'when no pre-configured defaults have been set'
58
91
  end # describe '#initialize'
59
92
 
60
93
  describe '#perform!' do
@@ -105,4 +138,40 @@ describe Backup::Database::Riak do
105
138
  end
106
139
  end
107
140
 
141
+ describe 'deprecations' do
142
+ after do
143
+ Backup::Database::Riak.clear_defaults!
144
+ end
145
+
146
+ describe '#utility_path' do
147
+ before do
148
+ Backup::Database::Riak.any_instance.stubs(:utility)
149
+ Backup::Logger.expects(:warn).with(
150
+ instance_of(Backup::Errors::ConfigurationError)
151
+ )
152
+ Backup::Logger.expects(:warn).with(
153
+ "Backup::Database::Riak.riak_admin_utility is being set to 'foo'"
154
+ )
155
+ end
156
+
157
+ context 'when set directly' do
158
+ it 'should issue a deprecation warning and set the replacement value' do
159
+ riak = Backup::Database::Riak.new(model) do |db|
160
+ db.utility_path = 'foo'
161
+ end
162
+ riak.riak_admin_utility.should == 'foo'
163
+ end
164
+ end
165
+
166
+ context 'when set as a default' do
167
+ it 'should issue a deprecation warning and set the replacement value' do
168
+ riak = Backup::Database::Riak.defaults do |db|
169
+ db.utility_path = 'foo'
170
+ end
171
+ riak = Backup::Database::Riak.new(model)
172
+ riak.riak_admin_utility.should == 'foo'
173
+ end
174
+ end
175
+ end # describe '#utility_path'
176
+ end
108
177
  end
@@ -40,6 +40,8 @@ describe Backup::Dependency do
40
40
  end
41
41
 
42
42
  it "should exit with status code 1" do
43
+ Backup::Logger.expects(:error)
44
+
43
45
  expect do
44
46
  Backup::Dependency.load("net-sftp")
45
47
  end.to raise_error { |exit| exit.status.should be(1) }
@@ -5,6 +5,16 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
5
5
  describe Backup::Encryptor::Base do
6
6
  let(:base) { Backup::Encryptor::Base.new }
7
7
 
8
+ it 'should include CLI::Helpers' do
9
+ Backup::Encryptor::Base.
10
+ include?(Backup::CLI::Helpers).should be_true
11
+ end
12
+
13
+ it 'should include Configuration::Helpers' do
14
+ Backup::Encryptor::Base.
15
+ include?(Backup::Configuration::Helpers).should be_true
16
+ end
17
+
8
18
  describe '#initialize' do
9
19
  it 'should load defaults' do
10
20
  Backup::Encryptor::Base.any_instance.expects(:load_defaults!)
@@ -9,30 +9,46 @@ describe Backup::Encryptor::GPG do
9
9
  end
10
10
  end
11
11
 
12
+ it 'should be a subclass of Encryptor::Base' do
13
+ Backup::Encryptor::GPG.
14
+ superclass.should == Backup::Encryptor::Base
15
+ end
16
+
12
17
  describe '#initialize' do
13
- it 'should read the adapter details correctly' do
14
- encryptor.key.should == 'gpg_key'
18
+ after { Backup::Encryptor::GPG.clear_defaults! }
19
+
20
+ it 'should load pre-configured defaults' do
21
+ Backup::Encryptor::GPG.any_instance.expects(:load_defaults!)
22
+ encryptor
15
23
  end
16
24
 
17
- context 'when options are not set' do
18
- it 'should use default values' do
25
+ context 'when no pre-configured defaults have been set' do
26
+ it 'should use the values given' do
27
+ encryptor.key.should == 'gpg_key'
28
+ end
29
+
30
+ it 'should use default values if none are given' do
19
31
  encryptor = Backup::Encryptor::GPG.new
20
32
  encryptor.key.should be_nil
21
33
  end
22
- end
34
+ end # context 'when no pre-configured defaults have been set'
23
35
 
24
- context 'when configuration defaults have been set' do
25
- after { Backup::Configuration::Encryptor::GPG.clear_defaults! }
26
-
27
- it 'should use configuration defaults' do
28
- Backup::Configuration::Encryptor::GPG.defaults do |encryptor|
29
- encryptor.key = 'my_key'
36
+ context 'when pre-configured defaults have been set' do
37
+ before do
38
+ Backup::Encryptor::GPG.defaults do |e|
39
+ e.key = 'default_key'
30
40
  end
41
+ end
31
42
 
43
+ it 'should use pre-configured defaults' do
32
44
  encryptor = Backup::Encryptor::GPG.new
33
- encryptor.key.should == 'my_key'
45
+ encryptor.key.should == 'default_key'
34
46
  end
35
- end
47
+
48
+ it 'should override pre-configured defaults' do
49
+ encryptor.key.should == 'gpg_key'
50
+ end
51
+ end # context 'when pre-configured defaults have been set'
36
52
  end # describe '#initialize'
37
53
 
38
54
  describe '#encrypt_with' do
@@ -12,42 +12,61 @@ describe Backup::Encryptor::OpenSSL do
12
12
  end
13
13
  end
14
14
 
15
+ it 'should be a subclass of Encryptor::Base' do
16
+ Backup::Encryptor::OpenSSL.
17
+ superclass.should == Backup::Encryptor::Base
18
+ end
19
+
15
20
  describe '#initialize' do
16
- it 'should read the adapter details correctly' do
17
- encryptor.password.should == 'mypassword'
18
- encryptor.password_file.should == '/my/password/file'
19
- encryptor.base64.should == true
20
- encryptor.salt.should == true
21
+ after { Backup::Encryptor::OpenSSL.clear_defaults! }
22
+
23
+ it 'should load pre-configured defaults' do
24
+ Backup::Encryptor::OpenSSL.any_instance.expects(:load_defaults!)
25
+ encryptor
21
26
  end
22
27
 
23
- context 'when options are not set' do
24
- it 'should use default values' do
28
+ context 'when no pre-configured defaults have been set' do
29
+ it 'should use the values given' do
30
+ encryptor.password.should == 'mypassword'
31
+ encryptor.password_file.should == '/my/password/file'
32
+ encryptor.base64.should == true
33
+ encryptor.salt.should == true
34
+ end
35
+
36
+ it 'should use default values if none are given' do
25
37
  encryptor = Backup::Encryptor::OpenSSL.new
26
38
  encryptor.password.should be_nil
27
39
  encryptor.password_file.should be_nil
28
40
  encryptor.base64.should be_false
29
41
  encryptor.salt.should be_true
30
42
  end
31
- end
32
-
33
- context 'when configuration defaults have been set' do
34
- after { Backup::Configuration::Encryptor::OpenSSL.clear_defaults! }
35
-
36
- it 'should use configuration defaults' do
37
- Backup::Configuration::Encryptor::OpenSSL.defaults do |encryptor|
38
- encryptor.password = 'my_password'
39
- encryptor.password_file = '/my_password/file'
40
- encryptor.base64 = true
41
- encryptor.salt = true
43
+ end # context 'when no pre-configured defaults have been set'
44
+
45
+ context 'when pre-configured defaults have been set' do
46
+ before do
47
+ Backup::Encryptor::OpenSSL.defaults do |e|
48
+ e.password = 'default_password'
49
+ e.password_file = '/default/password/file'
50
+ e.base64 = 'default_base64'
51
+ e.salt = 'default_salt'
42
52
  end
53
+ end
43
54
 
55
+ it 'should use pre-configured defaults' do
44
56
  encryptor = Backup::Encryptor::OpenSSL.new
45
- encryptor.password.should == 'my_password'
46
- encryptor.password_file.should == '/my_password/file'
57
+ encryptor.password = 'default_password'
58
+ encryptor.password_file = '/default/password/file'
59
+ encryptor.base64 = 'default_base64'
60
+ encryptor.salt = 'default_salt'
61
+ end
62
+
63
+ it 'should override pre-configured defaults' do
64
+ encryptor.password.should == 'mypassword'
65
+ encryptor.password_file.should == '/my/password/file'
47
66
  encryptor.base64.should == true
48
67
  encryptor.salt.should == true
49
68
  end
50
- end
69
+ end # context 'when pre-configured defaults have been set'
51
70
  end # describe '#initialize'
52
71
 
53
72
  describe '#encrypt_with' do
data/spec/logger_spec.rb CHANGED
@@ -181,6 +181,10 @@ describe Backup::Logger do
181
181
  FileUtils.unstub(:rm_f)
182
182
  end
183
183
 
184
+ after do
185
+ Backup::Config.send(:reset!)
186
+ end
187
+
184
188
  it 'should truncate the file, removing older lines' do
185
189
  max_bytes = 5_000
186
190
  line_len = 120
data/spec/model_spec.rb CHANGED
@@ -209,10 +209,25 @@ describe 'Backup::Model' do
209
209
  end
210
210
  end
211
211
 
212
- it 'should warn user of change from RSync to RSync::Local' do
212
+ it 'should warn user of change from RSync to RSync::Push' do
213
213
  Backup::Logger.expects(:warn)
214
214
  model.sync_with('Backup::Config::RSync')
215
- model.syncers.first.should be_an_instance_of Backup::Syncer::RSync::Local
215
+ model.syncers.first.should
216
+ be_an_instance_of Backup::Syncer::RSync::Push
217
+ end
218
+
219
+ it 'should warn user of change from S3 to Cloud::S3' do
220
+ Backup::Logger.expects(:warn)
221
+ model.sync_with('Backup::Config::S3')
222
+ model.syncers.first.should
223
+ be_an_instance_of Backup::Syncer::Cloud::S3
224
+ end
225
+
226
+ it 'should warn user of change from CloudFiles to Cloud::CloudFiles' do
227
+ Backup::Logger.expects(:warn)
228
+ model.sync_with('Backup::Config::CloudFiles')
229
+ model.syncers.first.should
230
+ be_an_instance_of Backup::Syncer::Cloud::CloudFiles
216
231
  end
217
232
  end
218
233
 
@@ -327,6 +342,8 @@ describe 'Backup::Model' do
327
342
  Timecop.freeze(Time.now)
328
343
  started_at = Time.now
329
344
  time = started_at.strftime("%Y.%m.%d.%H.%M.%S")
345
+ model.expects(:log!).with(:started)
346
+ model.expects(:log!).with(:finished)
330
347
 
331
348
  model.perform!
332
349
  model.time.should == time
@@ -6,31 +6,46 @@ describe 'Backup::Notifier::Base' do
6
6
  let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
7
  let(:notifier) { Backup::Notifier::Base.new(model) }
8
8
 
9
+ it 'should include Configuration::Helpers' do
10
+ Backup::Notifier::Base.
11
+ include?(Backup::Configuration::Helpers).should be_true
12
+ end
13
+
9
14
  describe '#initialize' do
15
+ after { Backup::Notifier::Base.clear_defaults! }
10
16
 
11
- it "sets the correct defaults" do
12
- notifier.on_success.should == true
13
- notifier.on_warning.should == true
14
- notifier.on_failure.should == true
17
+ it 'should load pre-configured defaults' do
18
+ Backup::Notifier::Base.any_instance.expects(:load_defaults!)
19
+ notifier
15
20
  end
16
21
 
17
- context 'when using configuration defaults' do
18
- after { Backup::Configuration::Notifier::Base.clear_defaults! }
22
+ it 'should set a reference to the model' do
23
+ notifier.instance_variable_get(:@model).should == model
24
+ end
19
25
 
20
- it 'uses configuration defaults' do
21
- Backup::Configuration::Notifier::Base.defaults do |notifier|
22
- notifier.on_success = false
23
- notifier.on_warning = false
24
- notifier.on_failure = false
26
+ context 'when no pre-configured defaults have been set' do
27
+ it 'should set default values' do
28
+ notifier.on_success.should == true
29
+ notifier.on_warning.should == true
30
+ notifier.on_failure.should == true
31
+ end
32
+ end # context 'when no pre-configured defaults have been set'
33
+
34
+ context 'when pre-configured defaults have been set' do
35
+ before do
36
+ Backup::Notifier::Base.defaults do |n|
37
+ n.on_success = false
38
+ n.on_warning = false
39
+ n.on_failure = false
25
40
  end
26
-
27
- base = Backup::Notifier::Base.new(model)
28
- base.on_success.should == false
29
- base.on_warning.should == false
30
- base.on_failure.should == false
31
41
  end
32
- end
33
42
 
43
+ it 'should use pre-configured defaults' do
44
+ notifier.on_success.should be_false
45
+ notifier.on_warning.should be_false
46
+ notifier.on_failure.should be_false
47
+ end
48
+ end # context 'when pre-configured defaults have been set'
34
49
  end # describe '#initialize'
35
50
 
36
51
  describe '#perform!' do
@@ -12,30 +12,60 @@ describe Backup::Notifier::Campfire do
12
12
  end
13
13
  end
14
14
 
15
+ it 'should be a subclass of Notifier::Base' do
16
+ Backup::Notifier::Campfire.
17
+ superclass.should == Backup::Notifier::Base
18
+ end
19
+
15
20
  describe '#initialize' do
16
- it 'should sets the correct values' do
17
- notifier.api_token.should == 'token'
18
- notifier.subdomain.should == 'subdomain'
19
- notifier.room_id.should == 'room_id'
20
-
21
- notifier.on_success.should == true
22
- notifier.on_warning.should == true
23
- notifier.on_failure.should == true
21
+ after { Backup::Notifier::Campfire.clear_defaults! }
22
+
23
+ it 'should load pre-configured defaults through Base' do
24
+ Backup::Notifier::Campfire.any_instance.expects(:load_defaults!)
25
+ notifier
24
26
  end
25
27
 
26
- context 'when using configuration defaults' do
27
- after { Backup::Configuration::Notifier::Campfire.clear_defaults! }
28
+ it 'should pass the model reference to Base' do
29
+ notifier.instance_variable_get(:@model).should == model
30
+ end
28
31
 
29
- it 'should use the configuration defaults' do
30
- Backup::Configuration::Notifier::Campfire.defaults do |campfire|
31
- campfire.api_token = 'some_token'
32
- campfire.subdomain = 'some_subdomain'
33
- campfire.room_id = 'some_room_id'
32
+ context 'when no pre-configured defaults have been set' do
33
+ it 'should use the values given' do
34
+ notifier.api_token.should == 'token'
35
+ notifier.subdomain.should == 'subdomain'
36
+ notifier.room_id.should == 'room_id'
34
37
 
35
- campfire.on_success = false
36
- campfire.on_warning = false
37
- campfire.on_failure = false
38
+ notifier.on_success.should == true
39
+ notifier.on_warning.should == true
40
+ notifier.on_failure.should == true
41
+ end
42
+
43
+ it 'should use default values if none are given' do
44
+ notifier = Backup::Notifier::Campfire.new(model)
45
+ notifier.api_token.should be_nil
46
+ notifier.subdomain.should be_nil
47
+ notifier.room_id.should be_nil
48
+
49
+ notifier.on_success.should == true
50
+ notifier.on_warning.should == true
51
+ notifier.on_failure.should == true
52
+ end
53
+ end # context 'when no pre-configured defaults have been set'
54
+
55
+ context 'when pre-configured defaults have been set' do
56
+ before do
57
+ Backup::Notifier::Campfire.defaults do |n|
58
+ n.api_token = 'some_token'
59
+ n.subdomain = 'some_subdomain'
60
+ n.room_id = 'some_room_id'
61
+
62
+ n.on_success = false
63
+ n.on_warning = false
64
+ n.on_failure = false
38
65
  end
66
+ end
67
+
68
+ it 'should use pre-configured defaults' do
39
69
  notifier = Backup::Notifier::Campfire.new(model)
40
70
  notifier.api_token.should == 'some_token'
41
71
  notifier.subdomain.should == 'some_subdomain'
@@ -46,24 +76,15 @@ describe Backup::Notifier::Campfire do
46
76
  notifier.on_failure.should == false
47
77
  end
48
78
 
49
- it 'should override the configuration defaults' do
50
- Backup::Configuration::Notifier::Campfire.defaults do |campfire|
51
- campfire.api_token = 'old_token'
52
- campfire.subdomain = 'old_subdomain'
53
- campfire.room_id = 'old_room_id'
79
+ it 'should override pre-configured defaults' do
80
+ notifier = Backup::Notifier::Campfire.new(model) do |n|
81
+ n.api_token = 'new_token'
82
+ n.subdomain = 'new_subdomain'
83
+ n.room_id = 'new_room_id'
54
84
 
55
- campfire.on_success = true
56
- campfire.on_warning = false
57
- campfire.on_failure = false
58
- end
59
- notifier = Backup::Notifier::Campfire.new(model) do |campfire|
60
- campfire.api_token = 'new_token'
61
- campfire.subdomain = 'new_subdomain'
62
- campfire.room_id = 'new_room_id'
63
-
64
- campfire.on_success = false
65
- campfire.on_warning = true
66
- campfire.on_failure = true
85
+ n.on_success = false
86
+ n.on_warning = true
87
+ n.on_failure = true
67
88
  end
68
89
 
69
90
  notifier.api_token.should == 'new_token'
@@ -74,8 +95,8 @@ describe Backup::Notifier::Campfire do
74
95
  notifier.on_warning.should == true
75
96
  notifier.on_failure.should == true
76
97
  end
77
- end # context 'when using configuration defaults'
78
- end
98
+ end # context 'when pre-configured defaults have been set'
99
+ end # describe '#initialize'
79
100
 
80
101
  describe '#notify!' do
81
102
  context 'when status is :success' do
@@ -163,14 +184,11 @@ describe 'Backup::Notifier::Campfire::Room' do
163
184
 
164
185
  describe '#send_message' do
165
186
  it 'should pass a JSON formatted HTTParty.post to #post' do
166
- room.expects(:post).with('speak',
167
- {
168
- :body => {
169
- :message => {
170
- :body => 'a message',
171
- :type => 'Textmessage'
172
- }
173
- }.to_json
187
+ room.expects(:post).with(
188
+ 'speak', {
189
+ :body => MultiJson.encode(
190
+ { :message => { :body => 'a message', :type => 'Textmessage' } }
191
+ )
174
192
  }
175
193
  )
176
194
  room.send(:send_message, 'a message')