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
@@ -0,0 +1,181 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
3
+
4
+ describe 'Backup::Syncer::Cloud::CloudFiles' do
5
+ let(:syncer) do
6
+ Backup::Syncer::Cloud::CloudFiles.new do |cf|
7
+ cf.api_key = 'my_api_key'
8
+ cf.username = 'my_username'
9
+ cf.container = 'my_container'
10
+ cf.auth_url = 'my_auth_url'
11
+ cf.servicenet = true
12
+ end
13
+ end
14
+
15
+ it 'should be a subclass of Syncer::Cloud::Base' do
16
+ Backup::Syncer::Cloud::CloudFiles.
17
+ superclass.should == Backup::Syncer::Cloud::Base
18
+ end
19
+
20
+ describe '#initialize' do
21
+ after { Backup::Syncer::Cloud::CloudFiles.clear_defaults! }
22
+
23
+ it 'should load pre-configured defaults through Syncer::Cloud::Base' do
24
+ Backup::Syncer::Cloud::CloudFiles.any_instance.expects(:load_defaults!)
25
+ syncer
26
+ end
27
+
28
+ it 'should strip any leading slash in path' do
29
+ syncer = Backup::Syncer::Cloud::CloudFiles.new do |cloud|
30
+ cloud.path = '/cleaned/path'
31
+ end
32
+ syncer.path.should == 'cleaned/path'
33
+ end
34
+
35
+ context 'when no pre-configured defaults have been set' do
36
+ it 'should use the values given' do
37
+ syncer.api_key.should == 'my_api_key'
38
+ syncer.username.should == 'my_username'
39
+ syncer.container.should == 'my_container'
40
+ syncer.auth_url.should == 'my_auth_url'
41
+ syncer.servicenet.should == true
42
+ end
43
+
44
+ it 'should use default values if none are given' do
45
+ syncer = Backup::Syncer::Cloud::CloudFiles.new
46
+
47
+ # from Syncer::Base
48
+ syncer.path.should == 'backups'
49
+ syncer.mirror.should == false
50
+ syncer.directories.should == []
51
+
52
+ # from Syncer::Cloud::Base
53
+ syncer.concurrency_type.should == false
54
+ syncer.concurrency_level.should == 2
55
+
56
+ syncer.api_key.should == nil
57
+ syncer.username.should == nil
58
+ syncer.container.should == nil
59
+ syncer.auth_url.should == nil
60
+ syncer.servicenet.should == nil
61
+ end
62
+ end # context 'when no pre-configured defaults have been set'
63
+
64
+ context 'when pre-configured defaults have been set' do
65
+ before do
66
+ Backup::Syncer::Cloud::CloudFiles.defaults do |cloud|
67
+ cloud.api_key = 'default_api_key'
68
+ cloud.username = 'default_username'
69
+ cloud.container = 'default_container'
70
+ cloud.auth_url = 'default_auth_url'
71
+ cloud.servicenet = 'default_servicenet'
72
+ end
73
+ end
74
+
75
+ it 'should use pre-configured defaults' do
76
+ syncer = Backup::Syncer::Cloud::CloudFiles.new
77
+
78
+ # from Syncer::Base
79
+ syncer.path.should == 'backups'
80
+ syncer.mirror.should == false
81
+ syncer.directories.should == []
82
+
83
+ # from Syncer::Cloud::Base
84
+ syncer.concurrency_type.should == false
85
+ syncer.concurrency_level.should == 2
86
+
87
+ syncer.api_key.should == 'default_api_key'
88
+ syncer.username.should == 'default_username'
89
+ syncer.container.should == 'default_container'
90
+ syncer.auth_url.should == 'default_auth_url'
91
+ syncer.servicenet.should == 'default_servicenet'
92
+ end
93
+
94
+ it 'should override pre-configured defaults' do
95
+ syncer = Backup::Syncer::Cloud::CloudFiles.new do |cloud|
96
+ cloud.path = 'new_path'
97
+ cloud.mirror = 'new_mirror'
98
+ cloud.concurrency_type = 'new_concurrency_type'
99
+ cloud.concurrency_level = 'new_concurrency_level'
100
+
101
+ cloud.api_key = 'new_api_key'
102
+ cloud.username = 'new_username'
103
+ cloud.container = 'new_container'
104
+ cloud.auth_url = 'new_auth_url'
105
+ cloud.servicenet = 'new_servicenet'
106
+ end
107
+
108
+ syncer.path.should == 'new_path'
109
+ syncer.mirror.should == 'new_mirror'
110
+ syncer.directories.should == []
111
+ syncer.concurrency_type.should == 'new_concurrency_type'
112
+ syncer.concurrency_level.should == 'new_concurrency_level'
113
+
114
+ syncer.api_key.should == 'new_api_key'
115
+ syncer.username.should == 'new_username'
116
+ syncer.container.should == 'new_container'
117
+ syncer.auth_url.should == 'new_auth_url'
118
+ syncer.servicenet.should == 'new_servicenet'
119
+ end
120
+ end # context 'when pre-configured defaults have been set'
121
+ end # describe '#initialize'
122
+
123
+ describe '#connection' do
124
+ let(:connection) { mock }
125
+
126
+ before do
127
+ Fog::Storage.expects(:new).once.with(
128
+ :provider => 'Rackspace',
129
+ :rackspace_username => 'my_username',
130
+ :rackspace_api_key => 'my_api_key',
131
+ :rackspace_auth_url => 'my_auth_url',
132
+ :rackspace_servicenet => true
133
+ ).returns(connection)
134
+ end
135
+
136
+ it 'should establish and re-use the connection' do
137
+ syncer.send(:connection).should == connection
138
+ syncer.instance_variable_get(:@connection).should == connection
139
+ syncer.send(:connection).should == connection
140
+ end
141
+ end
142
+
143
+ describe '#repository_object' do
144
+ let(:connection) { mock }
145
+ let(:directories) { mock }
146
+ let(:container) { mock }
147
+
148
+ before do
149
+ syncer.stubs(:connection).returns(connection)
150
+ connection.stubs(:directories).returns(directories)
151
+ end
152
+
153
+ context 'when the @container does not exist' do
154
+ before do
155
+ directories.expects(:get).once.with('my_container').returns(nil)
156
+ directories.expects(:create).once.with(
157
+ :key => 'my_container'
158
+ ).returns(container)
159
+ end
160
+
161
+ it 'should create and re-use the container' do
162
+ syncer.send(:repository_object).should == container
163
+ syncer.instance_variable_get(:@repository_object).should == container
164
+ syncer.send(:repository_object).should == container
165
+ end
166
+ end
167
+
168
+ context 'when the @container does exist' do
169
+ before do
170
+ directories.expects(:get).once.with('my_container').returns(container)
171
+ directories.expects(:create).never
172
+ end
173
+
174
+ it 'should retrieve and re-use the container' do
175
+ syncer.send(:repository_object).should == container
176
+ syncer.instance_variable_get(:@repository_object).should == container
177
+ syncer.send(:repository_object).should == container
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,174 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
3
+
4
+ describe 'Backup::Syncer::Cloud::S3' do
5
+ let(:syncer) do
6
+ Backup::Syncer::Cloud::S3.new do |s3|
7
+ s3.access_key_id = 'my_access_key_id'
8
+ s3.secret_access_key = 'my_secret_access_key'
9
+ s3.bucket = 'my_bucket'
10
+ s3.region = 'my_region'
11
+ end
12
+ end
13
+
14
+ it 'should be a subclass of Syncer::Cloud::Base' do
15
+ Backup::Syncer::Cloud::S3.
16
+ superclass.should == Backup::Syncer::Cloud::Base
17
+ end
18
+
19
+ describe '#initialize' do
20
+ after { Backup::Syncer::Cloud::S3.clear_defaults! }
21
+
22
+ it 'should load pre-configured defaults through Syncer::Cloud::Base' do
23
+ Backup::Syncer::Cloud::S3.any_instance.expects(:load_defaults!)
24
+ syncer
25
+ end
26
+
27
+ it 'should strip any leading slash in path' do
28
+ syncer = Backup::Syncer::Cloud::S3.new do |cloud|
29
+ cloud.path = '/cleaned/path'
30
+ end
31
+ syncer.path.should == 'cleaned/path'
32
+ end
33
+
34
+ context 'when no pre-configured defaults have been set' do
35
+ it 'should use the values given' do
36
+ syncer.access_key_id.should == 'my_access_key_id'
37
+ syncer.secret_access_key.should == 'my_secret_access_key'
38
+ syncer.bucket.should == 'my_bucket'
39
+ syncer.region.should == 'my_region'
40
+ end
41
+
42
+ it 'should use default values if none are given' do
43
+ syncer = Backup::Syncer::Cloud::S3.new
44
+
45
+ # from Syncer::Base
46
+ syncer.path.should == 'backups'
47
+ syncer.mirror.should == false
48
+ syncer.directories.should == []
49
+
50
+ # from Syncer::Cloud::Base
51
+ syncer.concurrency_type.should == false
52
+ syncer.concurrency_level.should == 2
53
+
54
+ syncer.access_key_id.should be_nil
55
+ syncer.secret_access_key.should be_nil
56
+ syncer.bucket.should be_nil
57
+ syncer.region.should be_nil
58
+ end
59
+ end # context 'when no pre-configured defaults have been set'
60
+
61
+ context 'when pre-configured defaults have been set' do
62
+ before do
63
+ Backup::Syncer::Cloud::S3.defaults do |cloud|
64
+ cloud.access_key_id = 'default_access_key_id'
65
+ cloud.secret_access_key = 'default_secret_access_key'
66
+ cloud.bucket = 'default_bucket'
67
+ cloud.region = 'default_region'
68
+ end
69
+ end
70
+
71
+ it 'should use pre-configured defaults' do
72
+ syncer = Backup::Syncer::Cloud::S3.new
73
+
74
+ # from Syncer::Base
75
+ syncer.path.should == 'backups'
76
+ syncer.mirror.should == false
77
+ syncer.directories.should == []
78
+
79
+ # from Syncer::Cloud::Base
80
+ syncer.concurrency_type.should == false
81
+ syncer.concurrency_level.should == 2
82
+
83
+ syncer.access_key_id.should == 'default_access_key_id'
84
+ syncer.secret_access_key.should == 'default_secret_access_key'
85
+ syncer.bucket.should == 'default_bucket'
86
+ syncer.region.should == 'default_region'
87
+ end
88
+
89
+ it 'should override pre-configured defaults' do
90
+ syncer = Backup::Syncer::Cloud::S3.new do |cloud|
91
+ cloud.path = 'new_path'
92
+ cloud.mirror = 'new_mirror'
93
+ cloud.concurrency_type = 'new_concurrency_type'
94
+ cloud.concurrency_level = 'new_concurrency_level'
95
+
96
+ cloud.access_key_id = 'new_access_key_id'
97
+ cloud.secret_access_key = 'new_secret_access_key'
98
+ cloud.bucket = 'new_bucket'
99
+ cloud.region = 'new_region'
100
+ end
101
+
102
+ syncer.path.should == 'new_path'
103
+ syncer.mirror.should == 'new_mirror'
104
+ syncer.directories.should == []
105
+ syncer.concurrency_type.should == 'new_concurrency_type'
106
+ syncer.concurrency_level.should == 'new_concurrency_level'
107
+
108
+ syncer.access_key_id.should == 'new_access_key_id'
109
+ syncer.secret_access_key.should == 'new_secret_access_key'
110
+ syncer.bucket.should == 'new_bucket'
111
+ syncer.region.should == 'new_region'
112
+ end
113
+ end # context 'when pre-configured defaults have been set'
114
+ end # describe '#initialize'
115
+
116
+ describe '#connection' do
117
+ let(:connection) { mock }
118
+
119
+ before do
120
+ Fog::Storage.expects(:new).once.with(
121
+ :provider => 'AWS',
122
+ :aws_access_key_id => 'my_access_key_id',
123
+ :aws_secret_access_key => 'my_secret_access_key',
124
+ :region => 'my_region'
125
+ ).returns(connection)
126
+ end
127
+
128
+ it 'should establish and re-use the connection' do
129
+ syncer.send(:connection).should == connection
130
+ syncer.instance_variable_get(:@connection).should == connection
131
+ syncer.send(:connection).should == connection
132
+ end
133
+ end
134
+
135
+ describe '#repository_object' do
136
+ let(:connection) { mock }
137
+ let(:directories) { mock }
138
+ let(:bucket) { mock }
139
+
140
+ before do
141
+ syncer.stubs(:connection).returns(connection)
142
+ connection.stubs(:directories).returns(directories)
143
+ end
144
+
145
+ context 'when the @bucket does not exist' do
146
+ before do
147
+ directories.expects(:get).once.with('my_bucket').returns(nil)
148
+ directories.expects(:create).once.with(
149
+ :key => 'my_bucket',
150
+ :location => 'my_region'
151
+ ).returns(bucket)
152
+ end
153
+
154
+ it 'should create and re-use the bucket' do
155
+ syncer.send(:repository_object).should == bucket
156
+ syncer.instance_variable_get(:@repository_object).should == bucket
157
+ syncer.send(:repository_object).should == bucket
158
+ end
159
+ end
160
+
161
+ context 'when the @bucket does exist' do
162
+ before do
163
+ directories.expects(:get).once.with('my_bucket').returns(bucket)
164
+ directories.expects(:create).never
165
+ end
166
+
167
+ it 'should retrieve and re-use the bucket' do
168
+ syncer.send(:repository_object).should == bucket
169
+ syncer.instance_variable_get(:@repository_object).should == bucket
170
+ syncer.send(:repository_object).should == bucket
171
+ end
172
+ end
173
+ end
174
+ end
@@ -2,81 +2,54 @@
2
2
 
