carrierwave-aws 1.1.0 → 1.2.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: bf33ae82322f4fdbd580886f60268ea23a2a9ce5
4
- data.tar.gz: b68f5c6a83e0415855eaae454838a7ff540c95e6
3
+ metadata.gz: 99322449ca09f847fad0897f683096b13fa37395
4
+ data.tar.gz: 3a4941fbb9ae7d78d359dee569c91a2741c67e59
5
5
  SHA512:
6
- metadata.gz: 4b3dff18c3ca97ae2474dabbafd68da584fdf26b12bdbc285fc002d835b6abb39f170a7f42078334e869f5eb8f7d17ccb710bb24c047a5069f5664ebc56d6fbe
7
- data.tar.gz: cd089a2aae0ed73a80db7dc9d1b164145e9460b10020a0f348ce6b60f12a59a9148c745f8b3bf4e702e56b97788ce7942281f4feaa5c521ac0263d46f7cfac2c
6
+ metadata.gz: 65b1e88465b0da6b185a97461c26db51dd41b761e4ca4733914bd8214dac6108d3e93fbf032d469e52bff7d10d587e0d22f278ce216675efbf73962c402545fd
7
+ data.tar.gz: 6d6e3f753a69a58e8f5f9b826c41b6e0dd052bb34ef27230d4d4e4727a1124775a780da4f23754e5b4c443d76880a8f7b28091ad9ee55c8e6450202d4f842532
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Carrierwave
4
4
  module AWS
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
@@ -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?, :size, to: :file
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.put(aws_options.write_options(new_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
- expect(storage.connection).to eq(storage.connection)
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
- original.file.copy_to('uploads/image2.png')
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
- original_attributes.reject! { |key, _| key == :last_modified }
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
- original_attributes = original.file.attributes
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('uploads/image2.png')
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')
@@ -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.1.0
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-02-24 00:00:00.000000000 Z
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.0'
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.0'
46
+ version: '2.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement