carrierwave-aws 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/carrierwave/aws/version.rb +1 -1
- data/lib/carrierwave/storage/aws_file.rb +8 -2
- data/spec/carrierwave/storage/aws_file_spec.rb +25 -0
- data/spec/carrierwave/storage/aws_spec.rb +3 -1
- data/spec/features/copying_files_spec.rb +5 -6
- data/spec/features/moving_files_spec.rb +5 -3
- data/spec/features/storing_files_spec.rb +20 -0
- data/spec/spec_helper.rb +7 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99322449ca09f847fad0897f683096b13fa37395
|
4
|
+
data.tar.gz: 3a4941fbb9ae7d78d359dee569c91a2741c67e59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b1e88465b0da6b185a97461c26db51dd41b761e4ca4733914bd8214dac6108d3e93fbf032d469e52bff7d10d587e0d22f278ce216675efbf73962c402545fd
|
7
|
+
data.tar.gz: 6d6e3f753a69a58e8f5f9b826c41b6e0dd052bb34ef27230d4d4e4727a1124775a780da4f23754e5b4c443d76880a8f7b28091ad9ee55c8e6450202d4f842532
|
@@ -6,7 +6,7 @@ module CarrierWave
|
|
6
6
|
attr_writer :file
|
7
7
|
attr_accessor :uploader, :connection, :path, :aws_options
|
8
8
|
|
9
|
-
delegate :content_type, :delete, :exists?,
|
9
|
+
delegate :content_type, :delete, :exists?, to: :file
|
10
10
|
|
11
11
|
def initialize(uploader, connection, path)
|
12
12
|
@uploader = uploader
|
@@ -19,6 +19,12 @@ module CarrierWave
|
|
19
19
|
@file ||= bucket.object(path)
|
20
20
|
end
|
21
21
|
|
22
|
+
def size
|
23
|
+
file.size
|
24
|
+
rescue Aws::S3::Errors::NotFound
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
22
28
|
alias to_file file
|
23
29
|
|
24
30
|
def attributes
|
@@ -50,7 +56,7 @@ module CarrierWave
|
|
50
56
|
if new_file.is_a?(self.class)
|
51
57
|
new_file.move_to(path)
|
52
58
|
else
|
53
|
-
file.
|
59
|
+
file.upload_file(new_file.path, aws_options.write_options(new_file))
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
@@ -101,4 +101,29 @@ describe CarrierWave::Storage::AWSFile do
|
|
101
101
|
expect(aws_file.url).to eq('http://example.com/files/1/file.txt')
|
102
102
|
end
|
103
103
|
end
|
104
|
+
|
105
|
+
describe '#store' do
|
106
|
+
context 'when new_file is an AWSFile' do
|
107
|
+
let(:new_file) do
|
108
|
+
CarrierWave::Storage::AWSFile.new(uploader, connection, path)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'moves the object' do
|
112
|
+
expect(new_file).to receive(:move_to).with(path)
|
113
|
+
aws_file.store(new_file)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when new file if a SanitizedFile' do
|
118
|
+
let(:new_file) do
|
119
|
+
CarrierWave::SanitizedFile.new('spec/fixtures/image.png')
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'uploads the file using with multipart support' do
|
123
|
+
expect(file).to(receive(:upload_file)
|
124
|
+
.with(new_file.path, an_instance_of(Hash)))
|
125
|
+
aws_file.store(new_file)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
104
129
|
end
|
@@ -23,7 +23,9 @@ describe CarrierWave::Storage::AWS do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'caches connections by credentials' do
|
26
|
-
|
26
|
+
new_storage = CarrierWave::Storage::AWS.new(uploader)
|
27
|
+
|
28
|
+
expect(storage.connection).to be(new_storage.connection)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -8,16 +8,15 @@ describe 'Copying Files', type: :feature do
|
|
8
8
|
original.store!(image)
|
9
9
|
original.retrieve_from_store!('image.png')
|
10
10
|
|
11
|
-
|
11
|
+
without_timestamp = ->(key, _) { key == :last_modified }
|
12
|
+
|
13
|
+
original.file.copy_to("#{original.store_dir}/image2.png")
|
12
14
|
|
13
15
|
copy = FeatureUploader.new
|
14
16
|
copy.retrieve_from_store!('image2.png')
|
15
17
|
|
16
|
-
original_attributes = original.file.attributes
|
17
|
-
|
18
|
-
|
19
|
-
copy_attributes = copy.file.attributes
|
20
|
-
copy_attributes.reject! { |key, _| key == :last_modified }
|
18
|
+
original_attributes = original.file.attributes.reject(&without_timestamp)
|
19
|
+
copy_attributes = copy.file.attributes.reject(&without_timestamp)
|
21
20
|
|
22
21
|
copy_acl_grants = copy.file.file.acl.grants
|
23
22
|
original_acl_grants = original.file.file.acl.grants
|
@@ -8,15 +8,17 @@ describe 'Moving Files', type: :feature do
|
|
8
8
|
original.store!(image)
|
9
9
|
original.retrieve_from_store!('image.png')
|
10
10
|
|
11
|
-
|
11
|
+
without_timestamp = ->(key, _) { key == :last_modified }
|
12
|
+
|
13
|
+
original_attributes = original.file.attributes.reject(&without_timestamp)
|
12
14
|
original_acl_grants = original.file.file.acl.grants
|
13
15
|
|
14
|
-
original.file.move_to(
|
16
|
+
original.file.move_to("#{original.store_dir}/image2.png")
|
15
17
|
|
16
18
|
move = FeatureUploader.new
|
17
19
|
move.retrieve_from_store!('image2.png')
|
18
20
|
|
19
|
-
copy_attributes = move.file.attributes
|
21
|
+
copy_attributes = move.file.attributes.reject(&without_timestamp)
|
20
22
|
copy_acl_grants = move.file.file.acl.grants
|
21
23
|
|
22
24
|
expect(copy_attributes).to eq(original_attributes)
|
@@ -20,6 +20,26 @@ describe 'Storing Files', type: :feature do
|
|
20
20
|
instance.file.delete
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'uploads a StringIO to the configured bucket' do
|
24
|
+
# https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Upload-from-a-string-in-Rails-3-or-later
|
25
|
+
io = StringIO.new(image.read)
|
26
|
+
|
27
|
+
def io.original_filename
|
28
|
+
'image.png'
|
29
|
+
end
|
30
|
+
image.rewind
|
31
|
+
|
32
|
+
instance.store!(io)
|
33
|
+
instance.retrieve_from_store!('image.png')
|
34
|
+
|
35
|
+
expect(instance.file.size).to eq(image.size)
|
36
|
+
expect(instance.file.read).to eq(image.read)
|
37
|
+
expect(instance.file.read).to eq(instance.file.read)
|
38
|
+
|
39
|
+
image.close
|
40
|
+
instance.file.delete
|
41
|
+
end
|
42
|
+
|
23
43
|
it 'retrieves the attributes for a stored file' do
|
24
44
|
instance.store!(image)
|
25
45
|
instance.retrieve_from_store!('image.png')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'carrierwave'
|
2
2
|
require 'carrierwave-aws'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
STORE_DIR = ENV['TRAVIS_JOB_NUMBER'] || SecureRandom.hex(5)
|
3
6
|
|
4
7
|
def source_environment_file!
|
5
8
|
return unless File.exist?('.env')
|
@@ -11,6 +14,10 @@ def source_environment_file!
|
|
11
14
|
end
|
12
15
|
|
13
16
|
FeatureUploader = Class.new(CarrierWave::Uploader::Base) do
|
17
|
+
def store_dir
|
18
|
+
STORE_DIR
|
19
|
+
end
|
20
|
+
|
14
21
|
def filename
|
15
22
|
'image.png'
|
16
23
|
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: 1.
|
4
|
+
version: 1.2.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: 2017-
|
11
|
+
date: 2017-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
39
|
+
version: '2.1'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '2.
|
46
|
+
version: '2.1'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|