3
3
  require File.expand_path('../../../spec_helper.rb', __FILE__)
4
4
 
5
- describe Backup::Syncer::RSync::Base do
5
+ describe 'Backup::Syncer::RSync::Base' do
6
6
  let(:syncer) { Backup::Syncer::RSync::Base.new }
7
7
 
8
+ it 'should be a subclass of Syncer::Base' do
9
+ Backup::Syncer::RSync::Base.
10
+ superclass.should == Backup::Syncer::Base
11
+ end
12
+
8
13
  describe '#initialize' do
14
+ after { Backup::Syncer::RSync::Base.clear_defaults! }
9
15
 
10
- it 'should use default values' do
11
- syncer.path.should == 'backups'
12
- syncer.directories.should == []
13
- syncer.mirror.should == false
14
- syncer.additional_options.should == []
16
+ it 'should load pre-configured defaults through Syncer::Base' do
17
+ Backup::Syncer::RSync::Base.any_instance.expects(:load_defaults!)
18
+ syncer
15
19
  end
16
20
 
17
- context 'when setting configuration defaults' do
18
- after { Backup::Configuration::Syncer::RSync::Base.clear_defaults! }
21
+ context 'when no pre-configured defaults have been set' do
22
+ it 'should use default values' do
23
+ syncer.path.should == 'backups'
24
+ syncer.mirror.should == false
25
+ syncer.directories.should == []
26
+ syncer.additional_options.should == []
27
+ end
28
+ end # context 'when no pre-configured defaults have been set'
19
29
 
