asset_cloud 2.5.1 → 2.7.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +326 -0
- data/.travis.yml +6 -0
- data/History.md +10 -0
- data/README.rdoc +20 -0
- data/Rakefile +5 -2
- data/asset_cloud.gemspec +2 -3
- data/lib/asset_cloud/asset.rb +4 -0
- data/lib/asset_cloud/base.rb +11 -1
- data/lib/asset_cloud/buckets/gcs_bucket.rb +1 -1
- data/lib/asset_cloud/metadata.rb +10 -3
- data/spec/active_record_bucket_spec.rb +27 -27
- data/spec/asset_cloud/metadata_spec.rb +31 -0
- data/spec/asset_extension_spec.rb +21 -18
- data/spec/asset_spec.rb +47 -56
- data/spec/base_spec.rb +81 -62
- data/spec/blackhole_bucket_spec.rb +6 -5
- data/spec/bucket_chain_spec.rb +50 -50
- data/spec/bucket_spec.rb +5 -4
- data/spec/callbacks_spec.rb +31 -31
- data/spec/file_system_spec.rb +15 -16
- data/spec/find_free_key_spec.rb +17 -19
- data/spec/gcs_bucket_remote_spec.rb +18 -19
- data/spec/gcs_bucket_spec.rb +50 -36
- data/spec/memory_bucket_spec.rb +8 -9
- data/spec/mock_s3_interface.rb +4 -3
- data/spec/remote_s3_bucket_spec.rb +17 -16
- data/spec/s3_bucket_spec.rb +12 -12
- data/spec/spec_helper.rb +2 -1
- data/spec/validations_spec.rb +18 -16
- data/spec/versioned_memory_bucket_spec.rb +6 -6
- metadata +9 -19
data/spec/base_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
class SpecialAsset < AssetCloud::Asset
|
@@ -6,82 +7,87 @@ end
|
|
6
7
|
class LiquidAsset < AssetCloud::Asset
|
7
8
|
end
|
8
9
|
|
10
|
+
class BrokenBucket < AssetCloud::Bucket
|
11
|
+
def write(*)
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
9
16
|
class BasicCloud < AssetCloud::Base
|
10
17
|
bucket :special, AssetCloud::MemoryBucket, asset_class: SpecialAsset
|
11
|
-
bucket :conditional, AssetCloud::MemoryBucket, asset_class:
|
18
|
+
bucket :conditional, AssetCloud::MemoryBucket, asset_class: proc { |key|
|
12
19
|
LiquidAsset if key.ends_with?('.liquid')
|
13
20
|
}
|
21
|
+
bucket :broken, BrokenBucket, asset_class: AssetCloud::Asset
|
14
22
|
end
|
15
23
|
|
16
24
|
describe BasicCloud do
|
17
25
|
directory = File.dirname(__FILE__) + '/files'
|
18
26
|
|
19
27
|
before do
|
20
|
-
@fs = BasicCloud.new(directory
|
28
|
+
@fs = BasicCloud.new(directory, 'http://assets/files')
|
21
29
|
end
|
22
30
|
|
23
31
|
it "should raise invalid bucket if none is given" do
|
24
|
-
@fs['image.jpg'].exist
|
32
|
+
expect(@fs['image.jpg'].exist?).to(eq(false))
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
35
|
it "should be backed by a file system bucket" do
|
29
|
-
@fs['products/key.txt'].exist
|
36
|
+
expect(@fs['products/key.txt'].exist?).to(eq(true))
|
30
37
|
end
|
31
38
|
|
32
39
|
it "should raise when listing non existing buckets" do
|
33
|
-
@fs.ls('products').
|
40
|
+
expect(@fs.ls('products')).to(eq([AssetCloud::Asset.new(@fs, 'products/key.txt')]))
|
34
41
|
end
|
35
42
|
|
36
|
-
|
37
43
|
it "should allow you to create new assets" do
|
38
44
|
obj = @fs.build('new_file.test')
|
39
|
-
obj.
|
40
|
-
obj.cloud.
|
45
|
+
expect(obj).to(be_an_instance_of(AssetCloud::Asset))
|
46
|
+
expect(obj.cloud).to(be_an_instance_of(BasicCloud))
|
41
47
|
end
|
42
48
|
|
43
49
|
it "should raise error when using with minus relative or absolute paths" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
expect { @fs['../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
51
|
+
expect { @fs['/test'] }.to(raise_error(AssetCloud::IllegalPath))
|
52
|
+
expect { @fs['.../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
53
|
+
expect { @fs['./test'] }.to(raise_error(AssetCloud::IllegalPath))
|
48
54
|
end
|
49
55
|
|
50
56
|
it "should raise error when filename has trailing period" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
expect { @fs['test.'] }.to(raise_error(AssetCloud::IllegalPath))
|
58
|
+
expect { @fs['/test/testfile.'] }.to(raise_error(AssetCloud::IllegalPath))
|
59
|
+
expect { @fs['test/directory/.'] }.to(raise_error(AssetCloud::IllegalPath))
|
60
|
+
expect { @fs['/test/testfile .'] }.to(raise_error(AssetCloud::IllegalPath))
|
61
|
+
expect { @fs['test/directory /.'] }.to(raise_error(AssetCloud::IllegalPath))
|
56
62
|
end
|
57
63
|
|
58
64
|
it "should raise error when filename ends with space" do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
expect { @fs['test '] }.to(raise_error(AssetCloud::IllegalPath))
|
66
|
+
expect { @fs['/test/testfile '] }.to(raise_error(AssetCloud::IllegalPath))
|
67
|
+
expect { @fs['test/directory/ '] }.to(raise_error(AssetCloud::IllegalPath))
|
68
|
+
expect { @fs['test. '] }.to(raise_error(AssetCloud::IllegalPath))
|
69
|
+
expect { @fs['/test/testfile. '] }.to(raise_error(AssetCloud::IllegalPath))
|
70
|
+
expect { @fs['test/directory/. '] }.to(raise_error(AssetCloud::IllegalPath))
|
65
71
|
end
|
66
72
|
|
67
73
|
it "should raise error when filename ends with slash" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
expect { @fs['test/'] }.to(raise_error(AssetCloud::IllegalPath))
|
75
|
+
expect { @fs['test/directory/'] }.to(raise_error(AssetCloud::IllegalPath))
|
76
|
+
expect { @fs['test /'] }.to(raise_error(AssetCloud::IllegalPath))
|
77
|
+
expect { @fs['/test/testfile /'] }.to(raise_error(AssetCloud::IllegalPath))
|
78
|
+
expect { @fs['test/directory//'] }.to(raise_error(AssetCloud::IllegalPath))
|
73
79
|
end
|
74
80
|
|
75
81
|
it "should raise error when using with minus relative even after another directory" do
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
expect { @fs['test/../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
83
|
+
expect { @fs['test/../../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
84
|
+
expect { @fs['test/../../../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
79
85
|
end
|
80
86
|
|
81
87
|
it "should raise an error when using names with combinations of '.' and ' '" do
|
82
|
-
|
83
|
-
|
84
|
-
|
88
|
+
expect { @fs['test. . . .. ... .. . '] }.to(raise_error(AssetCloud::IllegalPath))
|
89
|
+
expect { @fs['test. .'] }.to(raise_error(AssetCloud::IllegalPath))
|
90
|
+
expect { @fs['test. .test2'] }.to(raise_error(AssetCloud::IllegalPath))
|
85
91
|
end
|
86
92
|
|
87
93
|
it "should allow filenames with repeating dots" do
|
@@ -125,41 +131,41 @@ describe BasicCloud do
|
|
125
131
|
end
|
126
132
|
|
127
133
|
it "should compute complete urls to assets" do
|
128
|
-
@fs.url_for('products/key with spaces.txt').
|
134
|
+
expect(@fs.url_for('products/[key] with spaces.txt?foo=1&bar=2')).to(eq('http://assets/files/products/[key]%20with%20spaces.txt?foo=1&bar=2'))
|
129
135
|
end
|
130
136
|
|
131
137
|
describe "#find" do
|
132
138
|
it "should return the appropriate asset when one exists" do
|
133
139
|
asset = @fs.find('products/key.txt')
|
134
|
-
asset.key.
|
135
|
-
asset.value.
|
140
|
+
expect(asset.key).to(eq('products/key.txt'))
|
141
|
+
expect(asset.value).to(eq('value'))
|
136
142
|
end
|
137
143
|
it "should raise AssetNotFoundError when the asset doesn't exist" do
|
138
|
-
|
144
|
+
expect { @fs.find('products/not-there.txt') }.to(raise_error(AssetCloud::AssetNotFoundError))
|
139
145
|
end
|
140
146
|
end
|
141
147
|
|
142
148
|
describe "#[]" do
|
143
149
|
it "should return the appropriate asset when one exists" do
|
144
150
|
asset = @fs['products/key.txt']
|
145
|
-
asset.key.
|
146
|
-
asset.value.
|
151
|
+
expect(asset.key).to(eq('products/key.txt'))
|
152
|
+
expect(asset.value).to(eq('value'))
|
147
153
|
end
|
148
154
|
it "should not raise any errors when the asset doesn't exist" do
|
149
|
-
|
155
|
+
expect { @fs['products/not-there.txt'] }.not_to(raise_error)
|
150
156
|
end
|
151
157
|
end
|
152
158
|
|
153
159
|
describe "#move" do
|
154
160
|
it "should return move a resource" do
|
155
161
|
asset = @fs['products/key.txt']
|
156
|
-
asset.key.
|
157
|
-
asset.value.
|
162
|
+
expect(asset.key).to(eq('products/key.txt'))
|
163
|
+
expect(asset.value).to(eq('value'))
|
158
164
|
@fs.move('products/key.txt', 'products/key2.txt')
|
159
165
|
new_asset = @fs['products/key2.txt']
|
160
|
-
new_asset.key.
|
161
|
-
new_asset.value.
|
162
|
-
expect {@fs['products/key.txt'].value }.to
|
166
|
+
expect(new_asset.key).to(eq('products/key2.txt'))
|
167
|
+
expect(new_asset.value).to(eq('value'))
|
168
|
+
expect { @fs['products/key.txt'].value }.to(raise_error(AssetCloud::AssetNotFoundError))
|
163
169
|
@fs.move('products/key2.txt', 'products/key.txt')
|
164
170
|
end
|
165
171
|
end
|
@@ -167,46 +173,59 @@ describe BasicCloud do
|
|
167
173
|
describe "#[]=" do
|
168
174
|
it "should write through the Asset object (and thus run any callbacks on the asset)" do
|
169
175
|
special_asset = double(:special_asset)
|
170
|
-
special_asset.
|
171
|
-
special_asset.
|
172
|
-
SpecialAsset.
|
176
|
+
expect(special_asset).to(receive(:value=).with('fancy fancy!'))
|
177
|
+
expect(special_asset).to(receive(:store))
|
178
|
+
expect(SpecialAsset).to(receive(:at).and_return(special_asset))
|
173
179
|
@fs['special/fancy.txt'] = 'fancy fancy!'
|
174
180
|
end
|
175
181
|
end
|
176
182
|
|
177
183
|
describe "#bucket" do
|
178
184
|
it "should allow specifying a class to use for assets in this bucket" do
|
179
|
-
@fs['assets/rails_logo.gif'].
|
180
|
-
@fs['special/fancy.txt'].
|
185
|
+
expect(@fs['assets/rails_logo.gif']).to(be_instance_of(AssetCloud::Asset))
|
186
|
+
expect(@fs['special/fancy.txt']).to(be_instance_of(SpecialAsset))
|
181
187
|
|
182
|
-
@fs.build('assets/foo').
|
183
|
-
@fs.build('special/foo').
|
188
|
+
expect(@fs.build('assets/foo')).to(be_instance_of(AssetCloud::Asset))
|
189
|
+
expect(@fs.build('special/foo')).to(be_instance_of(SpecialAsset))
|
184
190
|
end
|
185
191
|
|
186
192
|
it "should allow specifying a proc that determines the class to use, using the default bucket when returning nil" do
|
187
|
-
@fs.build('conditional/default.js').
|
188
|
-
@fs.build('conditional/better.liquid').
|
193
|
+
expect(@fs.build('conditional/default.js')).to(be_instance_of(AssetCloud::Asset))
|
194
|
+
expect(@fs.build('conditional/better.liquid')).to(be_instance_of(LiquidAsset))
|
189
195
|
end
|
190
196
|
|
191
197
|
it "should raise " do
|
192
|
-
expect { BasicCloud.bucket(AssetCloud::MemoryBucket, asset_class:
|
198
|
+
expect { BasicCloud.bucket(AssetCloud::MemoryBucket, asset_class: proc {}) }.to(raise_error(ArgumentError))
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "write!" do
|
203
|
+
it "should write through the Asset object (and thus run any callbacks on the asset)" do
|
204
|
+
special_asset = double(:special_asset)
|
205
|
+
expect(special_asset).to(receive(:value=).with('fancy fancy!'))
|
206
|
+
expect(special_asset).to(receive(:store!))
|
207
|
+
expect(SpecialAsset).to(receive(:at).and_return(special_asset))
|
208
|
+
@fs.write!('special/fancy.txt', 'fancy fancy!')
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should raise AssetNotSaved when write fails" do
|
212
|
+
expect { @fs.write!('broken/file.txt', 'n/a') }.to(raise_error(AssetCloud::AssetNotSaved))
|
193
213
|
end
|
194
214
|
end
|
195
215
|
|
196
216
|
describe "MATCH_BUCKET" do
|
197
217
|
it "should match following stuff " do
|
198
|
-
|
199
218
|
'products/key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
200
|
-
|
219
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
201
220
|
|
202
221
|
'products/subpath/key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
203
|
-
|
222
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
204
223
|
|
205
224
|
'key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
206
|
-
|
225
|
+
expect(Regexp.last_match(1)).to(eq(nil))
|
207
226
|
|
208
227
|
'products' =~ AssetCloud::Base::MATCH_BUCKET
|
209
|
-
|
228
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
210
229
|
end
|
211
230
|
end
|
212
231
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
class BlackholeCloud < AssetCloud::Base
|
@@ -8,7 +9,7 @@ describe BlackholeCloud do
|
|
8
9
|
directory = File.dirname(__FILE__) + '/files'
|
9
10
|
|
10
11
|
before do
|
11
|
-
@fs = BlackholeCloud.new(directory
|
12
|
+
@fs = BlackholeCloud.new(directory, 'http://assets/files')
|
12
13
|
end
|
13
14
|
|
14
15
|
it "should allow access to files using the [] operator" do
|
@@ -16,12 +17,12 @@ describe BlackholeCloud do
|
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should return nil for non existent files" do
|
19
|
-
@fs['tmp/image.jpg'].exist
|
20
|
+
expect(@fs['tmp/image.jpg'].exist?).to(eq(false))
|
20
21
|
end
|
21
22
|
|
22
23
|
it "should still return nil, even if you wrote something there" do
|
23
24
|
@fs['tmp/image.jpg'] = 'test'
|
24
|
-
@fs['tmp/image.jpg'].exist
|
25
|
+
expect(@fs['tmp/image.jpg'].exist?).to(eq(false))
|
25
26
|
end
|
26
27
|
|
27
28
|
describe "when using a sub path" do
|
@@ -30,12 +31,12 @@ describe BlackholeCloud do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
it "should return nil for non existent files" do
|
33
|
-
@fs['tmp/image.jpg'].exist
|
34
|
+
expect(@fs['tmp/image.jpg'].exist?).to(eq(false))
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should still return nil, even if you wrote something there" do
|
37
38
|
@fs['tmp/image.jpg'] = 'test'
|
38
|
-
@fs['tmp/image.jpg'].exist
|
39
|
+
expect(@fs['tmp/image.jpg'].exist?).to(eq(false))
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/spec/bucket_chain_spec.rb
CHANGED
@@ -1,58 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
class ChainedCloud < AssetCloud::Base
|
4
|
-
bucket :stuff, AssetCloud::BucketChain.chain(
|
5
|
+
bucket :stuff, AssetCloud::BucketChain.chain(AssetCloud::MemoryBucket,
|
5
6
|
AssetCloud::MemoryBucket,
|
6
|
-
AssetCloud::FileSystemBucket
|
7
|
+
AssetCloud::FileSystemBucket)
|
7
8
|
|
8
|
-
bucket :versioned_stuff, AssetCloud::BucketChain.chain(
|
9
|
+
bucket :versioned_stuff, AssetCloud::BucketChain.chain(AssetCloud::FileSystemBucket,
|
9
10
|
AssetCloud::VersionedMemoryBucket,
|
10
|
-
AssetCloud::MemoryBucket
|
11
|
+
AssetCloud::MemoryBucket)
|
11
12
|
end
|
12
13
|
|
13
14
|
describe AssetCloud::BucketChain do
|
14
15
|
directory = File.dirname(__FILE__) + '/files'
|
15
16
|
|
16
17
|
before(:each) do
|
17
|
-
@cloud = ChainedCloud.new(directory
|
18
|
+
@cloud = ChainedCloud.new(directory, 'http://assets/files')
|
18
19
|
@bucket_chain = @cloud.buckets[:stuff]
|
19
20
|
@chained_buckets = @bucket_chain.chained_buckets
|
20
|
-
@chained_buckets.each {|b| b.ls('stuff').each
|
21
|
+
@chained_buckets.each { |b| b.ls('stuff').each(&:delete) }
|
21
22
|
|
22
23
|
@versioned_stuff = @cloud.buckets[:versioned_stuff]
|
23
24
|
end
|
24
25
|
|
25
26
|
describe ".chain" do
|
26
27
|
it 'should take multiple Bucket classes and return a new Bucket class' do
|
27
|
-
@bucket_chain.
|
28
|
+
expect(@bucket_chain).to(be_a_kind_of(AssetCloud::BucketChain))
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
describe "#write" do
|
32
33
|
it 'should write to each sub-bucket when everything is kosher and return the result of the first write' do
|
33
34
|
@chained_buckets.each do |bucket|
|
34
|
-
bucket.
|
35
|
+
expect(bucket).to(receive(:write).with('stuff/foo', 'successful creation').and_return('successful creation'))
|
35
36
|
end
|
36
37
|
|
37
|
-
@bucket_chain.write('stuff/foo', 'successful creation').
|
38
|
+
expect(@bucket_chain.write('stuff/foo', 'successful creation')).to(eq('successful creation'))
|
38
39
|
end
|
39
40
|
it 'should roll back creation-writes and re-raise an error when a bucket raises one' do
|
40
|
-
@chained_buckets.last.
|
41
|
+
expect(@chained_buckets.last).to(receive(:write).with('stuff/foo', 'unsuccessful creation').and_raise('hell'))
|
41
42
|
@chained_buckets[0..-2].each do |bucket|
|
42
|
-
bucket.
|
43
|
-
bucket.
|
43
|
+
expect(bucket).to(receive(:write).with('stuff/foo', 'unsuccessful creation').and_return(true))
|
44
|
+
expect(bucket).to(receive(:delete).with('stuff/foo').and_return(true))
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
+
expect { @bucket_chain.write('stuff/foo', 'unsuccessful creation') }.to(raise_error(RuntimeError))
|
47
48
|
end
|
48
49
|
it 'should roll back update-writes and re-raise an error when a bucket raises one' do
|
49
50
|
@bucket_chain.write('stuff/foo', "original value")
|
50
51
|
|
51
|
-
@chained_buckets.last.
|
52
|
+
expect(@chained_buckets.last).to(receive(:write).with('stuff/foo', 'new value').and_raise('hell'))
|
52
53
|
|
53
|
-
|
54
|
+
expect { @bucket_chain.write('stuff/foo', 'new value') }.to(raise_error(RuntimeError))
|
54
55
|
@chained_buckets.each do |bucket|
|
55
|
-
bucket.read('stuff/foo').
|
56
|
+
expect(bucket.read('stuff/foo')).to(eq('original value'))
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
@@ -62,7 +63,7 @@ describe AssetCloud::BucketChain do
|
|
62
63
|
@bucket_chain.write('stuff/foo', "successful deletion comin' up")
|
63
64
|
|
64
65
|
@chained_buckets.each do |bucket|
|
65
|
-
bucket.
|
66
|
+
expect(bucket).to(receive(:delete).with('stuff/foo').and_return(true))
|
66
67
|
end
|
67
68
|
|
68
69
|
@bucket_chain.delete('stuff/foo')
|
@@ -70,47 +71,46 @@ describe AssetCloud::BucketChain do
|
|
70
71
|
it 'should roll back deletions and re-raise an error when a bucket raises one' do
|
71
72
|
@bucket_chain.write('stuff/foo', "this deletion will fail")
|
72
73
|
|
73
|
-
@chained_buckets.last.
|
74
|
+
expect(@chained_buckets.last).to(receive(:delete).with('stuff/foo').and_raise('hell'))
|
74
75
|
@chained_buckets[0..-2].each do |bucket|
|
75
|
-
bucket.
|
76
|
-
bucket.
|
76
|
+
expect(bucket).to(receive(:delete).with('stuff/foo').and_return(true))
|
77
|
+
expect(bucket).to(receive(:write).with('stuff/foo', 'this deletion will fail').and_return(true))
|
77
78
|
end
|
78
79
|
|
79
|
-
|
80
|
+
expect { @bucket_chain.delete('stuff/foo') }.to(raise_error(RuntimeError))
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
84
|
describe "#read" do
|
84
85
|
it 'should read from only the first available sub-bucket' do
|
85
|
-
@chained_buckets[0].
|
86
|
-
@chained_buckets[0].
|
87
|
-
@chained_buckets[0].
|
86
|
+
expect(@chained_buckets[0]).to(receive(:read).with('stuff/foo').and_raise(NotImplementedError))
|
87
|
+
expect(@chained_buckets[0]).to(receive(:ls).with(nil).and_raise(NoMethodError))
|
88
|
+
expect(@chained_buckets[0]).to(receive(:stat).and_return(:metadata))
|
88
89
|
|
89
|
-
@chained_buckets[1].
|
90
|
-
@chained_buckets[1].
|
91
|
-
@chained_buckets[1].
|
90
|
+
expect(@chained_buckets[1]).to(receive(:read).with('stuff/foo').and_return('bar'))
|
91
|
+
expect(@chained_buckets[1]).to(receive(:ls).with(nil).and_return(:some_assets))
|
92
|
+
expect(@chained_buckets[1]).not_to(receive(:stat))
|
92
93
|
|
93
94
|
@chained_buckets[2..-1].each do |bucket|
|
94
|
-
bucket.
|
95
|
-
bucket.
|
96
|
-
bucket.
|
95
|
+
expect(bucket).not_to(receive(:read))
|
96
|
+
expect(bucket).not_to(receive(:ls))
|
97
|
+
expect(bucket).not_to(receive(:stat))
|
97
98
|
end
|
98
99
|
|
99
|
-
@bucket_chain.read('stuff/foo').
|
100
|
-
@bucket_chain.ls.
|
101
|
-
@bucket_chain.stat.
|
100
|
+
expect(@bucket_chain.read('stuff/foo')).to(eq('bar'))
|
101
|
+
expect(@bucket_chain.ls).to(eq(:some_assets))
|
102
|
+
expect(@bucket_chain.stat).to(eq(:metadata))
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
106
|
describe "#read_version" do
|
107
107
|
it 'should read from only the first available sub-bucket' do
|
108
108
|
buckets = @versioned_stuff.chained_buckets
|
109
109
|
|
110
|
-
buckets[1].
|
111
|
-
buckets.last.
|
110
|
+
expect(buckets[1]).to(receive(:read_version).with('stuff/foo', 3).and_return('bar'))
|
111
|
+
expect(buckets.last).not_to(receive(:read_version))
|
112
112
|
|
113
|
-
@versioned_stuff.read_version('stuff/foo', 3).
|
113
|
+
expect(@versioned_stuff.read_version('stuff/foo', 3)).to(eq('bar'))
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -118,10 +118,10 @@ describe AssetCloud::BucketChain do
|
|
118
118
|
it 'should read from only the first available sub-bucket' do
|
119
119
|
buckets = @versioned_stuff.chained_buckets
|
120
120
|
|
121
|
-
buckets[1].
|
122
|
-
buckets.last.
|
121
|
+
expect(buckets[1]).to(receive(:versions).with('versioned_stuff/foo').and_return([1, 2, 3]))
|
122
|
+
expect(buckets.last).not_to(receive(:versions))
|
123
123
|
|
124
|
-
@versioned_stuff.versions('versioned_stuff/foo').
|
124
|
+
expect(@versioned_stuff.versions('versioned_stuff/foo')).to(eq([1, 2, 3]))
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -131,28 +131,28 @@ describe AssetCloud::BucketChain do
|
|
131
131
|
@cloud['versioned_stuff/foo'] = content
|
132
132
|
end
|
133
133
|
asset = @cloud['versioned_stuff/foo']
|
134
|
-
asset.value.
|
135
|
-
asset.rollback(1).value.
|
136
|
-
asset.versions.
|
134
|
+
expect(asset.value).to(eq('three'))
|
135
|
+
expect(asset.rollback(1).value).to(eq('one'))
|
136
|
+
expect(asset.versions).to(eq([1, 2, 3]))
|
137
137
|
asset.value = 'four'
|
138
138
|
asset.store
|
139
|
-
asset.versions.
|
139
|
+
expect(asset.versions).to(eq([1, 2, 3, 4]))
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
describe '#respond_to?' do
|
144
144
|
it 'should return true if any chained buckets respond to the given method' do
|
145
|
-
@bucket_chain.respond_to?(:foo).
|
146
|
-
@chained_buckets[1].
|
147
|
-
@bucket_chain.respond_to?(:bar).
|
145
|
+
expect(@bucket_chain.respond_to?(:foo)).to(eq(false))
|
146
|
+
expect(@chained_buckets[1]).to(receive(:respond_to?).with(:bar).and_return(true))
|
147
|
+
expect(@bucket_chain.respond_to?(:bar)).to(eq(true))
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
describe '#method_missing' do
|
152
152
|
it 'should try each bucket' do
|
153
|
-
@chained_buckets[1].
|
154
|
-
@chained_buckets[2].
|
155
|
-
@bucket_chain.buzz.
|
153
|
+
expect(@chained_buckets[1]).to(receive(:buzz).and_return(true))
|
154
|
+
expect(@chained_buckets[2]).not_to(receive(:buzz))
|
155
|
+
expect(@bucket_chain.buzz).to(eq(true))
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|