opium 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/opium/file.rb +7 -2
- data/lib/opium/version.rb +1 -1
- data/spec/opium/file_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 544c54e1dac7cf8a8adb4f02fc4335c33c9778b7
|
4
|
+
data.tar.gz: 81bab9d1dbd8139fd8c73d830b16476e1e6b42d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6c906d84d6b3499c0c531fda9966e19e06b80c91e31a850b147bc6c11887120ece07ae9c54b931b6b05496adf0fcdbc8aacfa2d78b9284026c974b424cf4449
|
7
|
+
data.tar.gz: c9a2d427d4f7b961382eeed079fd1400ef2304ea2861577f2cf67354657cc462b673c7fe59c9cad4714d307d11296bdabd9b934091e9c9277b7712ce83878da4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.1.6
|
2
|
+
### Resolved Issues
|
3
|
+
- #39: `Opium::File#upload` now paramterizes the file name.
|
4
|
+
- #38: Added Content-Length and Transfer-Encoding headers to file uploads.
|
5
|
+
|
1
6
|
## 1.1.5
|
2
7
|
### Resolved Issues
|
3
8
|
- #37: Callbacks no longer makes `:update` a private method.
|
data/lib/opium/file.rb
CHANGED
@@ -47,8 +47,8 @@ module Opium
|
|
47
47
|
{}.tap do |result|
|
48
48
|
mime_type = options.fetch( :content_type, MimeMagic.by_magic(file) )
|
49
49
|
mime_type = MimeMagic.by_path(file) if mime_type == 'application/zip'
|
50
|
-
result[:id] = options[:original_filename] || ::File.basename( file )
|
51
|
-
result[:headers] = { content_type: mime_type.to_s }
|
50
|
+
result[:id] = parameterize_name( options[:original_filename] || ::File.basename( file ) )
|
51
|
+
result[:headers] = { content_type: mime_type.to_s, content_length: file.size.to_s }
|
52
52
|
result[:sent_headers] = options[:sent_headers] if options.key? :sent_headers
|
53
53
|
end
|
54
54
|
end
|
@@ -60,6 +60,11 @@ module Opium
|
|
60
60
|
def has_keys( object, *keys )
|
61
61
|
object.keys.all? {|key| keys.include? key}
|
62
62
|
end
|
63
|
+
|
64
|
+
def parameterize_name( name )
|
65
|
+
without_extension, extension = ::File.basename( name, '.*' ), ::File.extname( name )
|
66
|
+
without_extension.parameterize + extension
|
67
|
+
end
|
63
68
|
end
|
64
69
|
|
65
70
|
def initialize( attributes = {} )
|
data/lib/opium/version.rb
CHANGED
data/spec/opium/file_spec.rb
CHANGED
@@ -43,6 +43,23 @@ describe Opium::File do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
context 'with non-standard characters in filename' do
|
47
|
+
let(:upload_options) { { original_filename: 'chunky&bacon$with cheddar@cheese.jpg' } }
|
48
|
+
|
49
|
+
it { expect { result }.to_not raise_exception }
|
50
|
+
it 'paramterizes the name' do
|
51
|
+
expect( result.name ).to end_with 'chunky-bacon-with-cheddar-cheese.jpg'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when executed' do
|
56
|
+
let(:upload_options) { { sent_headers: true } }
|
57
|
+
|
58
|
+
it { expect { result }.to_not raise_exception }
|
59
|
+
it { expect( result.keys ).to include( 'Content-Length' ) }
|
60
|
+
it { expect( result['Content-Length'] ).to eq gif_file.size.to_s }
|
61
|
+
end
|
62
|
+
|
46
63
|
context 'with a :content_type option' do
|
47
64
|
let(:upload_options) { { content_type: 'image/png', sent_headers: true } }
|
48
65
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|