carrierwave-base64 2.5.1.1 → 2.5.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/carrierwave/base64/adapter.rb +1 -1
- data/lib/carrierwave/base64/version.rb +1 -1
- data/spec/adapter_spec.rb +104 -76
- 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: 1bf3a0864b2f90cac7985e88aaa336bfba20730f
|
4
|
+
data.tar.gz: a64c775e1a9f9922a621593a9dc0c9f748aa04ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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] ||=
|
9
|
+
options[:file_name] ||= proc { attribute }
|
10
10
|
|
11
11
|
define_method "#{attribute}=" do |data|
|
12
12
|
return if data == send(attribute).to_s
|
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
|
-
|
6
|
-
|
7
|
-
:image, uploader
|
8
|
-
|
9
|
-
|
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
|
-
|
18
|
-
|
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 '
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
31
|
+
it 'creates a file' do
|
32
|
+
subject.save!
|
33
|
+
subject.reload
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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 '
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
)
|
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 '
|
52
|
-
subject.
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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 '
|
71
|
-
|
72
|
-
|
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 '
|
84
|
+
it 'creates a file' do
|
80
85
|
subject.save!
|
81
|
-
|
82
|
-
|
86
|
+
subject.reload
|
87
|
+
|
83
88
|
expect(
|
84
|
-
|
85
|
-
).to eq file_path('../uploads', '
|
89
|
+
subject.image.current_path
|
90
|
+
).to eq file_path('../uploads', 'batman.jpeg')
|
86
91
|
end
|
87
|
-
end
|
88
|
-
end
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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.
|
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-
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|