carrierwave-aws 0.6.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cfb613038a1d6671516ddc5f04d4c6a78024a7d
4
- data.tar.gz: 85ed3134b7b2ffb7b2e5b6fab8a825a26b0258c9
3
+ metadata.gz: c1e20392785ccfd2e605fc9767c0dc197ad37a68
4
+ data.tar.gz: 50b782478484e7943ebd65a92a0e5d85941b1160
5
5
  SHA512:
6
- metadata.gz: 58cf39368f66fafde4dfcde883d2a19314012a4b3604ca3160caf067dbb42905a727eb8d985c4d9e3f85251c1cd6961caa9aadd4d06c60431a314b5b710d50c8
7
- data.tar.gz: 7efb7a4b9c857749c55b420946bfa8eafc2d7bd4ee9217046ee610ada3e098f6447c5820b79f68c6ee5a52377a41b4f8cf2d453a605b3655d1db3be57f948757
6
+ metadata.gz: ead96dc851927e50fac612af14175c5c2d24a05ec05a345fea5e67cb0656f040595f8548d45705f300a7305a887702ebb68fc3f4df9a9d2cbe2d7c35fd5265db
7
+ data.tar.gz: cca3f59e0331a5dcbfdc72323105eaa30b798142853eb7ef42798e57dd55e2d143551c96a616d2ae41f89f7c0971fcf5c0f3c2a8106b75b8aa61b640d2c67597
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
+ ---
1
2
  language: ruby
2
3
  rvm:
3
4
  - 2.1.5
@@ -17,4 +18,3 @@ env:
17
18
  B75vnSCFTnQgCP4dmz78VN/WWj88Tpnh4cjUCU0cQjQ5M7oQ0KTbM0d7WDyf
18
19
  rf0F+B9OihBtLNQWqjocRvNH0dU5OzBLCC9DVolUgNwOdNTHW2I7CwlxJ5t7
19
20
  ljQTxzPP+tFASwzBHjywbo7n0EX3efT5UOZhbD9LZL93X4SOlyU=
20
- - secure: Uv276ljIrpfYNE34zKnawA6rxchmMymTzMs3LRcmsCDawDhNmtEuoqeHLiZctFU0k40YDylwcDXDWJayVDSW97+ytMqFfQ6e7HkL06iNZPcAW8V0LJt4SrVzRGIm6ER9Xib57lXhOnfS0jcVxT/UuD0pegvYdZb0VhUedmqInP0=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Version 0.7.0 2015-07-02
2
+
3
+ * Revert to AWS-SDK v1. There are too many breaking changes between v1 and v2 to
4
+ be wrapped in a minor version change. This effectively reverts all changes
5
+ betwen `0.5.0` and `0.6.0`, restoring the old `0.5.0` behavior.
6
+
1
7
  ## Version 0.6.0 2015-06-26
2
8
 
3
9
  * Breaking Change: Updated to use AWS-SDK v2 [Mark Oleson]
data/README.md CHANGED
@@ -38,20 +38,33 @@ the use of `aws_bucket` instead of `fog_directory`, and `aws_acl` instead of
38
38
  CarrierWave.configure do |config|
39
39
  config.storage = :aws
40
40
  config.aws_bucket = ENV.fetch('S3_BUCKET_NAME')
41
- config.aws_acl = 'public-read'
41
+ config.aws_acl = :public_read
42
42
  config.asset_host = 'http://example.com'
43
-
44
- # The maximum period for authenticated_urls is only 7 days.
45
- config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
43
+ config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365
46
44
 
47
45
  config.aws_credentials = {
48
46
  access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
49
- secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
50
- region: ENV.fetch('AWS_REGION') # Required
47
+ secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY')
51
48
  }
52
49
  end
53
50
  ```
54
51
 
52
+ If you want to supply your own AWS configuration, put it inside
53
+ `config.aws_credentials` like this:
54
+
55
+ ```ruby
56
+ config.aws_credentials = {
57
+ access_key_id: ENV['AWS_ACCESS_KEY_ID'],
58
+ secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
59
+ config: AWS.config(my_aws_options)
60
+ }
61
+ ```
62
+
63
+ `AWS.config` will return `AWS::Core::Configuration` object which is used through
64
+ `aws-sdk` gem. Browse [Amazon Docs][amazon-docs] for additional info. For
65
+ example, if you want to turn off SSL for your asset URLs, you could simply set
66
+ `AWS.config(use_ssl: false)`.
67
+
55
68
  ### Custom options for AWS URLs
56
69
 
57
70
  If you have a custom uploader that specifies additional headers for each URL, please try the following example:
@@ -89,3 +102,5 @@ cp .env.sample .env
89
102
  3. Commit your changes (`git commit -am 'Add some feature'`)
90
103
  4. Push to the branch (`git push origin my-new-feature`)
91
104
  5. Create new Pull Request
105
+
106
+ [amazon-docs]: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ['lib']
18
18
 
19
19
  gem.add_dependency 'carrierwave', '~> 0.7'
20
- gem.add_dependency 'aws-sdk', '~> 2.0.47'
20
+ gem.add_dependency 'aws-sdk', '~> 1.58'
21
21
 
22
22
  gem.add_development_dependency 'rspec', '~> 3'
23
23
  end
@@ -2,8 +2,6 @@ require 'carrierwave'
2
2
  require 'carrierwave/aws/version'
3
3
  require 'carrierwave/storage/aws'
4
4
  require 'carrierwave/storage/aws_file'
5
- require 'carrierwave/storage/aws_options'
6
- require 'carrierwave/support/uri_filename'
7
5
 
8
6
  class CarrierWave::Uploader::Base
9
7
  add_config :aws_attributes
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module AWS
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require 'aws-sdk-resources'
1
+ require 'aws/s3'
2
2
 
3
3
  module CarrierWave
4
4
  module Storage
@@ -23,7 +23,7 @@ module CarrierWave
23
23
 
24
24
  def connection
25
25
  @connection ||= begin
26
- self.class.connection_cache[credentials] ||= ::Aws::S3::Resource.new(*credentials)
26
+ self.class.connection_cache[credentials] ||= ::AWS::S3.new(*credentials)
27
27
  end
28
28
  end
29
29
 
@@ -1,51 +1,43 @@
1
1
  module CarrierWave
2
2
  module Storage
3
3
  class AWSFile
4
- attr_writer :file
5
- attr_accessor :uploader, :connection, :path, :aws_options
4
+ attr_writer :content_type
5
+ attr_reader :uploader, :connection, :path
6
6
 
7
7
  def initialize(uploader, connection, path)
8
- @uploader = uploader
9
- @connection = connection
10
- @path = path
11
- @aws_options = AWSOptions.new(uploader)
8
+ @uploader = uploader
9
+ @connection = connection
10
+ @path = path
12
11
  end
13
12
 
14
- def file
15
- @file ||= bucket.object(path)
16
- end
17
-
18
- alias_method :to_file, :file
19
-
20
13
  def attributes
21
- file.data.to_h
14
+ file.head.data
22
15
  end
23
16
 
24
17
  def content_type
25
- file.content_type
18
+ @content_type || file.content_type
26
19
  end
27
20
 
28
21
  def delete
29
22
  file.delete
30
23
  end
31
24
 
32
- def exists?
33
- file.exists?
25
+ def extension
26
+ path.split('.').last
34
27
  end
35
28
 
36
- def extension
37
- elements = path.split('.')
38
- elements.last if elements.size > 1
29
+ def exists?
30
+ file.exists?
39
31
  end
40
32
 
41
33
  def filename(options = {})
42
34
  if file_url = url(options)
43
- CarrierWave::Support::UriFilename.filename(file_url)
35
+ URI.decode(file_url.split('?').first).gsub(/.*\/(.*?$)/, '\1')
44
36
  end
45
37
  end
46
38
 
47
39
  def read
48
- file.get(aws_options.read_options).body.read
40
+ file.read(uploader_read_options)
49
41
  end
50
42
 
51
43
  def size
@@ -53,15 +45,25 @@ module CarrierWave
53
45
  end
54
46
 
55
47
  def store(new_file)
56
- !!file.put(aws_options.write_options(new_file))
48
+ @file = bucket.objects[path].write(uploader_write_options(new_file))
49
+
50
+ true
57
51
  end
58
52
 
59
- def copy_to(new_path)
60
- bucket.object(new_path).copy_from(copy_source: "#{bucket.name}/#{file.key}")
53
+ def to_file
54
+ file
55
+ end
56
+
57
+ def url(options = {})
58
+ if uploader.aws_acl != :public_read
59
+ authenticated_url(options)
60
+ else
61
+ public_url
62
+ end
61
63
  end
62
64
 
63
65
  def authenticated_url(options = {})
64
- file.presigned_url(:get, aws_options.expiration_options(options))
66
+ file.url_for(:read, { expires: uploader.aws_authenticated_url_expiration }.merge(options)).to_s
65
67
  end
66
68
 
67
69
  def public_url
@@ -72,18 +74,42 @@ module CarrierWave
72
74
  end
73
75
  end
74
76
 
75
- def url(options = {})
76
- if uploader.aws_acl.to_s != 'public-read'
77
- authenticated_url(options)
78
- else
79
- public_url
77
+ def copy_to(new_path)
78
+ file.copy_to(bucket.objects[new_path], uploader_copy_options)
79
+ end
80
+
81
+ def uploader_read_options
82
+ uploader.aws_read_options || {}
83
+ end
84
+
85
+ def uploader_write_options(new_file)
86
+ aws_attributes = uploader.aws_attributes || {}
87
+ aws_write_options = uploader.aws_write_options || {}
88
+
89
+ { acl: uploader.aws_acl,
90
+ content_type: new_file.content_type,
91
+ file: new_file.path
92
+ }.merge(aws_attributes).merge(aws_write_options)
93
+ end
94
+
95
+ def uploader_copy_options
96
+ aws_write_options = uploader.aws_write_options || {}
97
+
98
+ storage_options = aws_write_options.select do |key,_|
99
+ [:reduced_redundancy, :storage_class, :server_side_encryption].include?(key)
80
100
  end
101
+
102
+ { acl: uploader.aws_acl }.merge(storage_options)
81
103
  end
82
104
 
83
105
  private
84
106
 
85
107
  def bucket
86
- @bucket ||= connection.bucket(uploader.aws_bucket)
108
+ @bucket ||= connection.buckets[uploader.aws_bucket]
109
+ end
110
+
111
+ def file
112
+ @file ||= bucket.objects[path]
87
113
  end
88
114
  end
89
115
  end
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CarrierWave::Storage::AWSFile do
4
+ let(:objects) { { 'files/1/file.txt' => file } }
4
5
  let(:path) { 'files/1/file.txt' }
5
- let(:file) { double(:file, content_type: 'content/type', path: '/file/path') }
6
- let(:bucket) { double(:bucket, object: file) }
7
- let(:connection) { double(:connection, bucket: bucket) }
6
+ let(:bucket) { double(:bucket, objects: objects) }
7
+ let(:connection) { double(:connection, buckets: { 'example-com' => bucket }) }
8
+ let(:file) { double(:file, read: '0101010', content_type: 'content/type', path: '/file/path') }
8
9
 
9
10
  let(:uploader) do
10
11
  double(:uploader,
11
12
  aws_bucket: 'example-com',
12
- aws_acl: :'public-read',
13
+ aws_acl: :public_read,
13
14
  aws_attributes: {},
14
15
  asset_host: nil,
15
16
  aws_read_options: { encryption_key: 'abc' },
@@ -21,32 +22,86 @@ describe CarrierWave::Storage::AWSFile do
21
22
  CarrierWave::Storage::AWSFile.new(uploader, connection, path)
22
23
  end
23
24
 
25
+ describe '#exists?' do
26
+ it 'checks if the remote file object exists' do
27
+ expect(file).to receive(:exists?).and_return(true)
28
+
29
+ aws_file.exists?
30
+ end
31
+ end
32
+
33
+ describe '#read' do
34
+ it 'reads from the remote file object' do
35
+ expect(aws_file.read).to eq('0101010')
36
+ end
37
+ end
38
+
39
+ describe '#uploader_write_options' do
40
+ it 'includes acl, content_type, file, aws_attributes, and aws_write_options' do
41
+ expect(aws_file.uploader_write_options(file)).to eq(
42
+ acl: :public_read,
43
+ content_type: 'content/type',
44
+ file: '/file/path',
45
+ encryption_key: 'def'
46
+ )
47
+ end
48
+
49
+ it 'works if aws_attributes is nil' do
50
+ allow(uploader).to receive(:aws_attributes) { nil }
51
+
52
+ expect {
53
+ aws_file.uploader_write_options(file)
54
+ }.to_not raise_error
55
+ end
56
+
57
+ it 'works if aws_write_options is nil' do
58
+ allow(uploader).to receive(:aws_write_options) { nil }
59
+
60
+ expect {
61
+ aws_file.uploader_write_options(file)
62
+ }.to_not raise_error
63
+ end
64
+ end
65
+
66
+ describe '#uploader_read_options' do
67
+ it 'includes aws_read_options' do
68
+ expect(aws_file.uploader_read_options).to eq(encryption_key: 'abc')
69
+ end
70
+
71
+ it 'ensures that read options are a hash' do
72
+ allow(uploader).to receive(:aws_read_options) { nil }
73
+
74
+ expect(aws_file.uploader_read_options).to eq({})
75
+ end
76
+ end
77
+
24
78
  describe '#to_file' do
25
79
  it 'returns the internal file instance' do
26
- file = Object.new
27
- aws_file.file = file
28
-
29
80
  expect(aws_file.to_file).to be(file)
30
81
  end
31
82
  end
32
83
 
33
- describe '#extension' do
34
- it 'extracts the file extension from the path' do
35
- aws_file.path = 'file.txt'
84
+ describe '#authenticated_url' do
85
+ it 'requests a url for reading with the configured expiration' do
86
+ allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
36
87
 
37
- expect(aws_file.extension).to eq('txt')
88
+ expect(file).to receive(:url_for).with(:read, expires: 60)
89
+
90
+ aws_file.authenticated_url
38
91
  end
39
92
 
40
- it 'is nil if the file has no extension' do
41
- aws_file.path = 'filetxt'
93
+ it 'requests a url for reading with custom options' do
94
+ allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
95
+
96
+ expect(file).to receive(:url_for).with(:read, hash_including(response_content_disposition: 'attachment'))
42
97
 
43
- expect(aws_file.extension).to be_nil
98
+ aws_file.authenticated_url(response_content_disposition: 'attachment')
44
99
  end
45
100
  end
46
101
 
47
102
  describe '#url' do
48
103
  it 'requests a public url if acl is public readable' do
49
- allow(uploader).to receive(:aws_acl) { :'public-read' }
104
+ allow(uploader).to receive(:aws_acl) { :public_read }
50
105
 
51
106
  expect(file).to receive(:public_url)
52
107
 
@@ -57,16 +112,24 @@ describe CarrierWave::Storage::AWSFile do
57
112
  allow(uploader).to receive(:aws_acl) { :private }
58
113
  allow(uploader).to receive(:aws_authenticated_url_expiration) { 60 }
59
114
 
60
- expect(file).to receive(:presigned_url).with(:get, { expires_in: 60 })
115
+ expect(file).to receive(:url_for)
61
116
 
62
117
  aws_file.url
63
118
  end
64
119
 
65
120
  it 'uses the asset_host and file path if asset_host is set' do
66
- allow(uploader).to receive(:aws_acl) { :'public-read' }
121
+ allow(uploader).to receive(:aws_acl) { :public_read }
67
122
  allow(uploader).to receive(:asset_host) { 'http://example.com' }
68
123
 
69
124
  expect(aws_file.url).to eq('http://example.com/files/1/file.txt')
70
125
  end
71
126
  end
127
+
128
+ describe '#filename' do
129
+ it 'returns the filename from the url' do
130
+ expect(aws_file).to receive(:url).and_return('http://example.com/files/1/file%201.txt?foo=bar/baz.txt')
131
+
132
+ expect(aws_file.filename).to eq('file 1.txt')
133
+ end
134
+ end
72
135
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CarrierWave::Storage::AWS do
4
- let(:credentials) { { access_key_id: 'abc', secret_access_key: '123', region: 'us-east-1' } }
4
+ let(:credentials) { { access_key_id: 'abc', secret_access_key: '123' } }
5
5
  let(:uploader) { double(:uploader, aws_credentials: credentials) }
6
6
 
7
7
  subject(:storage) do
@@ -14,11 +14,17 @@ describe CarrierWave::Storage::AWS do
14
14
 
15
15
  describe '#connection' do
16
16
  it 'instantiates a new connection with credentials' do
17
- expect(Aws::S3::Resource).to receive(:new).with(credentials)
17
+ expect(AWS::S3).to receive(:new).with(credentials)
18
18
 
19
19
  storage.connection
20
20
  end
21
21
 
22
+ it 'instantiates a new connection without any credentials' do
23
+ allow(uploader).to receive(:aws_credentials) { nil }
24
+
25
+ expect { storage.connection }.not_to raise_exception
26
+ end
27
+
22
28
  it 'caches connections by credentials' do
23
29
  expect(storage.connection).to eq(storage.connection)
24
30
  end
@@ -1,16 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Copying Files', type: :feature do
4
- let(:image) { File.open('spec/fixtures/image.png', 'r') }
5
- let(:original) { FeatureUploader.new }
6
-
7
4
  it 'copies an existing file to the specified path' do
5
+ uploader = Class.new(CarrierWave::Uploader::Base) do
6
+ def filename; 'image.png'; end
7
+ end
8
+
9
+ image = File.open('spec/fixtures/image.png', 'r')
10
+ original = uploader.new
11
+
8
12
  original.store!(image)
9
13
  original.retrieve_from_store!('image.png')
10
14
 
11
15
  original.file.copy_to('uploads/image2.png')
12
16
 
13
- copy = FeatureUploader.new
17
+ copy = uploader.new
14
18
  copy.retrieve_from_store!('image2.png')
15
19
 
16
20
  original_attributes = original.file.attributes
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Querying Files', type: :feature do
4
+ it 'retrieves the attributes for a stored file' do
5
+ uploader = Class.new(CarrierWave::Uploader::Base) do
6
+ def filename; 'image.png'; end
7
+ end
8
+
9
+ image = File.open('spec/fixtures/image.png', 'r')
10
+ instance = uploader.new
11
+
12
+ instance.store!(image)
13
+ instance.retrieve_from_store!('image.png')
14
+
15
+ expect(instance.file.attributes).to include(
16
+ :meta,
17
+ :restore_in_progress,
18
+ :content_type,
19
+ :etag,
20
+ :accept_ranges,
21
+ :last_modified,
22
+ :content_length
23
+ )
24
+
25
+ image.close
26
+ instance.file.delete
27
+ end
28
+
29
+ it 'checks if a remote file exists' do
30
+ uploader = Class.new(CarrierWave::Uploader::Base) do
31
+ def filename; 'image.png'; end
32
+ end
33
+
34
+ image = File.open('spec/fixtures/image.png', 'r')
35
+ instance = uploader.new
36
+
37
+ instance.store!(image)
38
+ instance.retrieve_from_store!('image.png')
39
+
40
+ expect(instance.file.exists?).to be true
41
+
42
+ instance.file.delete
43
+
44
+ expect(instance.file.exists?).to be false
45
+
46
+ image.close
47
+ end
48
+ end
@@ -1,59 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Storing Files', type: :feature do
4
- let(:image) { File.open('spec/fixtures/image.png', 'r') }
5
- let(:instance) { FeatureUploader.new }
6
-
7
4
  it 'uploads the file to the configured bucket' do
8
- instance.store!(image)
9
- instance.retrieve_from_store!('image.png')
10
-
11
- expect(instance.file.size).to eq(image.size)
12
- expect(instance.file.read).to eq(image.read)
13
- expect(instance.file.read).to eq(instance.file.read)
14
-
15
- image.close
16
- instance.file.delete
17
- end
18
-
19
- it 'retrieves the attributes for a stored file' do
20
- instance.store!(image)
21
- instance.retrieve_from_store!('image.png')
22
-
23
- expect(instance.file.attributes).to include(
24
- :metadata,
25
- :content_type,
26
- :etag,
27
- :accept_ranges,
28
- :last_modified,
29
- :content_length
30
- )
31
-
32
- expect(instance.file.content_type).to eq('image/png')
33
- expect(instance.file.filename).to eq('image.png')
5
+ uploader = Class.new(CarrierWave::Uploader::Base) do
6
+ def filename; 'image.png'; end
7
+ end
34
8
 
35
- image.close
36
- instance.file.delete
37
- end
38
-
39
- it 'checks if a remote file exists' do
40
- instance.store!(image)
41
- instance.retrieve_from_store!('image.png')
42
-
43
- expect(instance.file.exists?).to be_truthy
44
-
45
- instance.file.delete
46
-
47
- expect(instance.file.exists?).to be_falsy
48
-
49
- image.close
50
- end
9
+ image = File.open('spec/fixtures/image.png', 'r')
10
+ instance = uploader.new
51
11
 
52
- it 'gets a url for remote files' do
53
12
  instance.store!(image)
54
13
  instance.retrieve_from_store!('image.png')
55
14
 
56
- expect(instance.url).to eq("https://#{ENV['S3_BUCKET_NAME']}.s3.amazonaws.com/#{instance.path}")
15
+ expect(instance.file.size).to be_nonzero
16
+ expect(image.size).to eq(instance.file.size)
57
17
 
58
18
  image.close
59
19
  instance.file.delete
data/spec/spec_helper.rb CHANGED
@@ -10,10 +10,6 @@ def source_environment_file!
10
10
  end
11
11
  end
12
12
 
13
- FeatureUploader = Class.new(CarrierWave::Uploader::Base) do
14
- def filename; 'image.png'; end
15
- end
16
-
17
13
  RSpec.configure do |config|
18
14
  source_environment_file!
19
15
 
@@ -36,12 +32,12 @@ RSpec.configure do |config|
36
32
  CarrierWave.configure do |config|
37
33
  config.storage = :aws
38
34
  config.aws_bucket = ENV['S3_BUCKET_NAME']
39
- config.aws_acl = :'public-read'
35
+ config.aws_acl = :public_read
40
36
 
41
37
  config.aws_credentials = {
42
38
  access_key_id: ENV['S3_ACCESS_KEY'],
43
39
  secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
44
- region: ENV['AWS_REGION']
40
+ region: ENV['S3_REGION']
45
41
  }
46
42
  end
47
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Selbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.47
33
+ version: '1.58'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.47
40
+ version: '1.58'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,11 @@ files:
73
73
  - lib/carrierwave/aws/version.rb
74
74
  - lib/carrierwave/storage/aws.rb
75
75
  - lib/carrierwave/storage/aws_file.rb
76
- - lib/carrierwave/storage/aws_options.rb
77
- - lib/carrierwave/support/uri_filename.rb
78
76
  - spec/carrierwave-aws_spec.rb
79
77
  - spec/carrierwave/storage/aws_file_spec.rb
80
- - spec/carrierwave/storage/aws_options_spec.rb
81
78
  - spec/carrierwave/storage/aws_spec.rb
82
- - spec/carrierwave/support/uri_filename_spec.rb
83
79
  - spec/features/copying_files_spec.rb
80
+ - spec/features/querying_files_spec.rb
84
81
  - spec/features/storing_files_spec.rb
85
82
  - spec/fixtures/image.png
86
83
  - spec/spec_helper.rb
@@ -110,10 +107,9 @@ summary: A slimmer alternative to using Fog for S3 support in CarrierWave
110
107
  test_files:
111
108
  - spec/carrierwave-aws_spec.rb
112
109
  - spec/carrierwave/storage/aws_file_spec.rb
113
- - spec/carrierwave/storage/aws_options_spec.rb
114
110
  - spec/carrierwave/storage/aws_spec.rb
115
- - spec/carrierwave/support/uri_filename_spec.rb
116
111
  - spec/features/copying_files_spec.rb
112
+ - spec/features/querying_files_spec.rb
117
113
  - spec/features/storing_files_spec.rb
118
114
  - spec/fixtures/image.png
119
115
  - spec/spec_helper.rb
@@ -1,42 +0,0 @@
1
- module CarrierWave
2
- module Storage
3
- class AWSOptions
4
- attr_reader :uploader
5
-
6
- def initialize(uploader)
7
- @uploader = uploader
8
- end
9
-
10
- def read_options
11
- aws_read_options
12
- end
13
-
14
- def write_options(new_file)
15
- { acl: uploader.aws_acl,
16
- body: new_file.to_file,
17
- content_type: new_file.content_type,
18
- }.merge(aws_attributes).merge(aws_write_options)
19
- end
20
-
21
- def expiration_options(options = {})
22
- uploader_expiration = uploader.aws_authenticated_url_expiration
23
-
24
- { expires_in: uploader_expiration }.merge(options)
25
- end
26
-
27
- private
28
-
29
- def aws_attributes
30
- uploader.aws_attributes || {}
31
- end
32
-
33
- def aws_read_options
34
- uploader.aws_read_options || {}
35
- end
36
-
37
- def aws_write_options
38
- uploader.aws_write_options || {}
39
- end
40
- end
41
- end
42
- end
@@ -1,11 +0,0 @@
1
- module CarrierWave
2
- module Support
3
- module UriFilename
4
- def self.filename(url)
5
- path = url.split('?').first
6
-
7
- URI.decode(path).gsub(/.*\/(.*?$)/, '\1')
8
- end
9
- end
10
- end
11
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CarrierWave::Storage::AWSOptions do
4
- uploader_klass = Class.new do
5
- attr_accessor :aws_attributes, :aws_read_options, :aws_write_options
6
-
7
- def aws_acl
8
- 'public-read'
9
- end
10
-
11
- def aws_authenticated_url_expiration
12
- '60'
13
- end
14
- end
15
-
16
- let(:uploader) { uploader_klass.new }
17
- let(:options) { CarrierWave::Storage::AWSOptions.new(uploader) }
18
-
19
- describe '#read_options' do
20
- it 'uses the uploader aws_read_options' do
21
- uploader.aws_read_options = { encryption_key: 'abc' }
22
-
23
- expect(options.read_options).to eq(uploader.aws_read_options)
24
- end
25
-
26
- it 'ensures that read_options are a hash' do
27
- uploader.aws_read_options = nil
28
-
29
- expect(options.read_options).to eq({})
30
- end
31
- end
32
-
33
- describe '#write_options' do
34
- let(:file) { CarrierWave::SanitizedFile.new('spec/fixtures/image.png') }
35
-
36
- it 'includes acl, content_type, body (file), aws_attributes, and aws_write_options' do
37
- uploader.aws_write_options = { encryption_key: 'def' }
38
-
39
- write_options = options.write_options(file)
40
-
41
- expect(write_options).to include(
42
- acl: 'public-read',
43
- content_type: 'image/png',
44
- encryption_key: 'def'
45
- )
46
- expect(write_options[:body].path).to eq(file.path)
47
- end
48
-
49
- it 'works if aws_attributes is nil' do
50
- expect(uploader).to receive(:aws_attributes) { nil }
51
-
52
- expect {
53
- options.write_options(file)
54
- }.to_not raise_error
55
- end
56
-
57
- it 'works if aws_write_options is nil' do
58
- expect(uploader).to receive(:aws_write_options) { nil }
59
-
60
- expect {
61
- options.write_options(file)
62
- }.to_not raise_error
63
- end
64
- end
65
-
66
- describe '#expiration_options' do
67
- it 'extracts the expiration value' do
68
- expect(options.expiration_options).to eq(
69
- expires_in: uploader.aws_authenticated_url_expiration
70
- )
71
- end
72
-
73
- it 'allows expiration to be overridden' do
74
- expect(options.expiration_options(expires_in: 10)).to eq(
75
- expires_in: 10
76
- )
77
- end
78
- end
79
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CarrierWave::Support::UriFilename do
4
- UriFilename = CarrierWave::Support::UriFilename
5
-
6
- describe '.filename' do
7
- it 'extracts a decoded filename from file uri' do
8
- samples = {
9
- 'http://example.com/file.txt' => 'file.txt',
10
- 'http://example.com/files/1/file%201.txt?foo=bar/baz.txt' => 'file 1.txt',
11
- }
12
-
13
- samples.each do |uri, name|
14
- expect(UriFilename.filename(uri)).to eq(name)
15
- end
16
- end
17
- end
18
- end