attachment_saver 1.2.0 → 1.3.0
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/Gemfile +11 -0
- data/Gemfile.lock +59 -0
- data/attachment_saver.gemspec +2 -0
- data/lib/attachment_saver.rb +2 -0
- data/lib/attachment_saver/version.rb +1 -1
- data/lib/processors/image.rb +2 -0
- data/test/attachment_saver_test.rb +17 -17
- data/test/file_system_datastore_test.rb +4 -3
- data/test/fixtures/ssrf.png +4 -0
- data/test/image_fixtures.rb +1 -1
- data/test/image_processor_test_common.rb +41 -13
- data/test/in_column_datastore_test.rb +1 -1
- data/test/model_test.rb +2 -2
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c35a16fce5a99e7ed88cc052759edcfbe3888202
|
4
|
+
data.tar.gz: 79cb33e50d35f9dd4828a42e07cb11781637e3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0911d907f27e14f6f75c1e3c80dc70f492e465868de2f38c6f7325d52eb7fa79dbaef9007070be838da7ddf76d4302b64e59b41fa268f8c176ac32191cb7612d'
|
7
|
+
data.tar.gz: 649583ca6636e12a6f3f4e03ea1a8ea71124c09f5c728f116b1765e4457cdbe8ef874800b5acdc4c3c08bdbdb346fc8f954b42ee1b8d6bb6a4802b9d43f5fe78
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in transaction_isolation_level.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
attachment_saver (1.2.0)
|
5
|
+
activerecord
|
6
|
+
mimemagic
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
RubyInline (3.12.4)
|
12
|
+
ZenTest (~> 4.3)
|
13
|
+
ZenTest (4.11.1)
|
14
|
+
activemodel (5.1.4)
|
15
|
+
activesupport (= 5.1.4)
|
16
|
+
activerecord (5.1.4)
|
17
|
+
activemodel (= 5.1.4)
|
18
|
+
activesupport (= 5.1.4)
|
19
|
+
arel (~> 8.0)
|
20
|
+
activesupport (5.1.4)
|
21
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
22
|
+
i18n (~> 0.7)
|
23
|
+
minitest (~> 5.1)
|
24
|
+
tzinfo (~> 1.1)
|
25
|
+
arel (8.0.0)
|
26
|
+
concurrent-ruby (1.0.5)
|
27
|
+
i18n (0.9.1)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
image_science (1.3.0)
|
30
|
+
RubyInline (~> 3.9)
|
31
|
+
image_size (1.5.0)
|
32
|
+
metaclass (0.0.4)
|
33
|
+
mimemagic (0.3.2)
|
34
|
+
mini_magick (4.8.0)
|
35
|
+
minitest (5.10.3)
|
36
|
+
mocha (1.3.0)
|
37
|
+
metaclass (~> 0.0.1)
|
38
|
+
rake (12.3.0)
|
39
|
+
rmagick (2.16.0)
|
40
|
+
sqlite3 (1.3.13)
|
41
|
+
thread_safe (0.3.6)
|
42
|
+
tzinfo (1.2.4)
|
43
|
+
thread_safe (~> 0.1)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
attachment_saver!
|
50
|
+
image_science
|
51
|
+
image_size
|
52
|
+
mini_magick
|
53
|
+
mocha
|
54
|
+
rake
|
55
|
+
rmagick
|
56
|
+
sqlite3
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.15.3
|
data/attachment_saver.gemspec
CHANGED
@@ -32,5 +32,7 @@ EOF
|
|
32
32
|
gem.add_development_dependency "image_science"
|
33
33
|
gem.add_development_dependency "rmagick"
|
34
34
|
gem.add_development_dependency "mini_magick"
|
35
|
+
gem.add_development_dependency "image_size"
|
35
36
|
gem.add_development_dependency "sqlite3"
|
37
|
+
gem.add_development_dependency "mocha"
|
36
38
|
end
|
data/lib/attachment_saver.rb
CHANGED
@@ -123,6 +123,8 @@ module AttachmentSaver
|
|
123
123
|
process_attachment(filename)
|
124
124
|
rescue AttachmentProcessorError
|
125
125
|
raise # pass any exceptions of the correct type (which anything eminating from our processors should be) straight
|
126
|
+
rescue NotImplementedError
|
127
|
+
raise
|
126
128
|
rescue Exception => ex
|
127
129
|
raise AttachmentProcessorError, "#{ex.class}: #{ex.message}", ex.backtrace # wrap anything else
|
128
130
|
end
|
data/lib/processors/image.rb
CHANGED
@@ -54,8 +54,8 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
54
54
|
|
55
55
|
def test_default_methods
|
56
56
|
model = SomeModel.new
|
57
|
-
|
58
|
-
|
57
|
+
assert_nil model.uploaded_data
|
58
|
+
assert_nil model.uploaded_file
|
59
59
|
assert_equal false, model.process_attachment?
|
60
60
|
assert File.directory?(model.tempfile_directory)
|
61
61
|
end
|
@@ -66,10 +66,10 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
66
66
|
model = SomeModel.new
|
67
67
|
model.uploaded_data = 'test #1'
|
68
68
|
assert_equal 7, model.size
|
69
|
-
|
70
|
-
|
69
|
+
assert_nil model.content_type
|
70
|
+
assert_nil model.original_filename
|
71
71
|
assert_equal 'test #1', model.uploaded_data # before converting to an uploaded_file
|
72
|
-
|
72
|
+
assert_not_nil model.uploaded_file
|
73
73
|
assert model.uploaded_file.is_a?(Tempfile)
|
74
74
|
assert_equal model.uploaded_file.object_id, model.uploaded_file.object_id, 'uploaded_file should return the same instance each time'
|
75
75
|
assert_equal 'test #1', model.uploaded_data # after converting to an uploaded_file
|
@@ -83,10 +83,10 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
83
83
|
data = File.open(ImageFixtures::valid[:path], "rb").read
|
84
84
|
model.uploaded_data = data
|
85
85
|
assert_equal ImageFixtures::valid[:size], model.size
|
86
|
-
|
87
|
-
|
86
|
+
assert_nil model.content_type
|
87
|
+
assert_nil model.original_filename
|
88
88
|
assert_equal data, model.uploaded_data # before converting to an uploaded_file
|
89
|
-
|
89
|
+
assert_not_nil model.uploaded_file
|
90
90
|
assert model.uploaded_file.is_a?(Tempfile)
|
91
91
|
assert_equal model.uploaded_file.object_id, model.uploaded_file.object_id, 'uploaded_file should return the same instance each time'
|
92
92
|
assert_equal data, model.uploaded_data # after converting to an uploaded_file
|
@@ -99,9 +99,9 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
99
99
|
model = SomeModel.new
|
100
100
|
model.uploaded_data = StringIO.new('test #2')
|
101
101
|
assert_equal 7, model.size
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
assert_nil model.content_type
|
103
|
+
assert_nil model.original_filename
|
104
|
+
assert_not_nil model.uploaded_file
|
105
105
|
assert model.uploaded_file.is_a?(Tempfile)
|
106
106
|
assert_equal model.uploaded_file.object_id, model.uploaded_file.object_id, 'uploaded_file should return the same instance each time'
|
107
107
|
assert_equal 'test #2', model.uploaded_data
|
@@ -116,8 +116,8 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
116
116
|
model = SomeModel.new
|
117
117
|
model.uploaded_data = tempfile
|
118
118
|
assert_equal 7, model.size
|
119
|
-
|
120
|
-
|
119
|
+
assert_nil model.content_type
|
120
|
+
assert_nil model.original_filename
|
121
121
|
assert_equal tempfile.object_id, model.uploaded_file.object_id, 'uploaded_file should return the originally given tempfile'
|
122
122
|
assert_equal 'test #3', model.uploaded_data
|
123
123
|
assert_equal 'test #3', contents_of(model.uploaded_file)
|
@@ -171,9 +171,9 @@ class AttachmentSaverTest < ActiveSupport::TestCase
|
|
171
171
|
|
172
172
|
model = SomeModel.new
|
173
173
|
model.uploaded_data = '' # this is what controllers get sent when there's a file field but no file selected; attachment_saver accordingly handles blank strings as a special case
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
174
|
+
assert_nil model.uploaded_file
|
175
|
+
assert_nil model.size
|
176
|
+
assert_nil model.content_type
|
177
|
+
assert_nil model.original_filename
|
178
178
|
end
|
179
179
|
end
|
@@ -47,7 +47,8 @@ class FileSystemDatastoreTest < ActiveSupport::TestCase
|
|
47
47
|
@saved_to = filename
|
48
48
|
save_attachment_to_without_record(filename)
|
49
49
|
end
|
50
|
-
|
50
|
+
alias_method :save_attachment_to_without_record, :save_attachment_to
|
51
|
+
alias_method :save_attachment_to, :save_attachment_to_with_record
|
51
52
|
|
52
53
|
|
53
54
|
def save_attachment_to_test(expected_data)
|
@@ -346,8 +347,8 @@ class FileSystemDatastoreTest < ActiveSupport::TestCase
|
|
346
347
|
|
347
348
|
assert_raises(AttachmentProcessorError) { save_attachment }
|
348
349
|
|
349
|
-
|
350
|
-
|
350
|
+
assert_nil storage_key, "storage key wasn't reset after processing failed"
|
351
|
+
assert_not_nil @saved_to, "save_attachment_to not called"
|
351
352
|
assert !File.exist?(@saved_to), "saved file wasn't removed after processing failed"
|
352
353
|
end
|
353
354
|
|
data/test/image_fixtures.rb
CHANGED
@@ -31,6 +31,10 @@ module ImageProcessorTestModel
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module ImageProcessorTests
|
34
|
+
def processes_images?
|
35
|
+
true # overridden for examine-only processors
|
36
|
+
end
|
37
|
+
|
34
38
|
def test_attributes_from_valid
|
35
39
|
processor_model.attachment_options = {}
|
36
40
|
ImageFixtures.all_readable.each do |fixture|
|
@@ -46,16 +50,33 @@ module ImageProcessorTests
|
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
49
|
-
def
|
53
|
+
def test_attributes_from_non_image
|
50
54
|
processor_model.attachment_options = {}
|
51
|
-
ImageFixtures.all_unreadable.each do |fixture|
|
55
|
+
(ImageFixtures.all_unreadable - [ImageFixtures.corrupt]).each do |fixture|
|
52
56
|
model = processor_model.new(File.open(fixture[:path], 'rb'))
|
53
57
|
model.content_type = fixture[:content_type]
|
54
58
|
assert_raises(processor_exception) { model.examine_image }
|
55
59
|
assert_equal fixture[:expected_content_type], model.content_type
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
assert_nil model.width
|
61
|
+
assert_nil model.height
|
62
|
+
assert_nil model.image_size
|
63
|
+
assert_equal 'bin', model.file_extension
|
64
|
+
model.original_filename = fixture[:original_filename]
|
65
|
+
assert_equal fixture[:expected_extension], model.file_extension
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_attributes_from_corrupt
|
70
|
+
processor_model.attachment_options = {}
|
71
|
+
if processes_images?
|
72
|
+
fixture = ImageFixtures.corrupt
|
73
|
+
model = processor_model.new(File.open(fixture[:path], 'rb'))
|
74
|
+
model.content_type = fixture[:content_type]
|
75
|
+
assert_raises(processor_exception) { model.examine_image }
|
76
|
+
assert_equal fixture[:expected_content_type], model.content_type
|
77
|
+
assert_nil model.width
|
78
|
+
assert_nil model.height
|
79
|
+
assert_nil model.image_size
|
59
80
|
assert_equal 'bin', model.file_extension
|
60
81
|
model.original_filename = fixture[:original_filename]
|
61
82
|
assert_equal fixture[:expected_extension], model.file_extension
|
@@ -78,14 +99,21 @@ module ImageProcessorTests
|
|
78
99
|
model = processor_model.new(File.open(fixture[:path], 'rb'))
|
79
100
|
model.content_type = fixture[:content_type]
|
80
101
|
model.original_filename = fixture[:original_filename]
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
102
|
+
|
103
|
+
if processes_images?
|
104
|
+
model.process_attachment(model.uploaded_file_path)
|
105
|
+
|
106
|
+
ImageOperations.expected_results.each do |format_name, size|
|
107
|
+
derived = model.find_derived(format_name)
|
108
|
+
assert !derived.nil?, "no derived image named #{format_name} generated"
|
109
|
+
assert_equal size.first, derived[:width], "#{format_name} width incorrect"
|
110
|
+
assert_equal size.last, derived[:height], "#{format_name} height incorrect"
|
111
|
+
assert_equal model.file_extension, derived[:file_extension], "#{format_name} file_extension incorrect"
|
112
|
+
end
|
113
|
+
else
|
114
|
+
assert_raise(NotImplementedError) do
|
115
|
+
model.process_attachment(model.uploaded_file_path)
|
116
|
+
end
|
89
117
|
end
|
90
118
|
end
|
91
119
|
end
|
data/test/model_test.rb
CHANGED
@@ -155,7 +155,7 @@ class ModelTest < ActiveSupport::TestCase
|
|
155
155
|
model.update_attributes(:uploaded_data => uploaded_file_from(ImageFixtures::valid))
|
156
156
|
new_storage_filenames = [model.storage_filename] + model.formats.sort_by(&:format_name).collect(&:storage_filename)
|
157
157
|
model.reload
|
158
|
-
model.formats
|
158
|
+
model.formats.reload
|
159
159
|
reloaded_storage_filenames = [model.storage_filename] + model.formats.sort_by(&:format_name).collect(&:storage_filename)
|
160
160
|
|
161
161
|
assert_equal Image::FORMATS.size, model.formats.size
|
@@ -182,7 +182,7 @@ class ModelTest < ActiveSupport::TestCase
|
|
182
182
|
OtherImage.want_smalls = false
|
183
183
|
model.update_attributes!(:uploaded_data => uploaded_file_from(ImageFixtures::valid))
|
184
184
|
#assert_equal ["normal"], model.formats.collect(&:format_name).sort # because we use formats.destroy(..ids..), they really should be removed from the formats collection in memory, but aren't in Rails 1.2.3 :/. so the normal, expected semantics is that apps must reload to see collection changes.
|
185
|
-
assert_equal ["normal"], model.formats
|
185
|
+
assert_equal ["normal"], model.formats.reload.collect(&:format_name).sort
|
186
186
|
# note that the small size has not only been not regenerated, it's been deleted
|
187
187
|
end
|
188
188
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attachment_saver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: image_size
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: sqlite3
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mocha
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: |
|
112
140
|
This plugin implements attachment storage and processing, integrated with
|
113
141
|
ActiveRecord models and Ruby CGI/Rails-style uploads. Image processing
|
@@ -123,6 +151,8 @@ extensions: []
|
|
123
151
|
extra_rdoc_files: []
|
124
152
|
files:
|
125
153
|
- ".gitignore"
|
154
|
+
- Gemfile
|
155
|
+
- Gemfile.lock
|
126
156
|
- MIT-LICENSE
|
127
157
|
- README
|
128
158
|
- Rakefile
|
@@ -146,6 +176,7 @@ files:
|
|
146
176
|
- test/fixtures/broken.jpg
|
147
177
|
- test/fixtures/emptyextension.
|
148
178
|
- test/fixtures/noextension
|
179
|
+
- test/fixtures/ssrf.png
|
149
180
|
- test/fixtures/test.jpg
|
150
181
|
- test/fixtures/test.js
|
151
182
|
- test/fixtures/wrongextension.png
|
@@ -181,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
212
|
version: '0'
|
182
213
|
requirements: []
|
183
214
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.2
|
215
|
+
rubygems_version: 2.5.2
|
185
216
|
signing_key:
|
186
217
|
specification_version: 4
|
187
218
|
summary: Saves attachments in files, models, or columns.
|
@@ -192,6 +223,7 @@ test_files:
|
|
192
223
|
- test/fixtures/broken.jpg
|
193
224
|
- test/fixtures/emptyextension.
|
194
225
|
- test/fixtures/noextension
|
226
|
+
- test/fixtures/ssrf.png
|
195
227
|
- test/fixtures/test.jpg
|
196
228
|
- test/fixtures/test.js
|
197
229
|
- test/fixtures/wrongextension.png
|
@@ -207,3 +239,4 @@ test_files:
|
|
207
239
|
- test/rmagick_processor_test.rb
|
208
240
|
- test/schema.rb
|
209
241
|
- test/test_helper.rb
|
242
|
+
has_rdoc: false
|