carrierwave-base64 2.5.2 → 2.5.3

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: 1bf3a0864b2f90cac7985e88aaa336bfba20730f
4
- data.tar.gz: a64c775e1a9f9922a621593a9dc0c9f748aa04ba
3
+ metadata.gz: 7dff45d674c5e293cfead7291d9a6c53be492672
4
+ data.tar.gz: 628856bf8cccdf7dd686ae2ee57deef2d5077e4d
5
5
  SHA512:
6
- metadata.gz: 5a799a89394c9c5e16481edde7c3db7c67746ff0257adfcb6e9d56fec393c2a0dc37705f9266cbe20df8e3c606b18edc93426a3b8a0afabea3589439a482d5d4
7
- data.tar.gz: 989f85844ff4302d89efc9d3b912739d07712c69e8eaa5515ddab714505f255842f7aa98a772b548be36a8362c46e603c5b1c8de7aed260ff117d0d05ab6c9e5
6
+ metadata.gz: dee1bc71961ec31d297fb70af591fe833c4934bb38685e862ab33ff58bc9f69e34f4850b26a86b7189c8c0c775e581e89d20e0f89b5ea56c20e05e1957dc3169
7
+ data.tar.gz: d4be112dc0dec5e83a78e6bd1027422f559da7f8d61f3afc1bb30baee75ece8783823dd2026bf5e78d062f01b978c2b16ef78de5af9273a1f8ef44f98ddc64e2
@@ -1,5 +1,9 @@
1
1
  # carrierwave-base64 changelog
2
2
 
3
+ ## 2.5.3
4
+
5
+ - Fixed an incorrect deprecation warning that fired even with `file_name` option set to a Proc (#60, @frodsan)
6
+
3
7
  ## 2.5.2
4
8
 
5
9
  - Fixed the exception for uploads without `file_name` option set (issue #56 by @hanhdt, fix by @szajbus)
@@ -8,6 +8,14 @@ module Carrierwave
8
8
  mount_uploader attribute, uploader_class, options
9
9
  options[:file_name] ||= proc { attribute }
10
10
 
11
+ if options[:file_name].is_a?(String)
12
+ warn(
13
+ '[Deprecation warning] Setting `file_name` option to a string is '\
14
+ 'deprecated and will be removed in 3.0.0. If you want to keep the '\
15
+ 'existing behaviour, wrap the string in a Proc'
16
+ )
17
+ end
18
+
11
19
  define_method "#{attribute}=" do |data|
12
20
  return if data == send(attribute).to_s
13
21
 
@@ -21,8 +29,8 @@ module Carrierwave
21
29
  filename = if options[:file_name].respond_to?(:call)
22
30
  options[:file_name].call(self)
23
31
  else
24
- options[:file_name].to_s
25
- end
32
+ options[:file_name]
33
+ end.to_s
26
34
 
27
35
  super Carrierwave::Base64::Base64StringIO.new(data.strip, filename)
28
36
  end
@@ -5,13 +5,13 @@ module Carrierwave
5
5
 
6
6
  attr_accessor :file_extension, :file_name
7
7
 
8
- def initialize(encoded_file, file_name_proc_or_string)
8
+ def initialize(encoded_file, file_name)
9
9
  description, encoded_bytes = encoded_file.split(',')
10
10
 
11
11
  raise ArgumentError unless encoded_bytes
12
12
  raise ArgumentError if encoded_bytes.eql?('(null)')
13
13
 
14
- @file_name = extract_file_name(file_name_proc_or_string)
14
+ @file_name = file_name
15
15
  @file_extension = get_file_extension description
16
16
  bytes = ::Base64.decode64 encoded_bytes
17
17
 
@@ -32,19 +32,6 @@ module Carrierwave
32
32
  end
33
33
  mime_type.preferred_extension
34
34
  end
35
-
36
- def extract_file_name(proc_or_string)
37
- if proc_or_string.is_a?(Proc)
38
- proc_or_string.call
39
- else
40
- warn(
41
- '[Deprecation warning] Setting `file_name` option to a string is '\
42
- 'deprecated and will be removed in 3.0.0. If you want to keep the '\
43
- 'existing behaviour, wrap the string in a Proc'
44
- )
45
- proc_or_string
46
- end
47
- end
48
35
  end
49
36
  end
50
37
  end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = '2.5.2'.freeze
3
+ VERSION = '2.5.3'.freeze
4
4
  end
5
5
  end
@@ -51,6 +51,26 @@ RSpec.describe Carrierwave::Base64::Adapter do
51
51
  expect(subject.image).to be_an_instance_of(uploader)
52
52
  end
53
53
 
54
+ context 'when file_name is a string' do
55
+ it 'issues a deprecation warning' do
56
+ expect do
57
+ User.mount_base64_uploader(
58
+ :image, uploader, file_name: 'file_name'
59
+ )
60
+ end.to warn('Deprecation')
61
+ end
62
+ end
63
+
64
+ context 'when file_name is a proc' do
65
+ it 'does NOT issue a deprecation warning' do
66
+ expect do
67
+ User.mount_base64_uploader(
68
+ :image, uploader, file_name: ->(u) { u.username }
69
+ )
70
+ end.not_to warn('Deprecation')
71
+ end
72
+ end
73
+
54
74
  context 'normal file uploads' do
55
75
  before(:each) do
56
76
  sham_rack_app = ShamRack.at('www.example.com').stub
@@ -32,20 +32,6 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
32
32
  model = described_class.new data, 'string-file-name'
33
33
  expect(model.file_name).to eql('string-file-name')
34
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
49
35
  end
50
36
  end
51
37
 
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.2
4
+ version: 2.5.3
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-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave