bulldog 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/lib/bulldog/attachment/base.rb +3 -6
- data/lib/bulldog/attachment/has_dimensions.rb +43 -34
- data/lib/bulldog/attachment/image.rb +5 -26
- data/lib/bulldog/attachment/pdf.rb +3 -28
- data/lib/bulldog/attachment/video.rb +48 -45
- data/lib/bulldog/style.rb +28 -1
- data/lib/bulldog/version.rb +1 -1
- data/spec/data/3-bytes.txt +1 -0
- data/spec/data/4-bytes.txt +1 -0
- data/spec/data/5-bytes.txt +1 -0
- data/spec/data/6-bytes.txt +1 -0
- data/spec/data/test-20x10.jpg +0 -0
- data/spec/data/test-20x10.pdf +0 -0
- data/spec/data/test-20x10x1.mov +0 -0
- data/spec/data/test-40x30.jpg +0 -0
- data/spec/data/test-40x30.pdf +0 -0
- data/spec/data/test-40x30x1.mov +0 -0
- data/spec/helpers/files.rb +123 -0
- data/spec/integration/lifecycle_hooks_spec.rb +1 -1
- data/spec/integration/processing_image_attachments.rb +1 -13
- data/spec/macros/attachment/has_dimensions_spec.rb +313 -0
- data/spec/spec_helper.rb +3 -4
- data/spec/unit/attachment/base_spec.rb +25 -45
- data/spec/unit/attachment/image_spec.rb +48 -171
- data/spec/unit/attachment/maybe_spec.rb +4 -12
- data/spec/unit/attachment/pdf_spec.rb +18 -136
- data/spec/unit/attachment/video_spec.rb +98 -170
- data/spec/unit/attachment_spec.rb +1 -1
- data/spec/unit/has_attachment_spec.rb +29 -26
- data/spec/unit/interpolation_spec.rb +2 -2
- data/spec/unit/processor/ffmpeg_spec.rb +3 -3
- data/spec/unit/processor/image_magick_spec.rb +1 -1
- data/spec/unit/processor/one_shot_spec.rb +1 -1
- data/spec/unit/stream_spec.rb +3 -3
- data/spec/unit/style_spec.rb +40 -0
- data/spec/unit/validations_spec.rb +33 -33
- metadata +28 -8
- data/spec/helpers/temporary_directory.rb +0 -25
- data/spec/helpers/test_upload_files.rb +0 -108
@@ -13,9 +13,8 @@ describe HasAttachment do
|
|
13
13
|
it "should provide a query method for the attachment" do
|
14
14
|
Thing.has_attachment :photo
|
15
15
|
thing = Thing.new
|
16
|
-
file = uploaded_file
|
17
16
|
thing.photo?.should be_false
|
18
|
-
thing.photo =
|
17
|
+
thing.photo = uploaded_file('test.jpg')
|
19
18
|
thing.photo?.should be_true
|
20
19
|
end
|
21
20
|
|
@@ -71,7 +70,7 @@ describe HasAttachment do
|
|
71
70
|
style :normal
|
72
71
|
process(:on => :my_event){calls << 1}
|
73
72
|
end
|
74
|
-
thing = Thing.new(:photo => uploaded_file)
|
73
|
+
thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
75
74
|
thing.process_attachment(:photo, :my_event)
|
76
75
|
calls.should == [1]
|
77
76
|
end
|
@@ -108,7 +107,7 @@ describe HasAttachment do
|
|
108
107
|
style :normal
|
109
108
|
process(:on => :my_event, :with => :test){context = self}
|
110
109
|
end
|
111
|
-
thing = Thing.new(:photo => uploaded_file)
|
110
|
+
thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
112
111
|
thing.process_attachment(:photo, :my_event)
|
113
112
|
context.should be_a(Processor::Test)
|
114
113
|
end
|
@@ -120,13 +119,17 @@ describe HasAttachment do
|
|
120
119
|
style :normal
|
121
120
|
process(:on => :my_event){context = self}
|
122
121
|
end
|
123
|
-
thing = Thing.new(:photo => uploaded_file)
|
122
|
+
thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
124
123
|
thing.process_attachment(:photo, :my_event)
|
125
124
|
context.should be_a(Processor::Base)
|
126
125
|
end
|
127
126
|
end
|
128
127
|
|
129
128
|
describe "object lifecycle" do
|
129
|
+
def test_image_file
|
130
|
+
uploaded_file('test.jpg')
|
131
|
+
end
|
132
|
+
|
130
133
|
outline "building a record" do
|
131
134
|
with_model_class :Thing do
|
132
135
|
spec = self
|
@@ -200,7 +203,7 @@ describe HasAttachment do
|
|
200
203
|
use_model_class(:Thing)
|
201
204
|
|
202
205
|
before do
|
203
|
-
@file = uploaded_file('test.jpg'
|
206
|
+
@file = uploaded_file('test.jpg')
|
204
207
|
end
|
205
208
|
|
206
209
|
def configure(&block)
|
@@ -295,7 +298,7 @@ describe HasAttachment do
|
|
295
298
|
describe "when the record already exists" do
|
296
299
|
describe "when a file name is set, and the original file exists" do
|
297
300
|
def instantiate
|
298
|
-
file = uploaded_file('test.jpg'
|
301
|
+
file = uploaded_file('test.jpg')
|
299
302
|
thing = Thing.create(:photo => file)
|
300
303
|
@thing = Thing.find(thing.id)
|
301
304
|
end
|
@@ -304,7 +307,7 @@ describe HasAttachment do
|
|
304
307
|
instantiate
|
305
308
|
@thing.photo_file_name.should == 'test.jpg'
|
306
309
|
@thing.photo_content_type.split(/;/).first.should == "image/jpeg"
|
307
|
-
@thing.photo_file_size.should == File.size(
|
310
|
+
@thing.photo_file_size.should == File.size("#{ROOT}/spec/data/test.jpg")
|
308
311
|
end
|
309
312
|
end
|
310
313
|
|
@@ -323,7 +326,7 @@ describe HasAttachment do
|
|
323
326
|
|
324
327
|
describe "when a file name is set, but the original file is missing" do
|
325
328
|
def instantiate
|
326
|
-
file = uploaded_file('test.jpg'
|
329
|
+
file = uploaded_file('test.jpg')
|
327
330
|
@thing = Thing.create(:photo => file)
|
328
331
|
File.unlink(original_path)
|
329
332
|
@thing = Thing.find(@thing.id)
|
@@ -333,7 +336,7 @@ describe HasAttachment do
|
|
333
336
|
instantiate
|
334
337
|
@thing.photo_file_name.should == 'test.jpg'
|
335
338
|
@thing.photo_content_type == "image/jpeg"
|
336
|
-
@thing.photo_file_size.should == File.size(
|
339
|
+
@thing.photo_file_size.should == File.size("#{ROOT}/spec/data/test.jpg")
|
337
340
|
end
|
338
341
|
|
339
342
|
describe "when the record is saved" do
|
@@ -357,14 +360,14 @@ describe HasAttachment do
|
|
357
360
|
|
358
361
|
describe "when an attachment is assigned" do
|
359
362
|
before do
|
360
|
-
@file = uploaded_file('test.jpg'
|
363
|
+
@file = uploaded_file('test.jpg')
|
361
364
|
end
|
362
365
|
|
363
366
|
it "should set the stored attributes" do
|
364
367
|
@thing.photo = @file
|
365
368
|
@thing.photo_file_name.should == 'test.jpg'
|
366
369
|
@thing.photo_content_type.split(/;/).first.should == "image/jpeg"
|
367
|
-
@thing.photo_file_size.should == File.size(
|
370
|
+
@thing.photo_file_size.should == File.size("#{ROOT}/spec/data/test.jpg")
|
368
371
|
end
|
369
372
|
|
370
373
|
it "should not create the original file" do
|
@@ -389,7 +392,7 @@ describe HasAttachment do
|
|
389
392
|
|
390
393
|
describe "when the record exists and there is an attachment" do
|
391
394
|
before do
|
392
|
-
@old_file =
|
395
|
+
@old_file = uploaded_file('test.jpg')
|
393
396
|
thing = Thing.create(:photo => @old_file)
|
394
397
|
@thing = Thing.find(thing.id)
|
395
398
|
end
|
@@ -406,14 +409,14 @@ describe HasAttachment do
|
|
406
409
|
|
407
410
|
describe "when a new attachment is assigned" do
|
408
411
|
before do
|
409
|
-
@new_file =
|
412
|
+
@new_file = uploaded_file('test.png')
|
410
413
|
end
|
411
414
|
|
412
415
|
it "should set the stored attributes" do
|
413
416
|
@thing.photo = @new_file
|
414
417
|
@thing.photo_file_name.should == 'test.png'
|
415
418
|
@thing.photo_content_type.split(/;/).first.should == 'image/png'
|
416
|
-
@thing.photo_file_size.should == File.size(
|
419
|
+
@thing.photo_file_size.should == File.size("#{ROOT}/spec/data/test.png")
|
417
420
|
end
|
418
421
|
|
419
422
|
it "should not create the new original file yet" do
|
@@ -499,7 +502,7 @@ describe HasAttachment do
|
|
499
502
|
describe "#destroy" do
|
500
503
|
describe "when the record is new" do
|
501
504
|
before do
|
502
|
-
file = uploaded_file('test.jpg'
|
505
|
+
file = uploaded_file('test.jpg')
|
503
506
|
@thing = Thing.new(:photo => file)
|
504
507
|
end
|
505
508
|
|
@@ -526,7 +529,7 @@ describe HasAttachment do
|
|
526
529
|
|
527
530
|
describe "when the record existed and had an attachment" do
|
528
531
|
before do
|
529
|
-
file = uploaded_file('test.jpg'
|
532
|
+
file = uploaded_file('test.jpg')
|
530
533
|
thing = Thing.create(:photo => file)
|
531
534
|
@thing = Thing.find(thing.id)
|
532
535
|
end
|
@@ -567,7 +570,7 @@ describe HasAttachment do
|
|
567
570
|
Thing.has_attachment :photo do
|
568
571
|
path "#{spec.temporary_directory}/:id.jpg"
|
569
572
|
end
|
570
|
-
thing = Thing.create(:name => 'old', :photo => uploaded_file)
|
573
|
+
thing = Thing.create(:name => 'old', :photo => uploaded_file('test.jpg'))
|
571
574
|
@thing = Thing.find(thing.id)
|
572
575
|
end
|
573
576
|
|
@@ -586,7 +589,7 @@ describe HasAttachment do
|
|
586
589
|
end
|
587
590
|
|
588
591
|
it "should return true if a new value has been assigned to the attachment" do
|
589
|
-
@thing.photo = uploaded_file
|
592
|
+
@thing.photo = uploaded_file('test.jpg')
|
590
593
|
@thing.photo_changed?.should be_true
|
591
594
|
end
|
592
595
|
end
|
@@ -599,7 +602,7 @@ describe HasAttachment do
|
|
599
602
|
|
600
603
|
it "should return a clone of the original value after assignment" do
|
601
604
|
original_photo = @thing.photo
|
602
|
-
@thing.photo = uploaded_file
|
605
|
+
@thing.photo = uploaded_file('test.jpg')
|
603
606
|
@thing.photo_was.should_not equal(original_photo)
|
604
607
|
@thing.photo_was.should == original_photo
|
605
608
|
end
|
@@ -609,7 +612,7 @@ describe HasAttachment do
|
|
609
612
|
it "should return attachment changes along with other attribute changes" do
|
610
613
|
old_photo = @thing.photo
|
611
614
|
@thing.name = 'new'
|
612
|
-
@thing.photo = uploaded_file
|
615
|
+
@thing.photo = uploaded_file('test.jpg')
|
613
616
|
@thing.changes.should == {
|
614
617
|
'name' => ['old', 'new'],
|
615
618
|
'photo' => [old_photo, @thing.photo],
|
@@ -619,7 +622,7 @@ describe HasAttachment do
|
|
619
622
|
|
620
623
|
describe "when the record is saved and only attachments have been modified" do
|
621
624
|
before do
|
622
|
-
@thing.photo = uploaded_file
|
625
|
+
@thing.photo = uploaded_file('test.jpg')
|
623
626
|
end
|
624
627
|
|
625
628
|
it "should not hit the database"
|
@@ -634,7 +637,7 @@ describe HasAttachment do
|
|
634
637
|
describe "#save" do
|
635
638
|
before do
|
636
639
|
@thing.name = 'new'
|
637
|
-
@thing.photo = uploaded_file
|
640
|
+
@thing.photo = uploaded_file('test.jpg')
|
638
641
|
end
|
639
642
|
|
640
643
|
it "should clear all changes" do
|
@@ -674,7 +677,7 @@ describe HasAttachment do
|
|
674
677
|
|
675
678
|
describe "when a file was assigned to the attachment" do
|
676
679
|
it "should update ATTACHMENT_updated_at" do
|
677
|
-
@thing.photo = uploaded_file
|
680
|
+
@thing.photo = uploaded_file('test.jpg')
|
678
681
|
@thing.save.should be_true
|
679
682
|
@thing.photo_updated_at.should == Time.now
|
680
683
|
end
|
@@ -683,7 +686,7 @@ describe HasAttachment do
|
|
683
686
|
|
684
687
|
describe "when the record already exists" do
|
685
688
|
before do
|
686
|
-
thing = Thing.create(:photo => uploaded_file('test.jpg'
|
689
|
+
thing = Thing.create(:photo => uploaded_file('test.jpg'))
|
687
690
|
@thing = Thing.find(thing.id)
|
688
691
|
end
|
689
692
|
|
@@ -699,7 +702,7 @@ describe HasAttachment do
|
|
699
702
|
describe "when a new file was assigned to the attachment" do
|
700
703
|
it "should update ATTACHMENT_updated_at" do
|
701
704
|
warp_ahead 1.minute
|
702
|
-
@thing.photo = uploaded_file('test.jpg'
|
705
|
+
@thing.photo = uploaded_file('test.jpg')
|
703
706
|
@thing.save.should be_true
|
704
707
|
@thing.photo_updated_at.should == Time.now
|
705
708
|
end
|
@@ -43,7 +43,7 @@ describe Interpolation do
|
|
43
43
|
style :small
|
44
44
|
store_attributes :file_name => nil
|
45
45
|
end
|
46
|
-
@thing = Thing.new(:photo =>
|
46
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
47
47
|
@style = Thing.attachment_reflections[:photo].styles[:small]
|
48
48
|
end
|
49
49
|
|
@@ -132,7 +132,7 @@ describe Interpolation do
|
|
132
132
|
store_attributes :file_name => :photo_file_name
|
133
133
|
end
|
134
134
|
|
135
|
-
@thing = Thing.new(:photo =>
|
135
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
136
136
|
@style = Thing.attachment_reflections[:photo].styles[:small]
|
137
137
|
end
|
138
138
|
|
@@ -17,7 +17,7 @@ describe Processor::Ffmpeg do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
thing = Thing.create(:video =>
|
20
|
+
thing = Thing.create(:video => uploaded_file('test.mov'))
|
21
21
|
@thing = Thing.find(thing.id)
|
22
22
|
end
|
23
23
|
|
@@ -187,9 +187,9 @@ describe Processor::Ffmpeg do
|
|
187
187
|
|
188
188
|
describe "when the frame attachment already exists" do
|
189
189
|
before do
|
190
|
-
thing = Thing.create(:frame =>
|
190
|
+
thing = Thing.create(:frame => uploaded_file('test.jpg'))
|
191
191
|
@thing = Thing.find(thing.id)
|
192
|
-
@thing.video =
|
192
|
+
@thing.video = uploaded_file('test.mov')
|
193
193
|
@thing.video.stubs(:duration).returns(1)
|
194
194
|
end
|
195
195
|
|
@@ -8,7 +8,7 @@ describe Processor::ImageMagick do
|
|
8
8
|
Thing.has_attachment :attachment do
|
9
9
|
path "#{spec.temporary_directory}/attachment.:style.:extension"
|
10
10
|
end
|
11
|
-
thing = Thing.create(:attachment =>
|
11
|
+
thing = Thing.create(:attachment => uploaded_file('test.jpg'))
|
12
12
|
@thing = Thing.find(thing.id)
|
13
13
|
end
|
14
14
|
|
data/spec/unit/stream_spec.rb
CHANGED
@@ -93,8 +93,8 @@ describe Stream do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should make #content_type return the new content type of the file" do
|
96
|
-
jpg_data = File.read(
|
97
|
-
png_data = File.read(
|
96
|
+
jpg_data = File.read("#{ROOT}/spec/data/test.jpg")
|
97
|
+
png_data = File.read("#{ROOT}/spec/data/test.png")
|
98
98
|
stream = stream(jpg_data)
|
99
99
|
stream.content_type.should =~ %r'\Aimage/jpeg'
|
100
100
|
update_target(stream, png_data)
|
@@ -109,7 +109,7 @@ describe Stream do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should not change the result of #content_type" do
|
112
|
-
jpg_data = File.read(
|
112
|
+
jpg_data = File.read("#{ROOT}/spec/data/test.jpg")
|
113
113
|
stream = stream(jpg_data)
|
114
114
|
stream.reload
|
115
115
|
stream.content_type.should =~ %r'\Aimage/jpeg'
|
data/spec/unit/style_spec.rb
CHANGED
@@ -48,4 +48,44 @@ describe Style do
|
|
48
48
|
style.inspect.should == "#<Style :big {:size=>\"100x100\"}>"
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
describe "#dimensions" do
|
53
|
+
it "should return nil if there is no :size attribute" do
|
54
|
+
style = Style.new(:dimensionless)
|
55
|
+
style.dimensions.should be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return the value parsed from the :size attribute" do
|
59
|
+
style = Style.new(:dimensionless, :size => '40x30')
|
60
|
+
style.dimensions.should == [40, 30]
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "when the :size attribute is updated" do
|
64
|
+
before do
|
65
|
+
@style = Style.new(:dimensionless, :size => '40x30')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return nil if it was set to nil" do
|
69
|
+
@style[:size] = nil
|
70
|
+
@style.dimensions.should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return the value parsed from the new :size attribute" do
|
74
|
+
@style[:size] = '80x60'
|
75
|
+
@style.dimensions.should == [80, 60]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#filled?" do
|
81
|
+
it "should return true if the :filled attribute is true" do
|
82
|
+
style = Style.new(:filled, :filled => true)
|
83
|
+
style.should be_filled
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return false if the :filled attribute is omitted" do
|
87
|
+
style = Style.new(:unfilled)
|
88
|
+
style.should_not be_filled
|
89
|
+
end
|
90
|
+
end
|
51
91
|
end
|
@@ -194,11 +194,11 @@ describe Validations do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
def make_thing_pass
|
197
|
-
@thing.photo =
|
197
|
+
@thing.photo = uploaded_file('test.jpg')
|
198
198
|
end
|
199
199
|
|
200
200
|
def make_thing_fail
|
201
|
-
@thing.photo =
|
201
|
+
@thing.photo = uploaded_file('empty.txt')
|
202
202
|
end
|
203
203
|
|
204
204
|
it_should_behave_like "an ActiveRecord validation"
|
@@ -212,18 +212,18 @@ describe Validations do
|
|
212
212
|
|
213
213
|
it "should fail if the file is empty" do
|
214
214
|
Thing.validates_attachment_presence_of :photo
|
215
|
-
@thing = Thing.new(:photo =>
|
215
|
+
@thing = Thing.new(:photo => uploaded_file('empty.txt'))
|
216
216
|
@thing.should_not be_valid
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should pass if the file is not empty" do
|
220
220
|
Thing.validates_attachment_presence_of :photo
|
221
|
-
@thing = Thing.new(:photo =>
|
221
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
222
222
|
@thing.should be_valid
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
-
it_should_use_i18n_key(:attachment_blank){@thing.photo =
|
226
|
+
it_should_use_i18n_key(:attachment_blank){@thing.photo = uploaded_file('empty.txt')}
|
227
227
|
end
|
228
228
|
|
229
229
|
describe ".validates_attachment_file_size_of" do
|
@@ -236,11 +236,11 @@ describe Validations do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
def make_thing_pass
|
239
|
-
@thing.photo =
|
239
|
+
@thing.photo = uploaded_file('4-bytes.txt')
|
240
240
|
end
|
241
241
|
|
242
242
|
def make_thing_fail
|
243
|
-
@thing.photo =
|
243
|
+
@thing.photo = uploaded_file('6-bytes.txt')
|
244
244
|
end
|
245
245
|
|
246
246
|
it_should_behave_like "an ActiveRecord validation"
|
@@ -259,17 +259,17 @@ describe Validations do
|
|
259
259
|
end
|
260
260
|
|
261
261
|
it "should fail if the file size is less than the limit" do
|
262
|
-
@thing.photo =
|
262
|
+
@thing.photo = uploaded_file('4-bytes.txt')
|
263
263
|
@thing.should_not be_valid
|
264
264
|
end
|
265
265
|
|
266
266
|
it "should fail if the file size is equal to the limit" do
|
267
|
-
@thing.photo =
|
267
|
+
@thing.photo = uploaded_file('5-bytes.txt')
|
268
268
|
@thing.should_not be_valid
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should pass if the file size is greater than the limit" do
|
272
|
-
@thing.photo =
|
272
|
+
@thing.photo = uploaded_file('6-bytes.txt')
|
273
273
|
@thing.should be_valid
|
274
274
|
end
|
275
275
|
end
|
@@ -281,72 +281,72 @@ describe Validations do
|
|
281
281
|
end
|
282
282
|
|
283
283
|
it "should fail if the file size is greater than the limit" do
|
284
|
-
@thing.photo =
|
284
|
+
@thing.photo = uploaded_file('6-bytes.txt')
|
285
285
|
@thing.should_not be_valid
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should fail if the file size is equal to the limit" do
|
289
|
-
@thing.photo =
|
289
|
+
@thing.photo = uploaded_file('5-bytes.txt')
|
290
290
|
@thing.should_not be_valid
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should pass if the file size is less than the limit" do
|
294
|
-
@thing.photo =
|
294
|
+
@thing.photo = uploaded_file('4-bytes.txt')
|
295
295
|
@thing.should be_valid
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
299
|
describe "when :in is given" do
|
300
300
|
before do
|
301
|
-
Thing.validates_attachment_file_size_of :photo, :in =>
|
301
|
+
Thing.validates_attachment_file_size_of :photo, :in => 4..5
|
302
302
|
@thing = Thing.new
|
303
303
|
end
|
304
304
|
|
305
305
|
it "should fail if the file size is less than the lower bound" do
|
306
|
-
@thing.photo =
|
306
|
+
@thing.photo = uploaded_file('3-bytes.txt')
|
307
307
|
@thing.should_not be_valid
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should pass if the file size is equal to the lower bound" do
|
311
|
-
@thing.photo =
|
311
|
+
@thing.photo = uploaded_file('4-bytes.txt')
|
312
312
|
@thing.should be_valid
|
313
313
|
end
|
314
314
|
|
315
315
|
it "should fail if the file size is greater than the upper bound" do
|
316
|
-
@thing.photo =
|
316
|
+
@thing.photo = uploaded_file('6-bytes.txt')
|
317
317
|
@thing.should_not be_valid
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
321
|
describe "when :in is given with an inclusive range" do
|
322
322
|
before do
|
323
|
-
Thing.validates_attachment_file_size_of :photo, :in =>
|
323
|
+
Thing.validates_attachment_file_size_of :photo, :in => 4..5
|
324
324
|
@thing = Thing.new
|
325
325
|
end
|
326
326
|
|
327
327
|
it "should pass if the file size is equal to the upper bound" do
|
328
|
-
@thing.photo =
|
328
|
+
@thing.photo = uploaded_file('5-bytes.txt')
|
329
329
|
@thing.should be_valid
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
333
333
|
describe "when :in is given with an exclusive range" do
|
334
334
|
before do
|
335
|
-
Thing.validates_attachment_file_size_of :photo, :in =>
|
335
|
+
Thing.validates_attachment_file_size_of :photo, :in => 4...5
|
336
336
|
@thing = Thing.new
|
337
337
|
end
|
338
338
|
|
339
339
|
it "should fail if the file size is equal to the upper bound" do
|
340
|
-
@thing.photo =
|
340
|
+
@thing.photo = uploaded_file('5-bytes.txt')
|
341
341
|
@thing.should_not be_valid
|
342
342
|
end
|
343
343
|
end
|
344
344
|
end
|
345
345
|
|
346
|
-
it_should_use_i18n_key(:attachment_too_large, :in => 3..5){@thing.photo =
|
347
|
-
it_should_use_i18n_key(:attachment_too_large, :less_than => 5){@thing.photo =
|
348
|
-
it_should_use_i18n_key(:attachment_too_small, :in =>
|
349
|
-
it_should_use_i18n_key(:attachment_too_small, :greater_than => 5){@thing.photo =
|
346
|
+
it_should_use_i18n_key(:attachment_too_large, :in => 3..5){@thing.photo = uploaded_file('6-bytes.txt')}
|
347
|
+
it_should_use_i18n_key(:attachment_too_large, :less_than => 5){@thing.photo = uploaded_file('6-bytes.txt')}
|
348
|
+
it_should_use_i18n_key(:attachment_too_small, :in => 4..5){@thing.photo = uploaded_file('3-bytes.txt')}
|
349
|
+
it_should_use_i18n_key(:attachment_too_small, :greater_than => 5){@thing.photo = uploaded_file('4-bytes.txt')}
|
350
350
|
end
|
351
351
|
|
352
352
|
describe ".validates_attachment_type_of" do
|
@@ -359,11 +359,11 @@ describe Validations do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
def make_thing_pass
|
362
|
-
@thing.photo =
|
362
|
+
@thing.photo = uploaded_file('test.jpg')
|
363
363
|
end
|
364
364
|
|
365
365
|
def make_thing_fail
|
366
|
-
@thing.photo =
|
366
|
+
@thing.photo = uploaded_file('test.mov')
|
367
367
|
end
|
368
368
|
|
369
369
|
it_should_behave_like "an ActiveRecord validation"
|
@@ -372,7 +372,7 @@ describe Validations do
|
|
372
372
|
describe "when :matches is given" do
|
373
373
|
before do
|
374
374
|
Thing.validates_attachment_type_of :photo, :matches => /^image/
|
375
|
-
@thing = Thing.new(:photo => uploaded_file)
|
375
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
376
376
|
end
|
377
377
|
|
378
378
|
it "should pass if the attachment is nil" do
|
@@ -396,16 +396,16 @@ describe Validations do
|
|
396
396
|
describe "when the value is a symbol" do
|
397
397
|
before do
|
398
398
|
Thing.validates_attachment_type_of :photo, :is => :image
|
399
|
-
@thing = Thing.new(:photo => uploaded_file)
|
399
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should pass if the symbol matches the Attachment type" do
|
403
|
-
@thing.photo =
|
403
|
+
@thing.photo = uploaded_file('test.jpg')
|
404
404
|
@thing.should be_valid
|
405
405
|
end
|
406
406
|
|
407
407
|
it "should fail if the symbol does not match the Attachment type" do
|
408
|
-
@thing.photo =
|
408
|
+
@thing.photo = uploaded_file('test.mov')
|
409
409
|
@thing.should_not be_valid
|
410
410
|
@thing.errors.on(:photo).should_not be_blank
|
411
411
|
end
|
@@ -413,7 +413,7 @@ describe Validations do
|
|
413
413
|
|
414
414
|
describe "when a mime-type string is given" do
|
415
415
|
before do
|
416
|
-
@thing = Thing.new(:photo => uploaded_file)
|
416
|
+
@thing = Thing.new(:photo => uploaded_file('test.jpg'))
|
417
417
|
end
|
418
418
|
|
419
419
|
describe "when the string contains optional parameters" do
|
@@ -486,6 +486,6 @@ describe Validations do
|
|
486
486
|
end
|
487
487
|
end
|
488
488
|
|
489
|
-
it_should_use_i18n_key(:attachment_wrong_type, :matches => /\Aimage/){@thing.photo =
|
489
|
+
it_should_use_i18n_key(:attachment_wrong_type, :matches => /\Aimage/){@thing.photo = uploaded_file('test.mov')}
|
490
490
|
end
|
491
491
|
end
|