attachment_saver 1.5.0 → 1.5.1

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: 4361cefbe15f73658b90fcdd5257d3f2dfedc449
4
- data.tar.gz: 3667eabf22adae5ecdd045993b5a4882f0120f17
3
+ metadata.gz: f6490e7e2047044a90f1e1173bde73a2f8d35a74
4
+ data.tar.gz: 0ca89b3a3ee2ef6ab30edbda1ca24dc33cf733bc
5
5
  SHA512:
6
- metadata.gz: 9301f20ce8cc4c68e0873df7b6cb7c4bb41a1f119c7dad7e20d1486fad0f5acacbb59eeaf564476730d839c7699f7dc3a615e6e32cbe9c8defe541b4398c8f3d
7
- data.tar.gz: 717eacc83e814b18d03b8857e28ccd8c89c97ef190cbab5c5fdedc3044ff329302b759fafd2ba9608b05d33c6f31894949d2ef45616f1a8d3eb8235bbe3c7058
6
+ metadata.gz: c4e7a26570502f01844906d7c2d2bdd258b80cc4abaf41f44fffeb358875b87b6600de35f98e74757ace80f93a4e23f34fad1142a9544ac4c844cbb8dfbd43f6
7
+ data.tar.gz: ad2e45480b8c97d37878bb4f98a60d3a6899b865519bea7c510f8a6f1a9c264393f183f0b30bc63dfdf0c7a6740dba4371fa8dd42319200f754b416cdc13d981
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attachment_saver (1.5.0)
4
+ attachment_saver (1.5.1)
5
5
  activerecord
6
6
  mimemagic
7
7
 
@@ -1,3 +1,3 @@
1
1
  module AttachmentSaver
2
- VERSION = '1.5.0'
2
+ VERSION = '1.5.1'
3
3
  end
@@ -53,16 +53,24 @@ module AttachmentSaver
53
53
  result = original_image.send(*resize_format) do |derived_image|
54
54
  return nil unless want_format?(derived_format_name, derived_image.width, derived_image.height)
55
55
 
56
- # both original_filename and content_type must be defined for parents when using image processing
57
- # - but apps can just define them using attr_accessor if they don't want them persisted to db
58
- derived_content_type = content_type
59
- derived_extension = derived_image.file_extension
56
+ if original_image.format == 'gif'
57
+ # as a special case hack, don't try and save derived images into GIF format (gdk_pixbuf2 doesn't support that)
58
+ derived_content_type = 'image/png'
59
+ derived_extension = 'png'
60
+ format = 'png'
61
+ else
62
+ # both original_filename and content_type must be defined for parents when using image processing
63
+ # - but apps can just define them using attr_accessor if they don't want them persisted to db
64
+ derived_content_type = content_type
65
+ derived_extension = derived_image.file_extension
66
+ format = original_image.format
67
+ end
60
68
 
61
69
  # we leverage tempfiles as discussed in the uploaded_file method
62
70
  temp = ExtendedTempfile.new("asgtemp", tempfile_directory, derived_extension)
63
71
  temp.binmode
64
72
  temp.close
65
- derived_image.save(temp.path, original_image.format)
73
+ derived_image.save(temp.path, format)
66
74
  temp.open # we close & reopen so we see the file the processor wrote to, even if it created a new file rather than writing into our tempfile
67
75
 
68
76
  { :format_name => derived_format_name.to_s,
Binary file
@@ -17,4 +17,8 @@ class GdkPixbufProcessorTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  include ImageProcessorTests
20
+
21
+ def saves_to_gif_format?
22
+ false
23
+ end
20
24
  end
@@ -8,7 +8,15 @@ class ImageOperations
8
8
  :width => 448,
9
9
  :height => 600 }
10
10
  end
11
-
11
+
12
+ def self.original_gif_image
13
+ { :path => ImageFixtures::fixture_path('test.gif'),
14
+ :content_type => 'image/gif',
15
+ :original_filename => 'test.gif',
16
+ :width => 100,
17
+ :height => 73 }
18
+ end
19
+
12
20
  def self.resize_operations
13
21
  {
14
22
  :squish1 => [:squish, 100, 50],
@@ -35,6 +35,10 @@ module ImageProcessorTests
35
35
  true # overridden for examine-only processors
36
36
  end
37
37
 
38
+ def saves_to_gif_format?
39
+ true
40
+ end
41
+
38
42
  def test_attributes_from_valid
39
43
  processor_model.attachment_options = {}
40
44
  ImageFixtures.all_readable.each do |fixture|
@@ -116,4 +120,36 @@ module ImageProcessorTests
116
120
  end
117
121
  end
118
122
  end
123
+
124
+ def test_derived_attributes_from_gif
125
+ processor_model.attachment_options = {:formats => ImageOperations.resize_operations}
126
+
127
+ fixture = ImageOperations.original_gif_image
128
+ model = processor_model.new(File.open(fixture[:path], 'rb'))
129
+ model.content_type = fixture[:content_type]
130
+ model.original_filename = fixture[:original_filename]
131
+
132
+ if processes_images?
133
+ model.process_attachment(model.uploaded_file_path)
134
+
135
+ ImageOperations.expected_results.each do |format_name, size|
136
+ derived = model.find_derived(format_name)
137
+ assert !derived.nil?, "no derived image named #{format_name} generated"
138
+ assert_equal size.first, derived[:width], "#{format_name} width incorrect"
139
+ assert_equal size.last, derived[:height], "#{format_name} height incorrect"
140
+
141
+ if saves_to_gif_format?
142
+ assert_equal model.file_extension, derived[:file_extension], "#{format_name} file_extension incorrect"
143
+ assert_equal fixture[:content_type], derived[:content_type]
144
+ else
145
+ assert_equal "png", derived[:file_extension], "#{format_name} file_extension incorrect"
146
+ assert_equal "image/png", derived[:content_type]
147
+ end
148
+ end
149
+ else
150
+ assert_raise(NotImplementedError) do
151
+ model.process_attachment(model.uploaded_file_path)
152
+ end
153
+ end
154
+ end
119
155
  end
@@ -17,4 +17,8 @@ class ImageScienceProcessorTest < ActiveSupport::TestCase
17
17
  end
18
18
 
19
19
  include ImageProcessorTests
20
+
21
+ def saves_to_gif_format?
22
+ false
23
+ end
20
24
  end
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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Bryant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2018-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -195,6 +195,7 @@ files:
195
195
  - test/fixtures/noextension
196
196
  - test/fixtures/pd.png
197
197
  - test/fixtures/ssrf.png
198
+ - test/fixtures/test.gif
198
199
  - test/fixtures/test.jpg
199
200
  - test/fixtures/test.js
200
201
  - test/fixtures/wrongextension.png
@@ -246,6 +247,7 @@ test_files:
246
247
  - test/fixtures/noextension
247
248
  - test/fixtures/pd.png
248
249
  - test/fixtures/ssrf.png
250
+ - test/fixtures/test.gif
249
251
  - test/fixtures/test.jpg
250
252
  - test/fixtures/test.js
251
253
  - test/fixtures/wrongextension.png