file_column_with_s3 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README +4 -2
- data/Rakefile +0 -2
- data/lib/file_column.rb +2 -10
- data/lib/file_column/validations.rb +9 -47
- data/lib/file_column_helper.rb +0 -66
- data/lib/rails_file_column.rb +1 -1
- data/test/abstract_unit.rb +14 -8
- data/test/connection.rb +1 -1
- data/test/file_column_helper_test.rb +9 -5
- data/test/file_column_test.rb +30 -33
- data/test/fixtures/entry.rb +5 -8
- metadata +36 -52
- data/lib/magick_file_column.rb +0 -265
- data/test/magick_test.rb +0 -383
- data/test/magick_view_only_test.rb +0 -21
data/test/magick_test.rb
DELETED
@@ -1,383 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require File.dirname(__FILE__) + '/abstract_unit'
|
3
|
-
require File.dirname(__FILE__) + '/fixtures/entry'
|
4
|
-
|
5
|
-
class AbstractRMagickTest < Test::Unit::TestCase
|
6
|
-
def teardown
|
7
|
-
FileUtils.rm_rf File.dirname(__FILE__)+"/public/entry/"
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_truth
|
11
|
-
assert true
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def read_image(path)
|
17
|
-
Magick::Image::read(path).first
|
18
|
-
end
|
19
|
-
|
20
|
-
def assert_max_image_size(img, s)
|
21
|
-
assert img.columns <= s, "img has #{img.columns} columns, expected: #{s}"
|
22
|
-
assert img.rows <= s, "img has #{img.rows} rows, expected: #{s}"
|
23
|
-
assert_equal s, [img.columns, img.rows].max
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class RMagickSimpleTest < AbstractRMagickTest
|
28
|
-
def setup
|
29
|
-
Entry.file_column :image, :magick => { :geometry => "100x100" }
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_simple_resize_without_save
|
33
|
-
e = Entry.new
|
34
|
-
e.image = upload(f("kerb.jpg"))
|
35
|
-
|
36
|
-
img = read_image(e.image)
|
37
|
-
assert_max_image_size img, 100
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_simple_resize_with_save
|
41
|
-
e = Entry.new
|
42
|
-
e.image = upload(f("kerb.jpg"))
|
43
|
-
assert e.save
|
44
|
-
e.reload
|
45
|
-
|
46
|
-
img = read_image(e.image)
|
47
|
-
assert_max_image_size img, 100
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_resize_on_saved_image
|
51
|
-
Entry.file_column :image, :magick => { :geometry => "100x100" }
|
52
|
-
|
53
|
-
e = Entry.new
|
54
|
-
e.image = upload(f("skanthak.png"))
|
55
|
-
assert e.save
|
56
|
-
e.reload
|
57
|
-
old_path = e.image
|
58
|
-
|
59
|
-
e.image = upload(f("kerb.jpg"))
|
60
|
-
assert e.save
|
61
|
-
assert "kerb.jpg", File.basename(e.image)
|
62
|
-
assert !File.exists?(old_path), "old image '#{old_path}' still exists"
|
63
|
-
|
64
|
-
img = read_image(e.image)
|
65
|
-
assert_max_image_size img, 100
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_invalid_image
|
69
|
-
e = Entry.new
|
70
|
-
assert_nothing_raised { e.image = upload(f("invalid-image.jpg")) }
|
71
|
-
assert !e.valid?
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_serializable
|
75
|
-
e = Entry.new
|
76
|
-
e.image = upload(f("skanthak.png"))
|
77
|
-
assert_nothing_raised {
|
78
|
-
flash = Marshal.dump(e)
|
79
|
-
e = Marshal.load(flash)
|
80
|
-
}
|
81
|
-
assert File.exists?(e.image)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_imagemagick_still_usable
|
85
|
-
assert_nothing_raised {
|
86
|
-
img = Magick::Image::read(file_path("skanthak.png")).first
|
87
|
-
assert img.kind_of?(Magick::Image)
|
88
|
-
}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class RMagickRequiresImageTest < AbstractRMagickTest
|
93
|
-
def setup
|
94
|
-
Entry.file_column :image, :magick => {
|
95
|
-
:size => "100x100>",
|
96
|
-
:image_required => false,
|
97
|
-
:versions => {
|
98
|
-
:thumb => "80x80>",
|
99
|
-
:large => {:size => "200x200>", :lazy => true}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_image_required_with_image
|
105
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
106
|
-
assert_max_image_size read_image(e.image), 100
|
107
|
-
assert e.valid?
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_image_required_with_invalid_image
|
111
|
-
e = Entry.new(:image => upload(f("invalid-image.jpg")))
|
112
|
-
assert e.valid?, "did not ignore invalid image"
|
113
|
-
assert FileUtils.identical?(e.image, f("invalid-image.jpg")), "uploaded file has not been left alone"
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_versions_with_invalid_image
|
117
|
-
e = Entry.new(:image => upload(f("invalid-image.jpg")))
|
118
|
-
assert e.valid?
|
119
|
-
|
120
|
-
image_state = e.send(:image_state)
|
121
|
-
assert_nil image_state.create_magick_version_if_needed(:thumb)
|
122
|
-
assert_nil image_state.create_magick_version_if_needed(:large)
|
123
|
-
assert_nil image_state.create_magick_version_if_needed("300x300>")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class RMagickCustomAttributesTest < AbstractRMagickTest
|
128
|
-
def assert_image_property(img, property, value, text = nil)
|
129
|
-
assert File.exists?(img), "the image does not exist"
|
130
|
-
assert_equal value, read_image(img).send(property), text
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_simple_attributes
|
134
|
-
Entry.file_column :image, :magick => { :attributes => { :quality => 20 } }
|
135
|
-
e = Entry.new("image" => upload(f("kerb.jpg")))
|
136
|
-
assert_image_property e.image, :quality, 20, "the quality was not set"
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_version_attributes
|
140
|
-
Entry.file_column :image, :magick => {
|
141
|
-
:versions => {
|
142
|
-
:thumb => { :attributes => { :quality => 20 } }
|
143
|
-
}
|
144
|
-
}
|
145
|
-
e = Entry.new("image" => upload(f("kerb.jpg")))
|
146
|
-
assert_image_property e.image("thumb"), :quality, 20, "the quality was not set"
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_lazy_attributes
|
150
|
-
Entry.file_column :image, :magick => {
|
151
|
-
:versions => {
|
152
|
-
:thumb => { :attributes => { :quality => 20 }, :lazy => true }
|
153
|
-
}
|
154
|
-
}
|
155
|
-
e = Entry.new("image" => upload(f("kerb.jpg")))
|
156
|
-
e.send(:image_state).create_magick_version_if_needed(:thumb)
|
157
|
-
assert_image_property e.image("thumb"), :quality, 20, "the quality was not set"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
class RMagickVersionsTest < AbstractRMagickTest
|
162
|
-
def setup
|
163
|
-
Entry.file_column :image, :magick => {:geometry => "200x200",
|
164
|
-
:versions => {
|
165
|
-
:thumb => "50x50",
|
166
|
-
:medium => {:geometry => "100x100", :name => "100_100"},
|
167
|
-
:large => {:geometry => "150x150", :lazy => true}
|
168
|
-
}
|
169
|
-
}
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
def test_should_create_thumb
|
174
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
175
|
-
|
176
|
-
assert File.exists?(e.image("thumb")), "thumb-nail not created"
|
177
|
-
|
178
|
-
assert_max_image_size read_image(e.image("thumb")), 50
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_version_name_can_be_different_from_key
|
182
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
183
|
-
|
184
|
-
assert File.exists?(e.image("100_100"))
|
185
|
-
assert !File.exists?(e.image("medium"))
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_should_not_create_lazy_versions
|
189
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
190
|
-
assert !File.exists?(e.image("large")), "lazy versions should not be created unless needed"
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_should_create_lazy_version_on_demand
|
194
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
195
|
-
|
196
|
-
e.send(:image_state).create_magick_version_if_needed(:large)
|
197
|
-
|
198
|
-
assert File.exists?(e.image("large")), "lazy version should be created on demand"
|
199
|
-
|
200
|
-
assert_max_image_size read_image(e.image("large")), 150
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_generated_name_should_not_change
|
204
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
205
|
-
|
206
|
-
name1 = e.send(:image_state).create_magick_version_if_needed("50x50")
|
207
|
-
name2 = e.send(:image_state).create_magick_version_if_needed("50x50")
|
208
|
-
name3 = e.send(:image_state).create_magick_version_if_needed(:geometry => "50x50")
|
209
|
-
assert_equal name1, name2, "hash value has changed"
|
210
|
-
assert_equal name1, name3, "hash value has changed"
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_should_create_version_with_string
|
214
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
215
|
-
|
216
|
-
name = e.send(:image_state).create_magick_version_if_needed("32x32")
|
217
|
-
|
218
|
-
assert File.exists?(e.image(name))
|
219
|
-
|
220
|
-
assert_max_image_size read_image(e.image(name)), 32
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_should_create_safe_auto_id
|
224
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
225
|
-
|
226
|
-
name = e.send(:image_state).create_magick_version_if_needed("32x32")
|
227
|
-
|
228
|
-
assert_match /^[a-zA-Z0-9]+$/, name
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
class RMagickCroppingTest < AbstractRMagickTest
|
233
|
-
def setup
|
234
|
-
Entry.file_column :image, :magick => {:geometry => "200x200",
|
235
|
-
:versions => {
|
236
|
-
:thumb => {:crop => "1:1", :geometry => "50x50"}
|
237
|
-
}
|
238
|
-
}
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_should_crop_image_on_upload
|
242
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
243
|
-
|
244
|
-
img = read_image(e.image("thumb"))
|
245
|
-
|
246
|
-
assert_equal 50, img.rows
|
247
|
-
assert_equal 50, img.columns
|
248
|
-
end
|
249
|
-
|
250
|
-
end
|
251
|
-
|
252
|
-
class UrlForImageColumnTest < AbstractRMagickTest
|
253
|
-
include FileColumnHelper
|
254
|
-
|
255
|
-
def setup
|
256
|
-
Entry.file_column :image, :magick => {
|
257
|
-
:versions => {:thumb => "50x50"}
|
258
|
-
}
|
259
|
-
@request = RequestMock.new
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_should_use_version_on_symbol_option
|
263
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
264
|
-
|
265
|
-
url = url_for_image_column(e, "image", :thumb)
|
266
|
-
assert_match %r{^/entry/image/tmp/.+/thumb/skanthak.png$}, url
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_should_use_string_as_size
|
270
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
271
|
-
|
272
|
-
url = url_for_image_column(e, "image", "50x50")
|
273
|
-
|
274
|
-
assert_match %r{^/entry/image/tmp/.+/.+/skanthak.png$}, url
|
275
|
-
|
276
|
-
url =~ /\/([^\/]+)\/skanthak.png$/
|
277
|
-
dirname = $1
|
278
|
-
|
279
|
-
assert_max_image_size read_image(e.image(dirname)), 50
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_should_accept_version_hash
|
283
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
284
|
-
|
285
|
-
url = url_for_image_column(e, "image", :size => "50x50", :crop => "1:1", :name => "small")
|
286
|
-
|
287
|
-
assert_match %r{^/entry/image/tmp/.+/small/skanthak.png$}, url
|
288
|
-
|
289
|
-
img = read_image(e.image("small"))
|
290
|
-
assert_equal 50, img.rows
|
291
|
-
assert_equal 50, img.columns
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
class RMagickPermissionsTest < AbstractRMagickTest
|
296
|
-
def setup
|
297
|
-
Entry.file_column :image, :magick => {:geometry => "200x200",
|
298
|
-
:versions => {
|
299
|
-
:thumb => {:crop => "1:1", :geometry => "50x50"}
|
300
|
-
}
|
301
|
-
}, :permissions => 0616
|
302
|
-
end
|
303
|
-
|
304
|
-
def check_permissions(e)
|
305
|
-
assert_equal 0616, (File.stat(e.image).mode & 0777)
|
306
|
-
assert_equal 0616, (File.stat(e.image("thumb")).mode & 0777)
|
307
|
-
end
|
308
|
-
|
309
|
-
def test_permissions_with_rmagick
|
310
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
311
|
-
|
312
|
-
check_permissions e
|
313
|
-
|
314
|
-
assert e.save
|
315
|
-
|
316
|
-
check_permissions e
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
class Entry
|
321
|
-
def transform_grey(img)
|
322
|
-
img.quantize(256, Magick::GRAYColorspace)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
class RMagickTransformationTest < AbstractRMagickTest
|
327
|
-
def assert_transformed(image)
|
328
|
-
assert File.exists?(image), "the image does not exist"
|
329
|
-
assert 256 > read_image(image).number_colors, "the number of colors was not changed"
|
330
|
-
end
|
331
|
-
|
332
|
-
def test_simple_transformation
|
333
|
-
Entry.file_column :image, :magick => { :transformation => Proc.new { |image| image.quantize(256, Magick::GRAYColorspace) } }
|
334
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
335
|
-
assert_transformed(e.image)
|
336
|
-
end
|
337
|
-
|
338
|
-
def test_simple_version_transformation
|
339
|
-
Entry.file_column :image, :magick => {
|
340
|
-
:versions => { :thumb => Proc.new { |image| image.quantize(256, Magick::GRAYColorspace) } }
|
341
|
-
}
|
342
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
343
|
-
assert_transformed(e.image("thumb"))
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_complex_version_transformation
|
347
|
-
Entry.file_column :image, :magick => {
|
348
|
-
:versions => {
|
349
|
-
:thumb => { :transformation => Proc.new { |image| image.quantize(256, Magick::GRAYColorspace) } }
|
350
|
-
}
|
351
|
-
}
|
352
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
353
|
-
assert_transformed(e.image("thumb"))
|
354
|
-
end
|
355
|
-
|
356
|
-
def test_lazy_transformation
|
357
|
-
Entry.file_column :image, :magick => {
|
358
|
-
:versions => {
|
359
|
-
:thumb => { :transformation => Proc.new { |image| image.quantize(256, Magick::GRAYColorspace) }, :lazy => true }
|
360
|
-
}
|
361
|
-
}
|
362
|
-
e = Entry.new("image" => upload(f("skanthak.png")))
|
363
|
-
e.send(:image_state).create_magick_version_if_needed(:thumb)
|
364
|
-
assert_transformed(e.image("thumb"))
|
365
|
-
end
|
366
|
-
|
367
|
-
def test_simple_callback_transformation
|
368
|
-
Entry.file_column :image, :magick => :transform_grey
|
369
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
370
|
-
assert_transformed(e.image)
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_complex_callback_transformation
|
374
|
-
Entry.file_column :image, :magick => { :transformation => :transform_grey }
|
375
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
376
|
-
assert_transformed(e.image)
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
rescue LoadError
|
381
|
-
puts "Cannot find RMagick gem"
|
382
|
-
puts "Needs RMagick gem to run these tests and support image thumbnails with file_column"
|
383
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/entry'
|
3
|
-
|
4
|
-
class RMagickViewOnlyTest < Test::Unit::TestCase
|
5
|
-
include FileColumnHelper
|
6
|
-
|
7
|
-
def setup
|
8
|
-
Entry.file_column :image
|
9
|
-
@request = RequestMock.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
FileUtils.rm_rf File.dirname(__FILE__)+"/public/entry/"
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_url_for_image_column_without_model_versions
|
17
|
-
e = Entry.new(:image => upload(f("skanthak.png")))
|
18
|
-
|
19
|
-
assert_nothing_raised { url_for_image_column e, "image", "50x50" }
|
20
|
-
end
|
21
|
-
end
|