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
@@ -17,36 +17,69 @@ describe Backup::Storage::S3 do
17
17
  end
18
18
  end
19
19
 
20
+ it 'should be a subclass of Storage::Base' do
21
+ Backup::Storage::S3.
22
+ superclass.should == Backup::Storage::Base
23
+ end
24
+
20
25
  describe '#initialize' do
21
- it 'should set the correct values' do
22
- storage.access_key_id.should == 'my_access_key_id'
23
- storage.secret_access_key.should == 'my_secret_access_key'
24
- storage.bucket.should == 'my-bucket'
25
- storage.path.should == 'backups'
26
- storage.region.should == 'us-east-1'
27
-
28
- storage.storage_id.should be_nil
29
- storage.keep.should == 5
26
+ after { Backup::Storage::S3.clear_defaults! }
27
+
28
+ it 'should load pre-configured defaults through Base' do
29
+ Backup::Storage::S3.any_instance.expects(:load_defaults!)
30
+ storage
31
+ end
32
+
33
+ it 'should pass the model reference to Base' do
34
+ storage.instance_variable_get(:@model).should == model
30
35
  end
31
36
 
32
- it 'should set a storage_id if given' do
33
- s3 = Backup::Storage::S3.new(model, 'my storage_id')
34
- s3.storage_id.should == 'my storage_id'
37
+ it 'should pass the storage_id to Base' do
38
+ storage = Backup::Storage::S3.new(model, 'my_storage_id')
39
+ storage.storage_id.should == 'my_storage_id'
35
40
  end
36
41
 
37
- context 'when setting configuration defaults' do
38
- after { Backup::Configuration::Storage::S3.clear_defaults! }
39
-
40
- it 'should use the configured defaults' do
41
- Backup::Configuration::Storage::S3.defaults do |s3|
42
- s3.access_key_id = 'some_access_key_id'
43
- s3.secret_access_key = 'some_secret_access_key'
44
- s3.bucket = 'some-bucket'
45
- s3.path = 'some_path'
46
- s3.region = 'some_region'
47
- s3.keep = 15
42
+ context 'when no pre-configured defaults have been set' do
43
+ it 'should use the values given' do
44
+ storage.access_key_id.should == 'my_access_key_id'
45
+ storage.secret_access_key.should == 'my_secret_access_key'
46
+ storage.bucket.should == 'my-bucket'
47
+ storage.path.should == 'backups'
48
+ storage.region.should == 'us-east-1'
49
+
50
+ storage.storage_id.should be_nil
51
+ storage.keep.should == 5
52
+ end
53
+
54
+ it 'should use default values if none are given' do
55
+ storage = Backup::Storage::S3.new(model)
56
+
57
+ storage.access_key_id.should be_nil
58
+ storage.secret_access_key.should be_nil
59
+ storage.bucket.should be_nil
60
+ storage.path.should == 'backups'
61
+ storage.region.should be_nil
62
+
63
+ storage.storage_id.should be_nil
64
+ storage.keep.should be_nil
65
+ end
66
+ end # context 'when no pre-configured defaults have been set'
67
+
68
+ context 'when pre-configured defaults have been set' do
69
+ before do
70
+ Backup::Storage::S3.defaults do |s|
71
+ s.access_key_id = 'some_access_key_id'
72
+ s.secret_access_key = 'some_secret_access_key'
73
+ s.bucket = 'some-bucket'
74
+ s.path = 'some_path'
75
+ s.region = 'some_region'
76
+ s.keep = 15
48
77
  end
78
+ end
79
+
80
+ it 'should use pre-configured defaults' do
49
81
  storage = Backup::Storage::S3.new(model)
82
+
50
83
  storage.access_key_id.should == 'some_access_key_id'
51
84
  storage.secret_access_key.should == 'some_secret_access_key'
52
85
  storage.bucket.should == 'some-bucket'
@@ -57,22 +90,14 @@ describe Backup::Storage::S3 do
57
90
  storage.keep.should == 15
58
91
  end
59
92
 
