asset_cloud 2.5.0 → 2.6.1
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 +6 -0
- data/README.rdoc +8 -0
- data/Rakefile +5 -2
- data/asset_cloud.gemspec +2 -2
- data/lib/asset_cloud.rb +1 -0
- data/lib/asset_cloud/asset.rb +4 -0
- data/lib/asset_cloud/base.rb +4 -2
- 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 +60 -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 -5
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
|
@@ -8,7 +9,7 @@ end
|
|
8
9
|
|
9
10
|
class BasicCloud < AssetCloud::Base
|
10
11
|
bucket :special, AssetCloud::MemoryBucket, asset_class: SpecialAsset
|
11
|
-
bucket :conditional, AssetCloud::MemoryBucket, asset_class:
|
12
|
+
bucket :conditional, AssetCloud::MemoryBucket, asset_class: proc { |key|
|
12
13
|
LiquidAsset if key.ends_with?('.liquid')
|
13
14
|
}
|
14
15
|
end
|
@@ -17,71 +18,69 @@ describe BasicCloud do
|
|
17
18
|
directory = File.dirname(__FILE__) + '/files'
|
18
19
|
|
19
20
|
before do
|
20
|
-
@fs = BasicCloud.new(directory
|
21
|
+
@fs = BasicCloud.new(directory, 'http://assets/files')
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should raise invalid bucket if none is given" do
|
24
|
-
@fs['image.jpg'].exist
|
25
|
+
expect(@fs['image.jpg'].exist?).to(eq(false))
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
28
|
it "should be backed by a file system bucket" do
|
29
|
-
@fs['products/key.txt'].exist
|
29
|
+
expect(@fs['products/key.txt'].exist?).to(eq(true))
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should raise when listing non existing buckets" do
|
33
|
-
@fs.ls('products').
|
33
|
+
expect(@fs.ls('products')).to(eq([AssetCloud::Asset.new(@fs, 'products/key.txt')]))
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
it "should allow you to create new assets" do
|
38
37
|
obj = @fs.build('new_file.test')
|
39
|
-
obj.
|
40
|
-
obj.cloud.
|
38
|
+
expect(obj).to(be_an_instance_of(AssetCloud::Asset))
|
39
|
+
expect(obj.cloud).to(be_an_instance_of(BasicCloud))
|
41
40
|
end
|
42
41
|
|
43
42
|
it "should raise error when using with minus relative or absolute paths" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
expect { @fs['../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
44
|
+
expect { @fs['/test'] }.to(raise_error(AssetCloud::IllegalPath))
|
45
|
+
expect { @fs['.../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
46
|
+
expect { @fs['./test'] }.to(raise_error(AssetCloud::IllegalPath))
|
48
47
|
end
|
49
48
|
|
50
49
|
it "should raise error when filename has trailing period" do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
expect { @fs['test.'] }.to(raise_error(AssetCloud::IllegalPath))
|
51
|
+
expect { @fs['/test/testfile.'] }.to(raise_error(AssetCloud::IllegalPath))
|
52
|
+
expect { @fs['test/directory/.'] }.to(raise_error(AssetCloud::IllegalPath))
|
53
|
+
expect { @fs['/test/testfile .'] }.to(raise_error(AssetCloud::IllegalPath))
|
54
|
+
expect { @fs['test/directory /.'] }.to(raise_error(AssetCloud::IllegalPath))
|
56
55
|
end
|
57
56
|
|
58
57
|
it "should raise error when filename ends with space" do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
expect { @fs['test '] }.to(raise_error(AssetCloud::IllegalPath))
|
59
|
+
expect { @fs['/test/testfile '] }.to(raise_error(AssetCloud::IllegalPath))
|
60
|
+
expect { @fs['test/directory/ '] }.to(raise_error(AssetCloud::IllegalPath))
|
61
|
+
expect { @fs['test. '] }.to(raise_error(AssetCloud::IllegalPath))
|
62
|
+
expect { @fs['/test/testfile. '] }.to(raise_error(AssetCloud::IllegalPath))
|
63
|
+
expect { @fs['test/directory/. '] }.to(raise_error(AssetCloud::IllegalPath))
|
65
64
|
end
|
66
65
|
|
67
66
|
it "should raise error when filename ends with slash" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
expect { @fs['test/'] }.to(raise_error(AssetCloud::IllegalPath))
|
68
|
+
expect { @fs['test/directory/'] }.to(raise_error(AssetCloud::IllegalPath))
|
69
|
+
expect { @fs['test /'] }.to(raise_error(AssetCloud::IllegalPath))
|
70
|
+
expect { @fs['/test/testfile /'] }.to(raise_error(AssetCloud::IllegalPath))
|
71
|
+
expect { @fs['test/directory//'] }.to(raise_error(AssetCloud::IllegalPath))
|
73
72
|
end
|
74
73
|
|
75
74
|
it "should raise error when using with minus relative even after another directory" do
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
expect { @fs['test/../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
76
|
+
expect { @fs['test/../../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
77
|
+
expect { @fs['test/../../../test'] }.to(raise_error(AssetCloud::IllegalPath))
|
79
78
|
end
|
80
79
|
|
81
80
|
it "should raise an error when using names with combinations of '.' and ' '" do
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
expect { @fs['test. . . .. ... .. . '] }.to(raise_error(AssetCloud::IllegalPath))
|
82
|
+
expect { @fs['test. .'] }.to(raise_error(AssetCloud::IllegalPath))
|
83
|
+
expect { @fs['test. .test2'] }.to(raise_error(AssetCloud::IllegalPath))
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should allow filenames with repeating dots" do
|
@@ -125,41 +124,41 @@ describe BasicCloud do
|
|
125
124
|
end
|
126
125
|
|
127
126
|
it "should compute complete urls to assets" do
|
128
|
-
@fs.url_for('products/key with spaces.txt').
|
127
|
+
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
128
|
end
|
130
129
|
|
131
130
|
describe "#find" do
|
132
131
|
it "should return the appropriate asset when one exists" do
|
133
132
|
asset = @fs.find('products/key.txt')
|
134
|
-
asset.key.
|
135
|
-
asset.value.
|
133
|
+
expect(asset.key).to(eq('products/key.txt'))
|
134
|
+
expect(asset.value).to(eq('value'))
|
136
135
|
end
|
137
136
|
it "should raise AssetNotFoundError when the asset doesn't exist" do
|
138
|
-
|
137
|
+
expect { @fs.find('products/not-there.txt') }.to(raise_error(AssetCloud::AssetNotFoundError))
|
139
138
|
end
|
140
139
|
end
|
141
140
|
|
142
141
|
describe "#[]" do
|
143
142
|
it "should return the appropriate asset when one exists" do
|
144
143
|
asset = @fs['products/key.txt']
|
145
|
-
asset.key.
|
146
|
-
asset.value.
|
144
|
+
expect(asset.key).to(eq('products/key.txt'))
|
145
|
+
expect(asset.value).to(eq('value'))
|
147
146
|
end
|
148
147
|
it "should not raise any errors when the asset doesn't exist" do
|
149
|
-
|
148
|
+
expect { @fs['products/not-there.txt'] }.not_to(raise_error)
|
150
149
|
end
|
151
150
|
end
|
152
151
|
|
153
152
|
describe "#move" do
|
154
153
|
it "should return move a resource" do
|
155
154
|
asset = @fs['products/key.txt']
|
156
|
-
asset.key.
|
157
|
-
asset.value.
|
155
|
+
expect(asset.key).to(eq('products/key.txt'))
|
156
|
+
expect(asset.value).to(eq('value'))
|
158
157
|
@fs.move('products/key.txt', 'products/key2.txt')
|
159
158
|
new_asset = @fs['products/key2.txt']
|
160
|
-
new_asset.key.
|
161
|
-
new_asset.value.
|
162
|
-
expect {@fs['products/key.txt'].value }.to
|
159
|
+
expect(new_asset.key).to(eq('products/key2.txt'))
|
160
|
+
expect(new_asset.value).to(eq('value'))
|
161
|
+
expect { @fs['products/key.txt'].value }.to(raise_error(AssetCloud::AssetNotFoundError))
|
163
162
|
@fs.move('products/key2.txt', 'products/key.txt')
|
164
163
|
end
|
165
164
|
end
|
@@ -167,46 +166,45 @@ describe BasicCloud do
|
|
167
166
|
describe "#[]=" do
|
168
167
|
it "should write through the Asset object (and thus run any callbacks on the asset)" do
|
169
168
|
special_asset = double(:special_asset)
|
170
|
-
special_asset.
|
171
|
-
special_asset.
|
172
|
-
SpecialAsset.
|
169
|
+
expect(special_asset).to(receive(:value=).with('fancy fancy!'))
|
170
|
+
expect(special_asset).to(receive(:store))
|
171
|
+
expect(SpecialAsset).to(receive(:at).and_return(special_asset))
|
173
172
|
@fs['special/fancy.txt'] = 'fancy fancy!'
|
174
173
|
end
|
175
174
|
end
|
176
175
|
|
177
176
|
describe "#bucket" do
|
178
177
|
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'].
|
178
|
+
expect(@fs['assets/rails_logo.gif']).to(be_instance_of(AssetCloud::Asset))
|
179
|
+
expect(@fs['special/fancy.txt']).to(be_instance_of(SpecialAsset))
|
181
180
|
|
182
|
-
@fs.build('assets/foo').
|
183
|
-
@fs.build('special/foo').
|
181
|
+
expect(@fs.build('assets/foo')).to(be_instance_of(AssetCloud::Asset))
|
182
|
+
expect(@fs.build('special/foo')).to(be_instance_of(SpecialAsset))
|
184
183
|
end
|
185
184
|
|
186
185
|
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').
|
186
|
+
expect(@fs.build('conditional/default.js')).to(be_instance_of(AssetCloud::Asset))
|
187
|
+
expect(@fs.build('conditional/better.liquid')).to(be_instance_of(LiquidAsset))
|
189
188
|
end
|
190
189
|
|
191
190
|
it "should raise " do
|
192
|
-
expect { BasicCloud.bucket(AssetCloud::MemoryBucket, asset_class:
|
191
|
+
expect { BasicCloud.bucket(AssetCloud::MemoryBucket, asset_class: proc {}) }.to(raise_error(ArgumentError))
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
196
195
|
describe "MATCH_BUCKET" do
|
197
196
|
it "should match following stuff " do
|
198
|
-
|
199
197
|
'products/key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
200
|
-
|
198
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
201
199
|
|
202
200
|
'products/subpath/key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
203
|
-
|
201
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
204
202
|
|
205
203
|
'key.txt' =~ AssetCloud::Base::MATCH_BUCKET
|
206
|
-
|
204
|
+
expect(Regexp.last_match(1)).to(eq(nil))
|
207
205
|
|
208
206
|
'products' =~ AssetCloud::Base::MATCH_BUCKET
|
209
|
-
|
207
|
+
expect(Regexp.last_match(1)).to(eq('products'))
|
210
208
|
end
|
211
209
|
end
|
212
210
|
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
|