carrierwave-base64 2.5.1.1 → 2.5.2

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: b15712c569ca9849c2d0269932920b6ec796dec7
4
- data.tar.gz: a50333de3bdbe8bbba125bd5cc8b871923f3eefd
3
+ metadata.gz: 1bf3a0864b2f90cac7985e88aaa336bfba20730f
4
+ data.tar.gz: a64c775e1a9f9922a621593a9dc0c9f748aa04ba
5
5
  SHA512:
6
- metadata.gz: 90f8eb4468cbbc5a04e8cf39f273f887aaebcad8c5e75003f5af5ed6c9f571aa02103c6644b4195828dc5af081aac16a8a935728cc2a483c56100f97f55368b1
7
- data.tar.gz: 5c2c86306cee493271f224a60e120bd75bb3ce6d5df86a034bd49af0a6688cc2c29e3ac47d821af51260bd3caa922f108a16048301e07ccbf3842e32d03b9125
6
+ metadata.gz: 5a799a89394c9c5e16481edde7c3db7c67746ff0257adfcb6e9d56fec393c2a0dc37705f9266cbe20df8e3c606b18edc93426a3b8a0afabea3589439a482d5d4
7
+ data.tar.gz: 989f85844ff4302d89efc9d3b912739d07712c69e8eaa5515ddab714505f255842f7aa98a772b548be36a8362c46e603c5b1c8de7aed260ff117d0d05ab6c9e5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # carrierwave-base64 changelog
2
2
 