60
- it 'should override the configured defaults' do
61
- Backup::Configuration::Storage::S3.defaults do |s3|
62
- s3.access_key_id = 'old_access_key_id'
63
- s3.secret_access_key = 'old_secret_access_key'
64
- s3.bucket = 'old-bucket'
65
- s3.path = 'old_path'
66
- s3.region = 'old_region'
67
- s3.keep = 15
68
- end
69
- storage = Backup::Storage::S3.new(model) do |s3|
70
- s3.access_key_id = 'new_access_key_id'
71
- s3.secret_access_key = 'new_secret_access_key'
72
- s3.bucket = 'new-bucket'
73
- s3.path = 'new_path'
74
- s3.region = 'new_region'
75
- s3.keep = 10
93
+ it 'should override pre-configured defaults' do
94
+ storage = Backup::Storage::S3.new(model) do |s|
95
+ s.access_key_id = 'new_access_key_id'
96
+ s.secret_access_key = 'new_secret_access_key'
97
+ s.bucket = 'new-bucket'
98
+ s.path = 'new_path'
99
+ s.region = 'new_region'
100
+ s.keep = 10
76
101
  end
77
102
 
78
103
  storage.access_key_id.should == 'new_access_key_id'
@@ -84,8 +109,7 @@ describe Backup::Storage::S3 do
84
109
  storage.storage_id.should be_nil
85
110
  storage.keep.should == 10
86
111
  end
87
- end # context 'when setting configuration defaults'
88
-
112
+ end # context 'when pre-configured defaults have been set'
89
113
  end # describe '#initialize'
90
114
 
91
115
  describe '#provider' do
@@ -13,21 +13,26 @@ describe Backup::Storage::SCP do
13
13
  end
14
14
  end
15
15
 
16
+ it 'should be a subclass of Storage::Base' do
17
+ Backup::Storage::SCP.
18
+ superclass.should == Backup::Storage::Base
19
+ end
20
+
16
21
  describe '#initialize' do
17
- it 'should set the correct values' do
18
- storage.username.should == 'my_username'
19
- storage.password.should == 'my_password'
20
- storage.ip.should == '123.45.678.90'
21
- storage.port.should == 22
22
- storage.path.should == 'backups'
23
-
24
- storage.storage_id.should be_nil
25
- storage.keep.should == 5
22
+ after { Backup::Storage::SCP.clear_defaults! }
23
+
24
+ it 'should load pre-configured defaults through Base' do
25
+ Backup::Storage::SCP.any_instance.expects(:load_defaults!)
26
+ storage
27
+ end
28
+
29
+ it 'should pass the model reference to Base' do
30
+ storage.instance_variable_get(:@model).should == model
26
31
  end
27
32
 
28
- it 'should set a storage_id if given' do
29
- scp = Backup::Storage::SCP.new(model, 'my storage_id')
30
- scp.storage_id.should == 'my storage_id'
33
+ it 'should pass the storage_id to Base' do
34
+ storage = Backup::Storage::SCP.new(model, 'my_storage_id')
35
+ storage.storage_id.should == 'my_storage_id'
31
36
  end
32
37
 
33
38
  it 'should remove any preceeding tilde and slash from the path' do
@@ -37,19 +42,47 @@ describe Backup::Storage::SCP do
37
42
  storage.path.should == 'my_backups/path'
38
43
  end
39
44
 
