asset_cloud 2.5.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  class MemoryCloud < AssetCloud::Base
@@ -8,41 +9,39 @@ describe AssetCloud::MemoryBucket do
8
9
  directory = File.dirname(__FILE__) + '/files'
9
10
 
10
11
  before do
11
- @fs = MemoryCloud.new(directory , 'http://assets/files' )
12
+ @fs = MemoryCloud.new(directory, 'http://assets/files')
12
13
  end
13
14
 
14
15
  describe 'modifying items in subfolder' do
15
-
16
16
  it "should return nil when file does not exist" do
17
- @fs['memory/essay.txt'].exist?.should == false
17
+ expect(@fs['memory/essay.txt'].exist?).to(eq(false))
18
18
  end
19
19
 
20
20
  it "should return set content when asked for the same file" do
21
21
  @fs['memory/essay.txt'] = 'text'
22
- @fs['memory/essay.txt'].value.should == 'text'
22
+ expect(@fs['memory/essay.txt'].value).to(eq('text'))
23
23
  end
24
-
25
24
  end
26
25
 
27
26
  describe "#versioned?" do
28
27
  it "should return false" do
29
- @fs.buckets[:memory].versioned?.should == false
28
+ expect(@fs.buckets[:memory].versioned?).to(eq(false))
30
29
  end
31
30
  end
32
31
 
33
32
  describe '#ls' do
34
33
  before do
35
34
  %w{a b}.each do |letter|
36
- 2.times {|number| @fs.write("memory/#{letter}#{number}",'.')}
35
+ 2.times { |number| @fs.write("memory/#{letter}#{number}", '.') }
37
36
  end
38
37
  end
39
38
 
40
39
  it "should return a list of assets which start with the given prefix" do
41
- @fs.buckets[:memory].ls('memory/a').size.should == 2
40
+ expect(@fs.buckets[:memory].ls('memory/a').size).to(eq(2))
42
41
  end
43
42
 
44
43
  it "should return a list of all assets when a prefix is not given" do
45
- @fs.buckets[:memory].ls.size.should == 4
44
+ expect(@fs.buckets[:memory].ls.size).to(eq(4))
46
45
  end
47
46
  end
48
47
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'ostruct'
2
3
 
3
4
  class MockS3Interface
@@ -7,7 +8,7 @@ class MockS3Interface
7
8
 
8
9
  attr_reader :bucket_storage
9
10
 
10
- def initialize(aws_access_key_id = nil, aws_secret_access_key = nil, params = {})
11
+ def initialize(_aws_access_key_id = nil, _aws_secret_access_key = nil, _params = {})
11
12
  @buckets = {}
12
13
  end
13
14
 
@@ -32,7 +33,7 @@ class MockS3Interface
32
33
 
33
34
  {
34
35
  content_length: options.body.size,
35
- last_modified: Time.parse("Mon Aug 27 17:37:51 UTC 2007")
36
+ last_modified: Time.parse("Mon Aug 27 17:37:51 UTC 2007"),
36
37
  }
37
38
  end
38
39
 
@@ -60,7 +61,7 @@ class MockS3Interface
60
61
  if options[:acl] && !VALID_ACLS.include?(options[:acl])
61
62
  raise "Invalid ACL `#{options[:acl].inspect}`, must be one of: #{VALID_ACLS.inspect}"
62
63
  end
63
-
64
+
64
65
  options[:body] = options[:body].force_encoding(Encoding::BINARY)
65
66
 
66
67
  key = options.delete(:key)
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  class RemoteS3Cloud < AssetCloud::Base
4
5
  attr_accessor :s3_connection
5
6
  bucket :tmp, AssetCloud::S3Bucket
6
7
 
7
- def s3_bucket(key)
8
+ def s3_bucket(_key)
8
9
  s3_connection.bucket(ENV['S3_BUCKET_NAME'])
9
10
  end
10
11
  end
@@ -21,14 +22,14 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
21
22
  ),
22
23
  }
23
24
 
24
- @cloud = RemoteS3Cloud.new(directory , 'testing/assets/files' )
25
+ @cloud = RemoteS3Cloud.new(directory, 'testing/assets/files')
25
26
  @cloud.s3_connection = Aws::S3::Resource.new
26
27
  @bucket = @cloud.buckets[:tmp]
27
28
  end
28
29
 
29
30
  after(:all) do
30
31
  listing = @bucket.ls('tmp')
31
- listing.each { |object| object.delete }
32
+ listing.each(&:delete)
32
33
  end
33
34
 
34
35
  it "#ls should return assets with proper keys" do
@@ -37,8 +38,8 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
37
38
 
38
39
  ls = @bucket.ls('tmp')
39
40
 
40
- expect(ls).to all(be_an(AssetCloud::Asset))
41
- expect(ls.map(&:key) - ['tmp/test1.txt', 'tmp/test2.txt']).to be_empty
41
+ expect(ls).to(all(be_an(AssetCloud::Asset)))
42
+ expect(ls.map(&:key) - ['tmp/test1.txt', 'tmp/test2.txt']).to(be_empty)
42
43
  end
43
44
 
44
45
  it "#ls returns all assets" do
@@ -47,8 +48,8 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
47
48
 
48
49
  ls = @bucket.ls
49
50
 
50
- expect(ls).to all(be_an(AssetCloud::Asset))
51
- expect(ls.map(&:key) - ['tmp/test1.txt', 'tmp/test2.txt']).to be_empty
51
+ expect(ls).to(all(be_an(AssetCloud::Asset)))
52
+ expect(ls.map(&:key) - ['tmp/test1.txt', 'tmp/test2.txt']).to(be_empty)
52
53
  end
53
54
 
54
55
  it "#delete should ignore errors when deleting" do
@@ -58,7 +59,7 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
58
59
  it "#delete should always return true" do
59
60
  @cloud['tmp/test1.txt'] = 'test1'
60
61
 
61
- @bucket.delete('tmp/test1.txt').should == true
62
+ expect(@bucket.delete('tmp/test1.txt')).to(eq(true))
62
63
  end
63
64
 
64
65
  it "#stat should get metadata from S3" do
@@ -66,14 +67,14 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
66
67
  value = 'hello world'
67
68
  @cloud.build('tmp/new_file.test', value).store
68
69
  metadata = @bucket.stat('tmp/new_file.test')
69
- metadata.size.should == value.size
70
- metadata.updated_at.should >= start_time
70
+ expect(metadata.size).to(eq(value.size))
71
+ expect(metadata.updated_at).to(be >= start_time)
71
72
  end
72
73
 
73
74
  it "#stat a missing asset" do
74
75
  metadata = @bucket.stat('i_do_not_exist_and_never_will.test')
75
- expect(metadata).to be_an(AssetCloud::Metadata)
76
- expect(metadata.exist).to be false
76
+ expect(metadata).to(be_an(AssetCloud::Metadata))
77
+ expect(metadata.exist).to(be(false))
77
78
  end
78
79
 
79
80
  it "#read " do
@@ -81,19 +82,19 @@ describe 'Remote test for AssetCloud::S3Bucket', if: ENV['AWS_ACCESS_KEY_ID'] &&
81
82
  key = 'tmp/new_file.txt'
82
83
  @bucket.write(key, value)
83
84
  data = @bucket.read(key)
84
- data.should == value
85
+ expect(data).to(eq(value))
85
86
  end
86
87
 
87
88
  it "#read a missing asset" do
88
- expect { @bucket.read("i_do_not_exist_and_never_will.test") }.to raise_error(AssetCloud::AssetNotFoundError)
89
+ expect { @bucket.read("i_do_not_exist_and_never_will.test") }.to(raise_error(AssetCloud::AssetNotFoundError))
89
90
  end
90
91
 
91
92
  it "#reads first bytes when passed options" do
92
93
  value = 'hello world'
93
94
  key = 'tmp/new_file.txt'
94
- options = {range: 0...5}
95
+ options = { range: 0...5 }
95
96
  @bucket.write(key, value)
96
97
  data = @bucket.read(key, options)
97
- data.should == 'hello'
98
+ expect(data).to(eq('hello'))
98
99
  end
99
100
  end
@@ -5,7 +5,7 @@ class S3Cloud < AssetCloud::Base
5
5
  bucket :tmp, AssetCloud::S3Bucket
6
6
  attr_accessor :s3_connection, :s3_bucket_name
7
7
 
8
- def s3_bucket(key)
8
+ def s3_bucket(_key)
9
9
  s3_connection.bucket(s3_bucket_name)
10
10
  end
11
11
  end
@@ -14,7 +14,7 @@ describe AssetCloud::S3Bucket do
14
14
  directory = File.dirname(__FILE__) + '/files'
15
15
 
16
16
  before(:all) do
17
- @cloud = S3Cloud.new(directory , 'http://assets/files')
17
+ @cloud = S3Cloud.new(directory, 'http://assets/files')
18
18
  @cloud.s3_connection = MockS3Interface.new('a', 'b')
19
19
  @cloud.s3_bucket_name = 'asset-cloud-test'
20
20
 
@@ -30,32 +30,32 @@ describe AssetCloud::S3Bucket do
30
30
  collection = ["#{@cloud.url}/tmp/blah.gif", "#{@cloud.url}/tmp/add_to_cart.gif"].map do |key|
31
31
  MockS3Interface::S3Object.new(nil, key)
32
32
  end
33
- expect_any_instance_of(MockS3Interface::Bucket).to receive(:objects).and_return(collection)
33
+ expect_any_instance_of(MockS3Interface::Bucket).to(receive(:objects).and_return(collection))
34
34
 
35
35
  ls = @bucket.ls('tmp')
36
36
 
37
- expect(ls).to all(be_an(AssetCloud::Asset))
38
- expect(ls.map(&:key) - ['tmp/blah.gif', 'tmp/add_to_cart.gif']).to be_empty
37
+ expect(ls).to(all(be_an(AssetCloud::Asset)))
38
+ expect(ls.map(&:key) - ['tmp/blah.gif', 'tmp/add_to_cart.gif']).to(be_empty)
39
39
  end
40
40
 
41
41
  it "#delete should not ignore errors when deleting" do
42
- expect_any_instance_of(MockS3Interface::NullS3Object).to receive(:delete).and_raise(StandardError)
42
+ expect_any_instance_of(MockS3Interface::NullS3Object).to(receive(:delete).and_raise(StandardError))
43
43
 
44
- expect { @bucket.delete('assets/fail.gif') }.to raise_error(StandardError)
44
+ expect { @bucket.delete('assets/fail.gif') }.to(raise_error(StandardError))
45
45
  end
46
46
 
47
47
  it "#delete should always return true" do
48
- expect_any_instance_of(MockS3Interface::NullS3Object).to receive(:delete).and_return(nil)
48
+ expect_any_instance_of(MockS3Interface::NullS3Object).to(receive(:delete).and_return(nil))
49
49
 
50
- @bucket.delete('assets/fail.gif').should == true
50
+ expect(@bucket.delete('assets/fail.gif')).to(eq(true))
51
51
  end
52
52
 
53
53
  it "#stat should get metadata from S3" do
54
54
  value = 'hello world'
55
55
  @cloud.build('tmp/new_file.test', value).store
56
56
  metadata = @bucket.stat('tmp/new_file.test')
57
- metadata.size.should == value.size
58
- metadata.updated_at.should == Time.parse("Mon Aug 27 17:37:51 UTC 2007")
57
+ expect(metadata.size).to(eq(value.size))
58
+ expect(metadata.updated_at).to(eq(Time.parse("Mon Aug 27 17:37:51 UTC 2007")))
59
59
  end
60
60
 
61
61
  it "#read " do
@@ -63,6 +63,6 @@ describe AssetCloud::S3Bucket do
63
63
  key = 'tmp/new_file.txt'
64
64
  @bucket.write(key, value)
65
65
  data = @bucket.read(key)
66
- data.should == value
66
+ expect(data).to(eq(value))
67
67
  end
68
68
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'rubygems'
2
3
  require 'rspec'
3
4
  require 'pry-byebug' if RUBY_VERSION >= '2.0.0'
4
5
  require 'active_support/all'
5
- $:<< File.dirname(__FILE__) + "/../lib"
6
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
6
7
  require 'asset_cloud'
7
8
  require 'asset_cloud/buckets/s3_bucket'
8
9
  require 'asset_cloud/buckets/gcs_bucket'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  class ValidatedAsset < AssetCloud::Asset
4
5
  validate :no_cats
5
6
 
6
7
  private
8
+
7
9
  def no_cats
8
10
  add_error('no cats allowed!') if value =~ /cat/i
9
11
  add_warning('bad dog!', 'wet dog smell!') if value =~ /dog/i
@@ -11,7 +13,7 @@ class ValidatedAsset < AssetCloud::Asset
11
13
  end
12
14
 
13
15
  class BasicCloud < AssetCloud::Base
14
- bucket :dog_pound, AssetCloud::MemoryBucket, :asset_class => ValidatedAsset
16
+ bucket :dog_pound, AssetCloud::MemoryBucket, asset_class: ValidatedAsset
15
17
  end
16
18
 
17
19
  describe ValidatedAsset do
@@ -23,41 +25,41 @@ describe ValidatedAsset do
23
25
 
24
26
  describe "#store" do
25
27
  it "should not store the asset unless validations pass" do
26
- @cloud.should_receive(:write).with('dog_pound/fido', 'dog').and_return(true)
28
+ expect(@cloud).to(receive(:write).with('dog_pound/fido', 'dog').and_return(true))
27
29
 
28
30
  @cat.store
29
- @cat.store.should == false
30
- @cat.errors.should == ['no cats allowed!']
31
- @dog.store.should == true
31
+ expect(@cat.store).to(eq(false))
32
+ expect(@cat.errors).to(eq(['no cats allowed!']))
33
+ expect(@dog.store).to(eq(true))
32
34
  end
33
35
 