20
- it 'should use the configured defaults' do
21
- Backup::Configuration::Syncer::RSync::Base.defaults do |rsync|
22
- rsync.path = 'some_path'
23
- #rsync.directories = 'cannot_have_a_default_value'
24
- rsync.mirror = 'some_mirror'
30
+ context 'when pre-configured defaults have been set' do
31
+ before do
32
+ Backup::Syncer::RSync::Base.defaults do |rsync|
33
+ rsync.path = 'some_path'
34
+ rsync.mirror = 'some_mirror'
25
35
  rsync.additional_options = 'some_additional_options'
26
36
  end
27
- syncer = Backup::Syncer::RSync::Base.new
28
- syncer.path.should == 'some_path'
29
- syncer.directories.should == []
30
- syncer.mirror.should == 'some_mirror'
31
- syncer.additional_options.should == 'some_additional_options'
32
- end
33
- end
34
-
35
- end # describe '#initialize'
36
-
37
- describe '#directories' do
38
- before do
39
- syncer.directories = ['/some/directory', '/another/directory']
40
- end
41
-
42
- context 'when no block is given' do
43
- it 'should return @directories' do
44
- syncer.directories.should ==
45
- ['/some/directory', '/another/directory']
46
37
  end
47
- end
48
38
 
49
- context 'when a block is given' do
50
- it 'should evalute the block, allowing #add to add directories' do
51
- syncer.directories do
52
- add '/new/path'
53
- add '/another/new/path'
54
- end
55
- syncer.directories.should == [
56
- '/some/directory',
57
- '/another/directory',
58
- '/new/path',
59
- '/another/new/path'
60
- ]
39
+ it 'should use pre-configured defaults' do
40
+ syncer.path.should == 'some_path'
41
+ syncer.mirror.should == 'some_mirror'
42
+ syncer.directories.should == []
43
+ syncer.additional_options.should == 'some_additional_options'
61
44
  end