40
- context 'when setting configuration defaults' do
41
- after { Backup::Configuration::Storage::SCP.clear_defaults! }
42
-
43
- it 'should use the configured defaults' do
44
- Backup::Configuration::Storage::SCP.defaults do |scp|
45
- scp.username = 'some_username'
46
- scp.password = 'some_password'
47
- scp.ip = 'some_ip'
48
- scp.port = 'some_port'
49
- scp.path = 'some_path'
50
- scp.keep = 'some_keep'
45
+ context 'when no pre-configured defaults have been set' do
46
+ it 'should use the values given' do
47
+ storage.username.should == 'my_username'
48
+ storage.password.should == 'my_password'
49
+ storage.ip.should == '123.45.678.90'
50
+ storage.port.should == 22
51
+ storage.path.should == 'backups'
52
+
53
+ storage.storage_id.should be_nil
54
+ storage.keep.should == 5
55
+ end
56
+
57
+ it 'should use default values if none are given' do
58
+ storage = Backup::Storage::SCP.new(model)
59
+
60
+ storage.username.should be_nil
61
+ storage.password.should be_nil
62
+ storage.ip.should be_nil
63
+ storage.port.should == 22
64
+ storage.path.should == 'backups'
65
+
66
+ storage.storage_id.should be_nil
67
+ storage.keep.should be_nil
68
+ end
69
+ end # context 'when no pre-configured defaults have been set'
70
+
71
+ context 'when pre-configured defaults have been set' do
72
+ before do
73
+ Backup::Storage::SCP.defaults do |s|
74
+ s.username = 'some_username'
75
+ s.password = 'some_password'
76
+ s.ip = 'some_ip'
77
+ s.port = 'some_port'
78
+ s.path = 'some_path'
79
+ s.keep = 'some_keep'
51
80
  end
81
+ end
82
+
83
+ it 'should use pre-configured defaults' do
52
84
  storage = Backup::Storage::SCP.new(model)
85
+
53
86
  storage.username.should == 'some_username'
54
87
  storage.password.should == 'some_password'
55
88
  storage.ip.should == 'some_ip'
@@ -60,22 +93,14 @@ describe Backup::Storage::SCP do
60
93
  storage.keep.should == 'some_keep'
61
94
  end
62
95
 
63
- it 'should override the configured defaults' do
64
- Backup::Configuration::Storage::SCP.defaults do |scp|
65
- scp.username = 'old_username'
66
- scp.password = 'old_password'
67
- scp.ip = 'old_ip'
68
- scp.port = 'old_port'
69
- scp.path = 'old_path'
70
- scp.keep = 'old_keep'
71
- end
72
- storage = Backup::Storage::SCP.new(model) do |scp|
73
- scp.username = 'new_username'
74
- scp.password = 'new_password'
75
- scp.ip = 'new_ip'
76
- scp.port = 'new_port'
77
- scp.path = 'new_path'
78
- scp.keep = 'new_keep'
96
+ it 'should override pre-configured defaults' do
97
+ storage = Backup::Storage::SCP.new(model) do |s|
98
+ s.username = 'new_username'
99
+ s.password = 'new_password'
100
+ s.ip = 'new_ip'
101
+ s.port = 'new_port'
102
+ s.path = 'new_path'
103
+ s.keep = 'new_keep'
79
104
  end
80
105
 
81
106
  storage.username.should == 'new_username'
@@ -87,8 +112,7 @@ describe Backup::Storage::SCP do
87
112
  storage.storage_id.should be_nil
88
113
  storage.keep.should == 'new_keep'
89
114
  end
90
- end # context 'when setting configuration defaults'
91
-
115
+ end # context 'when pre-configured defaults have been set'
92
116
  end # describe '#initialize'
93
117
 
94
118
  describe '#connection' do
@@ -13,21 +13,26 @@ describe Backup::Storage::SFTP do
13
13
  end
14
14
  end
15
15
 
16
+ it 'should be a subclass of Storage::Base' do
17
+ Backup::Storage::SFTP.
18
+ superclass.should == Backup::Storage::Base
19
+ end
20
+
16
21
  describe '#initialize' do
17
- it 'should set the correct values' do
18
- storage.username.should == 'my_username'
19
- storage.password.should == 'my_password'
20
- storage.ip.should == '123.45.678.90'
21
- storage.port.should == 22
22
- storage.path.should == 'backups'
23
-
24
- storage.storage_id.should be_nil
25
- storage.keep.should == 5
22
+ after { Backup::Storage::SFTP.clear_defaults! }
23
+
24
+ it 'should load pre-configured defaults through Base' do
25
+ Backup::Storage::SFTP.any_instance.expects(:load_defaults!)
26
+ storage
27
+ end
28
+
29
+ it 'should pass the model reference to Base' do
30
+ storage.instance_variable_get(:@model).should == model
26
31
  end
27
32
 