3
+ ## 2.5.2
4
+
5
+ - Fixed the exception for uploads without `file_name` option set (issue #56 by @hanhdt, fix by @szajbus)
6
+
3
7
  ## 2.5.1
4
8
 
5
9
  - Fixed the issue with the filename to be set once for a model, and never updated again (@dustMason, #55)
@@ -6,7 +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
+ options[:file_name] ||= proc { attribute }
10
10
 
11
11
  define_method "#{attribute}=" do |data|
12
12
  return if data == send(attribute).to_s
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = '2.5.1.1'.freeze
3
+ VERSION = '2.5.2'.freeze
4
4
  end
5
5
  end
data/spec/adapter_spec.rb CHANGED
@@ -2,110 +2,138 @@ RSpec.describe Carrierwave::Base64::Adapter do
2
2
  describe '.mount_base64_uploader' do
3
3
  let(:uploader) { Class.new CarrierWave::Uploader::Base }
4
4
 
5
- subject do
6
- User.mount_base64_uploader(
7
- :image, uploader, file_name: ->(u) { u.username }
8
- )
9
- User.new(username: 'batman')
10
- end
11
-
12
- let(:mongoid_model) do
13
- MongoidModel.mount_base64_uploader(:image, uploader)
14
- MongoidModel.new
15
- end
5
+ context 'mongoid models' do
6
+ let(:mongoid_model) do
7
+ MongoidModel.mount_base64_uploader(:image, uploader)
8
+ MongoidModel.new
9
+ end
16
10
 
17
- it 'mounts the uploader on the image field' do
18
- expect(subject.image).to be_an_instance_of(uploader)
11
+ it 'does not call will_change' do
12
+ expect do
13
+ mongoid_model.image = 'test.jpg'
14
+ end.not_to raise_error
15
+ end
19
16
  end
20
17
 
21
- context 'normal file uploads' do
22
- before(:each) do
23
- sham_rack_app = ShamRack.at('www.example.com').stub
24
- sham_rack_app.register_resource(
25
- '/test.jpg', file_path('fixtures', 'test.jpg'), 'images/jpg'
26
- )
27
- subject[:image] = 'test.jpg'
18
+ context 'models without file_name option for the uploader' do
19
+ subject do
20
+ User.mount_base64_uploader(:image, uploader)
21
+ User.new
28
22
  end
29
23
 
30
- it 'sets will_change for the attribute on activerecord models' do
31
- expect(subject.changed?).to be_truthy
32
- end
24
+ context 'base64 strings' do
25
+ before(:each) do
26
+ subject.image = File.read(
27
+ file_path('fixtures', 'base64_image.fixture')
28
+ ).strip
29
+ end
33
30
 
34
- it 'saves the file' do
35
- subject.save!
36
- subject.reload
31
+ it 'creates a file' do
32
+ subject.save!
33
+ subject.reload
37
34
 
38
- expect(
39
- subject.image.current_path
40
- ).to eq file_path('../uploads', 'test.jpg')
35
+ expect(
36
+ subject.image.current_path
37
+ ).to eq file_path('../uploads', 'image.jpeg')
38
+ end
41
39
  end
42
40
  end
43
41
 
44
- context 'base64 strings' do
45
- before(:each) do
46
- subject.image = File.read(
47
- file_path('fixtures', 'base64_image.fixture')
48
- ).strip
42
+ context 'models with file_name options for the uploader' do
43
+ subject do
44
+ User.mount_base64_uploader(
45
+ :image, uploader, file_name: ->(u) { u.username }
46
+ )
47
+ User.new(username: 'batman')
49
48
  end
50
49
 
51
- it 'creates a file' do
52
- subject.save!
53
- subject.reload
54
-
55
- expect(
56
- subject.image.current_path
57
- ).to eq file_path('../uploads', 'batman.jpeg')
50
+ it 'mounts the uploader on the image field' do
51
+ expect(subject.image).to be_an_instance_of(uploader)
58
52
  end
59
53
 
60
- it 'sets will_change for the attribute' do
61
- expect(subject.changed?).to be_truthy
62
- end
54
+ context 'normal file uploads' do
55
+ before(:each) do
56
+ sham_rack_app = ShamRack.at('www.example.com').stub
57
+ sham_rack_app.register_resource(
58
+ '/test.jpg', file_path('fixtures', 'test.jpg'), 'images/jpg'
59
+ )
60
+ subject[:image] = 'test.jpg'
61
+ end
63
62
 
64
- it 'does not call will_change mongoid models' do
65
- expect do
66
- mongoid_model.image = 'test.jpg'
67
- end.not_to raise_error
63
+ it 'sets will_change for the attribute on activerecord models' do
64
+ expect(subject.changed?).to be_truthy
65
+ end
66
+
67
+ it 'saves the file' do
68
+ subject.save!
69
+ subject.reload
70
+
71
+ expect(
72
+ subject.image.current_path
73
+ ).to eq file_path('../uploads', 'test.jpg')
74
+ end
68
75
  end
69
76
 
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(
77
+ context 'base64 strings' do
78
+ before(:each) do
79
+ subject.image = File.read(
74
80
  file_path('fixtures', 'base64_image.fixture')
75
81
  ).strip
76
- another_subject
77
82
  end
78
83
 
79
- it 'should invoke the file_name proc upon each upload' do
84
+ it 'creates a file' do
80
85
  subject.save!
81
- another_subject.save!
82
- another_subject.reload
86
+ subject.reload
87
+
83
88
  expect(
84
- another_subject.image.current_path
85
- ).to eq file_path('../uploads', 'robin.jpeg')
89
+ subject.image.current_path
90
+ ).to eq file_path('../uploads', 'batman.jpeg')
86
91
  end
87
- end
88
- end
89
92
 
90
- context 'stored uploads exist for the field' do
91
- before :each do
92
- subject.image = File.read(
93
- file_path('fixtures', 'base64_image.fixture')
94
- ).strip
95
- subject.save!
96
- subject.reload
97
- end
93
+ it 'sets will_change for the attribute' do
94
+ expect(subject.changed?).to be_truthy
95
+ end
98
96
 
99
- it 'keeps the file when setting the attribute to existing value' do
100
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
101
- subject.update!(image: subject.image.to_s)
102
- expect(File.exist?(subject.reload.image.file.file)).to be_truthy
97
+ context 'with additional instances of the mounting class' do
98
+ let(:another_subject) do
99
+ another_subject = User.new(username: 'robin')
100
+ another_subject.image = File.read(
101
+ file_path('fixtures', 'base64_image.fixture')
102
+ ).strip
103
+ another_subject
104
+ end
105
+
106
+ it 'should invoke the file_name proc upon each upload' do
107
+ subject.save!
108
+ another_subject.save!
109
+ another_subject.reload
110
+ expect(
111
+ another_subject.image.current_path
112
+ ).to eq file_path('../uploads', 'robin.jpeg')
113
+ end
114
+ end
103
115
  end
104
116
 
105
- it 'removes files when remove_* is set to true' do
106
- subject.remove_image = true
107
- subject.save!
108
- expect(subject.reload.image.file).to be_nil
117
+ context 'stored uploads exist for the field' do
118
+ before :each do
119
+ subject.image = File.read(
120
+ file_path('fixtures', 'base64_image.fixture')
121
+ ).strip
122
+ subject.save!
123
+ subject.reload
124
+ end
125
+
126
+ it 'keeps the file when setting the attribute to existing value' do
127
+ expect(File.exist?(subject.reload.image.file.file)).to be_truthy
128
+ subject.update!(image: subject.image.to_s)
129
+ expect(File.exist?(subject.reload.image.file.file)).to be_truthy
130
+ end
131
+
132
+ it 'removes files when remove_* is set to true' do
133
+ subject.remove_image = true
134
+ subject.save!
135
+ expect(subject.reload.image.file).to be_nil
136
+ end
109
137
  end
110
138
  end
111
139
  end
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.1.1
4
+ version: 2.5.2
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-22 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave