carrierwave-aws 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ae750711da052d59eef528b9ae939763fcaf09d
4
- data.tar.gz: cd0697fdf6214142081cb3e019880437742ed056
3
+ metadata.gz: bf33ae82322f4fdbd580886f60268ea23a2a9ce5
4
+ data.tar.gz: b68f5c6a83e0415855eaae454838a7ff540c95e6
5
5
  SHA512:
6
- metadata.gz: de81a897ac5e7a64053dfdcce11053feeddad8026ff06ee6ecec5236fc7df17830aa6b27820193b7d5d217bf454ef87c4155ff7392014bd57a20925060b2bbd4
7
- data.tar.gz: 2ccc6e881ce7cc47050005c9f84ccd5197d29aca4c036565be5c8f3f85cd30b2a2eb3c3030475125962bd639476339460b8c0c61ace9cfafa79b44f9cf949f72
6
+ metadata.gz: 4b3dff18c3ca97ae2474dabbafd68da584fdf26b12bdbc285fc002d835b6abb39f170a7f42078334e869f5eb8f7d17ccb710bb24c047a5069f5664ebc56d6fbe
7
+ data.tar.gz: cd089a2aae0ed73a80db7dc9d1b164145e9460b10020a0f348ce6b60f12a59a9148c745f8b3bf4e702e56b97788ce7942281f4feaa5c521ac0263d46f7cfac2c
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Carrierwave
4
4
  module AWS
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -25,6 +25,24 @@ module CarrierWave
25
25
  AWSFile.new(uploader, connection, uploader.store_path(identifier))
26
26
  end
27
27
 
28
+ def cache!(file)
29
+ AWSFile.new(uploader, connection, uploader.cache_path).tap do |aws_file|
30
+ aws_file.store(file)
31
+ end
32
+ end
33
+
34
+ def retrieve_from_cache!(identifier)
35
+ AWSFile.new(uploader, connection, uploader.cache_path(identifier))
36
+ end
37
+
38
+ def delete_dir!(path)
39
+ # NOTE: noop, because there are no directories on S3
40
+ end
41
+
42
+ def clean_cache!(_seconds)
43
+ raise 'use Object Lifecycle Management to clean the cache'
44
+ end
45
+
28
46
  def connection
29
47
  @connection ||= begin
30
48
  conn_cache = self.class.connection_cache
@@ -37,11 +37,21 @@ module CarrierWave
37
37
  end
38
38
 
39
39
  def read
40
- file.get(aws_options.read_options).body.read
40
+ read_options = aws_options.read_options
41
+ if block_given?
42
+ file.get(read_options) { |chunk| yield chunk }
43
+ nil
44
+ else
45
+ file.get(read_options).body.read
46
+ end
41
47
  end
42
48
 
43
49
  def store(new_file)
44
- file.put(aws_options.write_options(new_file))
50
+ if new_file.is_a?(self.class)
51
+ new_file.move_to(path)
52
+ else
53
+ file.put(aws_options.write_options(new_file))
54
+ end
45
55
  end
46
56
 
47
57
  def copy_to(new_path)
@@ -51,8 +61,15 @@ module CarrierWave
51
61
  )
52
62
  end
53
63
 
64
+ def move_to(new_path)
65
+ file.move_to(
66
+ "#{bucket.name}/#{new_path}",
67
+ acl: uploader.aws_acl
68
+ )
69
+ end
70
+
54
71
  def signed_url(options = {})
55
- signer.call(public_url, options)
72
+ signer.call(public_url.dup, options)
56
73
  end
57
74
 
58
75
  def authenticated_url(options = {})
@@ -81,15 +81,15 @@ describe CarrierWave::Uploader::Base do
81
81
  end
82
82
 
83
83
  describe '#aws_signer' do
84
- let(:signer_proc) { -> (_unsigned, _options) {} }
85
- let(:other_signer) { -> (_unsigned, _options) {} }
84
+ let(:signer_proc) { ->(_unsigned, _options) {} }
85
+ let(:other_signer) { ->(_unsigned, _options) {} }
86
86
 
87
87
  it 'allows proper signer object' do
88
88
  expect { uploader.aws_signer = signer_proc }.not_to raise_exception
89
89
  end
90
90
 
91
91
  it 'does not allow signer with unknown api' do
92
- signer_proc = -> (_unsigned) {}
92
+ signer_proc = ->(_unsigned) {}
93
93
 
94
94
  expect { uploader.aws_signer = signer_proc }
95
95
  .to raise_exception(CarrierWave::Uploader::Base::ConfigurationError)
@@ -44,6 +44,25 @@ describe CarrierWave::Storage::AWSFile do
44
44
  end
45
45
  end
46
46
 
47
+ describe '#read' do
48
+ let(:s3_object) { instance_double('Aws::S3::Object') }
49
+
50
+ it 'reads the retrieved body if called without block' do
51
+ aws_file.file = s3_object
52
+
53
+ expect(s3_object).to receive_message_chain('get.body.read')
54
+ aws_file.read
55
+ end
56
+
57
+ it 'does not retrieve body if block given' do
58
+ aws_file.file = s3_object
59
+ block = proc {}
60
+
61
+ expect(s3_object).to receive('get')
62
+ expect(aws_file.read(&block)).to be_nil
63
+ end
64
+ end
65
+
47
66
  describe '#url' do
48
67
  it 'requests a public url if acl is public readable' do
49
68
  allow(uploader).to receive(:aws_acl) { :'public-read' }
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Moving Files', type: :feature do
4
+ let(:image) { File.open('spec/fixtures/image.png', 'r') }
5
+ let(:original) { FeatureUploader.new }
6
+
7
+ it 'copies an existing file to the specified path' do
8
+ original.store!(image)
9
+ original.retrieve_from_store!('image.png')
10
+
11
+ original_attributes = original.file.attributes
12
+ original_acl_grants = original.file.file.acl.grants
13
+
14
+ original.file.move_to('uploads/image2.png')
15
+
16
+ move = FeatureUploader.new
17
+ move.retrieve_from_store!('image2.png')
18
+
19
+ copy_attributes = move.file.attributes
20
+ copy_acl_grants = move.file.file.acl.grants
21
+
22
+ expect(copy_attributes).to eq(original_attributes)
23
+ expect(copy_acl_grants).to eq(original_acl_grants)
24
+ expect(original.file).not_to exist
25
+
26
+ image.close
27
+ move.file.delete
28
+ end
29
+ end
@@ -63,4 +63,32 @@ describe 'Storing Files', type: :feature do
63
63
  image.close
64
64
  instance.file.delete
65
65
  end
66
+
67
+ it 'uploads the cache file to the configured bucket' do
68
+ instance.cache!(image)
69
+ instance.retrieve_from_cache!(instance.cache_name)
70
+
71
+ expect(instance.file.size).to be_nonzero
72
+ expect(image.size).to eq(instance.file.size)
73
+
74
+ image.close
75
+ instance.file.delete
76
+ end
77
+
78
+ it 'moves cached files to final location when storing' do
79
+ instance.cache!(image)
80
+ cache_name = instance.cache_name
81
+ instance.store!
82
+
83
+ instance.retrieve_from_cache!(cache_name)
84
+ expect(instance.file).not_to exist
85
+
86
+ instance.retrieve_from_store!('image.png')
87
+ expect(instance.file.size).to eq(image.size)
88
+ expect(instance.file.read).to eq(image.read)
89
+ expect(instance.file.read).to eq(instance.file.read)
90
+
91
+ image.close
92
+ instance.file.delete
93
+ end
66
94
  end
@@ -36,9 +36,10 @@ RSpec.configure do |config|
36
36
 
37
37
  config.before(:all, type: :feature) do
38
38
  CarrierWave.configure do |cw_config|
39
- cw_config.storage = :aws
40
- cw_config.aws_bucket = ENV['S3_BUCKET_NAME']
41
- cw_config.aws_acl = :'public-read'
39
+ cw_config.storage = :aws
40
+ cw_config.cache_storage = :aws
41
+ cw_config.aws_bucket = ENV['S3_BUCKET_NAME']
42
+ cw_config.aws_acl = :'public-read'
42
43
 
43
44
  cw_config.aws_credentials = {
44
45
  access_key_id: ENV['S3_ACCESS_KEY'],
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: 1.0.2
4
+ version: 1.1.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: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -91,7 +91,7 @@ files:
91
91
  - spec/carrierwave/storage/aws_spec.rb
92
92
  - spec/carrierwave/support/uri_filename_spec.rb
93
93
  - spec/features/copying_files_spec.rb
94
- - spec/features/deleting_files_spec.rb
94
+ - spec/features/moving_files_spec.rb
95
95
  - spec/features/storing_files_spec.rb
96
96
  - spec/fixtures/image.png
97
97
  - spec/spec_helper.rb
@@ -125,7 +125,7 @@ test_files:
125
125
  - spec/carrierwave/storage/aws_spec.rb
126
126
  - spec/carrierwave/support/uri_filename_spec.rb
127
127
  - spec/features/copying_files_spec.rb
128
- - spec/features/deleting_files_spec.rb
128
+ - spec/features/moving_files_spec.rb
129
129
  - spec/features/storing_files_spec.rb
130
130
  - spec/fixtures/image.png
131
131
  - spec/spec_helper.rb
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Deleting Files', type: :feature do
4
- let(:image) { File.open('spec/fixtures/image.png', 'r') }
5
- let(:instance) { FeatureUploader.new }
6
-
7
- before do
8
- instance.aws_acl = 'public-read'
9
- instance.store!(image)
10
- end
11
-
12
- it 'deletes the image when assigned a `nil` value' do
13
- end
14
- end