28
- it 'should set a storage_id if given' do
29
- sftp = Backup::Storage::SFTP.new(model, 'my storage_id')
30
- sftp.storage_id.should == 'my storage_id'
33
+ it 'should pass the storage_id to Base' do
34
+ storage = Backup::Storage::SFTP.new(model, 'my_storage_id')
35
+ storage.storage_id.should == 'my_storage_id'
31
36
  end
32
37
 
33
38
  it 'should remove any preceeding tilde and slash from the path' do
@@ -37,19 +42,47 @@ describe Backup::Storage::SFTP do
37
42
  storage.path.should == 'my_backups/path'
38
43
  end
39
44
 
40
- context 'when setting configuration defaults' do
41
- after { Backup::Configuration::Storage::SFTP.clear_defaults! }
42
-
43
- it 'should use the configured defaults' do
44
- Backup::Configuration::Storage::SFTP.defaults do |sftp|
45
- sftp.username = 'some_username'
46
- sftp.password = 'some_password'
47
- sftp.ip = 'some_ip'
48
- sftp.port = 'some_port'
49
- sftp.path = 'some_path'
50
- sftp.keep = 'some_keep'
45
+ context 'when no pre-configured defaults have been set' do
46
+ it 'should use the values given' do
47
+ storage.username.should == 'my_username'
48
+ storage.password.should == 'my_password'
49
+ storage.ip.should == '123.45.678.90'
50
+ storage.port.should == 22
51
+ storage.path.should == 'backups'
52
+
53
+ storage.storage_id.should be_nil
54
+ storage.keep.should == 5
55
+ end
56
+
57
+ it 'should use default values if none are given' do
58
+ storage = Backup::Storage::SFTP.new(model)
59
+
60
+ storage.username.should be_nil
61
+ storage.password.should be_nil
62
+ storage.ip.should be_nil
63
+ storage.port.should == 22
64
+ storage.path.should == 'backups'
65
+
66
+ storage.storage_id.should be_nil
67
+ storage.keep.should be_nil
68
+ end
69
+ end # context 'when no pre-configured defaults have been set'
70
+
71
+ context 'when pre-configured defaults have been set' do
72
+ before do
73
+ Backup::Storage::SFTP.defaults do |s|
74
+ s.username = 'some_username'
75
+ s.password = 'some_password'
76
+ s.ip = 'some_ip'
77
+ s.port = 'some_port'
78
+ s.path = 'some_path'
79
+ s.keep = 'some_keep'
51
80
  end
81
+ end
82
+
83
+ it 'should use pre-configured defaults' do
52
84
  storage = Backup::Storage::SFTP.new(model)
85
+
53
86
  storage.username.should == 'some_username'
54
87
  storage.password.should == 'some_password'
55
88
  storage.ip.should == 'some_ip'
@@ -60,22 +93,14 @@ describe Backup::Storage::SFTP do
60
93
  storage.keep.should == 'some_keep'
61
94
  end
62
95
 
63
- it 'should override the configured defaults' do
64
- Backup::Configuration::Storage::SFTP.defaults do |sftp|
65
- sftp.username = 'old_username'
66
- sftp.password = 'old_password'
67
- sftp.ip = 'old_ip'
68
- sftp.port = 'old_port'
69
- sftp.path = 'old_path'
70
- sftp.keep = 'old_keep'
71
- end
72
- storage = Backup::Storage::SFTP.new(model) do |sftp|
73
- sftp.username = 'new_username'
74
- sftp.password = 'new_password'
75
- sftp.ip = 'new_ip'
76
- sftp.port = 'new_port'
77
- sftp.path = 'new_path'
78
- sftp.keep = 'new_keep'
96
+ it 'should override pre-configured defaults' do
97
+ storage = Backup::Storage::SFTP.new(model) do |s|
98
+ s.username = 'new_username'
99
+ s.password = 'new_password'
100
+ s.ip = 'new_ip'
101
+ s.port = 'new_port'
102
+ s.path = 'new_path'
103
+ s.keep = 'new_keep'
79
104
  end
80
105
 