62
- end
63
- end # describe '#directories'
64
-
65
- describe '#add' do
66
- before do
67
- syncer.directories = ['/some/directory', '/another/directory']
68
- end
69
-
70
- it 'should add the given path to @directories' do
71
- syncer.add '/my/path'
72
- syncer.directories.should ==
73
- ['/some/directory', '/another/directory', '/my/path']
74
- end
75
- end
45
+ end # context 'when pre-configured defaults have been set'
46
+ end # describe '#initialize'
76
47
 
77
48
  describe '#directory_options' do
78
49
  before do
79
- syncer.directories = ['/some/directory', '/another/directory']
50
+ syncer.instance_variable_set(
51
+ :@directories, ['/some/directory', '/another/directory']
52
+ )
80
53
  end
81
54
 
82
55
  it 'should return the directories for use in the command line' do
@@ -84,12 +57,19 @@ describe Backup::Syncer::RSync::Base do
84
57
  "'/some/directory' '/another/directory'"
85
58
  end
86
59
 
87
- it 'should expand relative paths' do
88
- syncer.directories += ['relative/path', '~/home/path']
89
- syncer.send(:directories_option).should ==
90
- "'/some/directory' '/another/directory' " +
91
- "'#{ File.expand_path('relative/path') }' " +
92
- "'#{ File.expand_path('~/home/path') }'"
60
+ context 'when @directories have relative paths' do
61
+ before do
62
+ syncer.instance_variable_set(
63
+ :@directories, ['/some/directory', '/another/directory',
64
+ 'relative/path', '~/home/path']
65
+ )
66
+ end
67
+ it 'should expand relative paths' do
68
+ syncer.send(:directories_option).should ==
69
+ "'/some/directory' '/another/directory' " +
70
+ "'#{ File.expand_path('relative/path') }' " +
71
+ "'#{ File.expand_path('~/home/path') }'"
72
+ end
93
73
  end
94
74
  end
95
75