34
36
  it "should store asset with warnings and save them in the warnings array" do
35
- @dog.store.should == true
36
- @dog.warnings.should == ['bad dog!', 'wet dog smell!']
37
- @cat.store.should == false
38
- @cat.warnings.should == []
37
+ expect(@dog.store).to(eq(true))
38
+ expect(@dog.warnings).to(eq(['bad dog!', 'wet dog smell!']))
39
+ expect(@cat.store).to(eq(false))
40
+ expect(@cat.warnings).to(eq([]))
39
41
  end
40
42
  end
41
43
 
42
44
  describe "#store!" do
43
45
  it "should raise AssetNotFound with error message when validation fails" do
44
- expect { @cat.store! }.to raise_error(AssetCloud::AssetNotSaved, "Validation failed: no cats allowed!")
46
+ expect { @cat.store! }.to(raise_error(AssetCloud::AssetNotSaved, "Validation failed: no cats allowed!"))
45
47
  end
46
48
 
47
49
  it "should return true when validations pass" do
48
- @dog.store!.should == true
50
+ expect(@dog.store!).to(eq(true))
49
51
  end
50
52
  end
51
53
 
52
54
  describe "#valid?" do
53
55
  it "should clear errors, run validations, and return validity" do
54
56
  @cat.store
55
- @cat.errors.should == ['no cats allowed!']
56
- @cat.valid?.should == false
57
- @cat.errors.should == ['no cats allowed!']
57
+ expect(@cat.errors).to(eq(['no cats allowed!']))
58
+ expect(@cat.valid?).to(eq(false))
59
+ expect(@cat.errors).to(eq(['no cats allowed!']))
58
60
  @cat.value = 'disguised feline'
59
- @cat.valid?.should == true
60
- @cat.errors.should be_empty
61
+ expect(@cat.valid?).to(eq(true))
62
+ expect(@cat.errors).to(be_empty)
61
63
  end
62
64
  end
63
65
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  class VersionedMemoryCloud < AssetCloud::Base
@@ -8,7 +9,7 @@ describe AssetCloud::VersionedMemoryBucket do
8
9
  directory = File.dirname(__FILE__) + '/files'
9
10
 
10
11
  before do
11
- @fs = VersionedMemoryCloud.new(directory , 'http://assets/files' )
12
+ @fs = VersionedMemoryCloud.new(directory, 'http://assets/files')
12
13
  %w{one two three}.each do |content|
13
14
  @fs.write("memory/foo", content)
14
15
  end
@@ -16,21 +17,20 @@ describe AssetCloud::VersionedMemoryBucket do
16
17
 
17
18
  describe '#versioned?' do
18
19
  it "should return true" do
19
- @fs.buckets[:memory].versioned?.should == true
20
+ expect(@fs.buckets[:memory].versioned?).to(eq(true))
20
21
  end
21
22
  end
22
23
 
23
24
  describe '#read_version' do
24
25
  it "should return the appropriate data when given a key and version" do
25
- @fs.read_version('memory/foo', 1).should == 'one'
26
- @fs.read_version('memory/foo', 3).should == 'three'
26
+ expect(@fs.read_version('memory/foo', 1)).to(eq('one'))
27
+ expect(@fs.read_version('memory/foo', 3)).to(eq('three'))
27
28
  end
28
29
  end
29
30
 
30
31
  describe '#versions' do
31
32
  it "should return a list of available version identifiers for the given key" do
32
- @fs.versions('memory/foo').should == [1,2,3]
33
+ expect(@fs.versions('memory/foo')).to(eq([1, 2, 3]))
33
34
  end
34
35
  end
35
-
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-01 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mocha
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: pry-byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry-byebug
84
+ name: rubocop-shopify
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -102,6 +102,8 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - ".github/probots.yml"
104
104
  - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".rubocop_todo.yml"
105
107
  - ".travis.yml"
106
108
  - Gemfile
107
109
  - History.md
@@ -130,6 +132,7 @@ files:
130
132
  - lib/asset_cloud/validations.rb
131
133
  - shipit.rubygems.yml
132
134
  - spec/active_record_bucket_spec.rb
135
+ - spec/asset_cloud/metadata_spec.rb
133
136
  - spec/asset_extension_spec.rb
134
137
  - spec/asset_spec.rb
135
138
  - spec/base_spec.rb
@@ -175,6 +178,7 @@ specification_version: 4
175
178
  summary: An abstraction layer around arbitrary and diverse asset stores.
176
179
  test_files:
177
180
  - spec/active_record_bucket_spec.rb
181
+ - spec/asset_cloud/metadata_spec.rb
178
182
  - spec/asset_extension_spec.rb
179
183
  - spec/asset_spec.rb
180
184
  - spec/base_spec.rb