81
106
  storage.username.should == 'new_username'
@@ -87,8 +112,7 @@ describe Backup::Storage::SFTP do
87
112
  storage.storage_id.should be_nil
88
113
  storage.keep.should == 'new_keep'
89
114
  end
90
- end # context 'when setting configuration defaults'
91
-
115
+ end # context 'when pre-configured defaults have been set'
92
116
  end # describe '#initialize'
93
117
 
94
118
  describe '#connection' do
@@ -3,15 +3,102 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Syncer::Base do
6
- let(:base) { Backup::Syncer::Base }
7
- let(:syncer) { base.new }
6
+ let(:syncer) { Backup::Syncer::Base.new }
8
7
 
9
8
  it 'should include CLI::Helpers' do
10
- base.included_modules.should include(Backup::CLI::Helpers)
9
+ Backup::Syncer::Base.
10
+ include?(Backup::CLI::Helpers).should be_true
11
11
  end
12
12
 
13
13
  it 'should include Configuration::Helpers' do
14
- base.included_modules.should include(Backup::Configuration::Helpers)
14
+ Backup::Syncer::Base.
15
+ include?(Backup::Configuration::Helpers).should be_true
16
+ end
17
+
18
+ describe '#initialize' do
19
+ after { Backup::Syncer::Base.clear_defaults! }
20
+
21
+ it 'should load pre-configured defaults through Base' do
22
+ Backup::Syncer::Base.any_instance.expects(:load_defaults!)
23
+ syncer
24
+ end
25
+
26
+ it 'should establish a new array for @directories' do
27
+ syncer.directories.should == []
28
+ end
29
+
30
+ context 'when no pre-configured defaults have been set' do
31
+ it 'should set default values' do
32
+ syncer.path.should == 'backups'
33
+ syncer.mirror.should == false
34
+ end
35
+ end # context 'when no pre-configured defaults have been set'
36
+
37
+ context 'when pre-configured defaults have been set' do
38
+ before do
39
+ Backup::Syncer::Base.defaults do |s|
40
+ s.path = 'some_path'
41
+ s.mirror = 'some_mirror'
42
+ end
43
+ end
44
+
45
+ it 'should use pre-configured defaults' do
46
+ syncer.path.should == 'some_path'
47
+ syncer.mirror.should == 'some_mirror'
48
+ end
49
+ end # context 'when pre-configured defaults have been set'
50
+ end # describe '#initialize'
51
+
52
+ describe '#directories' do
53
+ before do
54
+ syncer.instance_variable_set(
55
+ :@directories, ['/some/directory', '/another/directory']
56
+ )
57
+ end
58
+
59
+ context 'when no block is given' do
60
+ it 'should return @directories' do
61
+ syncer.directories.should ==
62
+ ['/some/directory', '/another/directory']
63
+ end
64
+ end
65
+
66
+ context 'when a block is given' do
67
+ it 'should evalute the block, allowing #add to add directories' do
68
+ syncer.directories do
69
+ add '/new/path'
70
+ add '/another/new/path'
71
+ end
72
+ syncer.directories.should == [
73
+ '/some/directory',
74
+ '/another/directory',
75
+ '/new/path',
76
+ '/another/new/path'
77
+ ]
78
+ end
79
+ end
80
+ end # describe '#directories'
81
+
82
+ describe '#add' do
83
+ before do
84
+ syncer.instance_variable_set(
85
+ :@directories, ['/some/directory', '/another/directory']
86
+ )
87
+ end
88
+
89
+ it 'should add the given path to @directories' do
90
+ syncer.add '/my/path'
91
+ syncer.directories.should ==
92
+ ['/some/directory', '/another/directory', '/my/path']
93
+ end
94
+
95
+ # Note: Each Syncer should handle this as needed.
96
+ # For example, expanding these here would break RSync::Pull
97
+ it 'should not expand the given paths' do
98
+ syncer.add 'relative/path'
99
+ syncer.directories.should ==
100
+ ['/some/directory', '/another/directory', 'relative/path']
101
+ end
15
102
  end
16
103
 
17
104
  describe '#syncer_name' do