carrierwave-base64 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +9 -1
- data/carrierwave-base64.gemspec +2 -1
- data/lib/carrierwave/base64/adapter.rb +8 -7
- data/lib/carrierwave/base64/version.rb +1 -1
- data/spec/adapter_spec.rb +20 -1
- data/spec/base64_string_io_spec.rb +19 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/support/custom_expectations/warn_expectation.rb +30 -0
- data/spec/support/models.rb +1 -3
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50240c7cf3c2cc6381e0f4b6fd264e26378acf8e
|
4
|
+
data.tar.gz: 814aa3ed6143aac25487da35fd311053e50ab5ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7c1c2b46ab8120ca6a6d6cb11e06668627de9a7ee6b3b6d36bf9bfc01a762e49a6d68ad97c3bb6f4596e540c2e65a1cc40b5bce8eef7f2f1e0eb75828cc3c5
|
7
|
+
data.tar.gz: 807f88ed34208638470d32eff7e5d509f078364908a12037988f2b9ad942e6a1c2df3d7fe7443e05c05aeada8d4517d5b8671a6b017eb935c0b32ad134017f12
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# carrierwave-base64 changelog
|
2
2
|
|
3
|
+
## 2.5.1
|
4
|
+
|
5
|
+
- Fixed the issue with the filename to be set once for a model, and never updated again (@dustMason, #55)
|
6
|
+
|
3
7
|
## 2.5.0
|
4
8
|
|
5
9
|
- The uploaded file is not deleted, when the attribute is set to the existing file name (@lebedev-yury, bug-report #51 by @jmuheim)
|
data/README.md
CHANGED
@@ -38,7 +38,15 @@ Now you can also upload files by passing an encoded base64 string to the attribu
|
|
38
38
|
|
39
39
|
The file extension for the uploaded base64 string is identified automatically using the [mime-types](https://github.com/mime-types/ruby-mime-types/) gem and `content_type` from the uploaded string.
|
40
40
|
|
41
|
-
If the required MIME type is not registered, you can add it, using [MIME::Types#add](http://www.rubydoc.info/gems/mime-types/MIME/Types#add-class_method)
|
41
|
+
If the required MIME type is not registered, you can add it, using [MIME::Types#add](http://www.rubydoc.info/gems/mime-types/MIME/Types#add-class_method):
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
MIME::Types.add(
|
45
|
+
MIME::Type.new('application/icml').tap do |type|
|
46
|
+
type.add_extensions 'icml'
|
47
|
+
end
|
48
|
+
)
|
49
|
+
```
|
42
50
|
|
43
51
|
## Setting the file name
|
44
52
|
|
data/carrierwave-base64.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
@@ -23,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_dependency 'carrierwave', '>= 0.8.0'
|
24
25
|
spec.add_dependency 'mime-types', '~> 3.0'
|
25
26
|
|
26
|
-
spec.add_development_dependency 'rails', '
|
27
|
+
spec.add_development_dependency 'rails', '~> 4'
|
27
28
|
spec.add_development_dependency 'sqlite3'
|
28
29
|
spec.add_development_dependency 'mongoid'
|
29
30
|
spec.add_development_dependency 'carrierwave-mongoid'
|
@@ -6,6 +6,7 @@ module Carrierwave
|
|
6
6
|
# rubocop:disable Metrics/PerceivedComplexity
|
7
7
|
def mount_base64_uploader(attribute, uploader_class, options = {})
|
8
8
|
mount_uploader attribute, uploader_class, options
|
9
|
+
options[:file_name] ||= -> { attribute }
|
9
10
|
|
10
11
|
define_method "#{attribute}=" do |data|
|
11
12
|
return if data == send(attribute).to_s
|
@@ -17,13 +18,13 @@ module Carrierwave
|
|
17
18
|
return super(data) unless data.is_a?(String) &&
|
18
19
|
data.strip.start_with?('data')
|
19
20
|
|
20
|
-
options[:file_name]
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
)
|
21
|
+
filename = if options[:file_name].respond_to?(:call)
|
22
|
+
options[:file_name].call(self)
|
23
|
+
else
|
24
|
+
options[:file_name].to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
super Carrierwave::Base64::Base64StringIO.new(data.strip, filename)
|
27
28
|
end
|
28
29
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
29
30
|
# rubocop:enable Metrics/CyclomaticComplexity
|
data/spec/adapter_spec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe Carrierwave::Base64::Adapter do
|
|
6
6
|
User.mount_base64_uploader(
|
7
7
|
:image, uploader, file_name: ->(u) { u.username }
|
8
8
|
)
|
9
|
-
User.new
|
9
|
+
User.new(username: 'batman')
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:mongoid_model) do
|
@@ -66,6 +66,25 @@ RSpec.describe Carrierwave::Base64::Adapter do
|
|
66
66
|
mongoid_model.image = 'test.jpg'
|
67
67
|
end.not_to raise_error
|
68
68
|
end
|
69
|
+
|
70
|
+
context 'with additional instances of the mounting class' do
|
71
|
+
let(:another_subject) do
|
72
|
+
another_subject = User.new(username: 'robin')
|
73
|
+
another_subject.image = File.read(
|
74
|
+
file_path('fixtures', 'base64_image.fixture')
|
75
|
+
).strip
|
76
|
+
another_subject
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should invoke the file_name proc upon each upload' do
|
80
|
+
subject.save!
|
81
|
+
another_subject.save!
|
82
|
+
another_subject.reload
|
83
|
+
expect(
|
84
|
+
another_subject.image.current_path
|
85
|
+
).to eq file_path('../uploads', 'robin.jpeg')
|
86
|
+
end
|
87
|
+
end
|
69
88
|
end
|
70
89
|
|
71
90
|
context 'stored uploads exist for the field' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.describe Carrierwave::Base64::Base64StringIO do
|
2
|
-
%w
|
3
|
-
image/jpeg application/pdf audio/mpeg
|
2
|
+
%w[application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
3
|
+
image/jpeg application/pdf audio/mpeg].each do |content_type|
|
4
4
|
context "correct #{content_type} data" do
|
5
5
|
let(:data) do
|
6
6
|
"data:#{content_type};base64,/9j/4AAQSkZJRgABAQEASABKdhH//2Q=="
|
@@ -22,7 +22,9 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
|
|
22
22
|
|
23
23
|
it 'calls a function that returns the file_name' do
|
24
24
|
method = ->(u) { u.username }
|
25
|
-
base64_string_io = described_class.new
|
25
|
+
base64_string_io = described_class.new(
|
26
|
+
data, method.curry[User.new(username: 'batman')]
|
27
|
+
)
|
26
28
|
expect(base64_string_io.file_name).to eql('batman')
|
27
29
|
end
|
28
30
|
|
@@ -30,6 +32,20 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
|
|
30
32
|
model = described_class.new data, 'string-file-name'
|
31
33
|
expect(model.file_name).to eql('string-file-name')
|
32
34
|
end
|
35
|
+
|
36
|
+
it 'issues deprecation warning when string given for file name' do
|
37
|
+
str = ->(u) { u.username }.curry[User.new(username: 'batman')]
|
38
|
+
expect do
|
39
|
+
described_class.new(data, str).file_name
|
40
|
+
end.to warn('Deprecation')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does NOT issue deprecation warning when Proc given for file name' do
|
44
|
+
prc = -> { 'String' }
|
45
|
+
expect do
|
46
|
+
described_class.new(data, prc).file_name
|
47
|
+
end.not_to warn('Deprecation')
|
48
|
+
end
|
33
49
|
end
|
34
50
|
end
|
35
51
|
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec::Matchers.define :warn do |message|
|
2
|
+
match do |block|
|
3
|
+
fake_stderr(&block).include? message
|
4
|
+
end
|
5
|
+
|
6
|
+
description do
|
7
|
+
"warn \"#{message}\""
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should do
|
11
|
+
"expected to #{description}"
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message_for_should_not do
|
15
|
+
"expected to not #{description}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def fake_stderr
|
19
|
+
original_stderr = $stderr
|
20
|
+
$stderr = StringIO.new
|
21
|
+
yield
|
22
|
+
$stderr.string
|
23
|
+
ensure
|
24
|
+
$stderr = original_stderr
|
25
|
+
end
|
26
|
+
|
27
|
+
def supports_block_expectations?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
data/spec/support/models.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-base64
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Lebedev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- spec/fixtures/base64_image.fixture
|
206
206
|
- spec/fixtures/test.jpg
|
207
207
|
- spec/spec_helper.rb
|
208
|
+
- spec/support/custom_expectations/warn_expectation.rb
|
208
209
|
- spec/support/models.rb
|
209
210
|
- spec/support/schema.rb
|
210
211
|
homepage: https://github.com/lebedev-yury/carrierwave-base64
|
@@ -227,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
228
|
version: '0'
|
228
229
|
requirements: []
|
229
230
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.6.8
|
231
232
|
signing_key:
|
232
233
|
specification_version: 4
|
233
234
|
summary: Upload images encoded as base64 to carrierwave.
|
@@ -237,5 +238,6 @@ test_files:
|
|
237
238
|
- spec/fixtures/base64_image.fixture
|
238
239
|
- spec/fixtures/test.jpg
|
239
240
|
- spec/spec_helper.rb
|
241
|
+
- spec/support/custom_expectations/warn_expectation.rb
|
240
242
|
- spec/support/models.rb
|
241
243
|
- spec/support/schema.rb
|