uploadcolumn 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/spec/active_record_extension_spec.rb +127 -126
- data/spec/spec_helper.rb +14 -11
- data/spec/uploaded_file_spec.rb +166 -165
- metadata +2 -2
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'tempfile'
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'spec'
|
4
4
|
require 'ruby-debug'
|
5
|
+
require 'action_view'
|
6
|
+
require 'action_controller'
|
5
7
|
|
6
8
|
require File.join(File.dirname(__FILE__), 'custom_matchers')
|
7
9
|
|
@@ -18,10 +20,10 @@ end
|
|
18
20
|
|
19
21
|
def stub_tempfile(filename, mime_type=nil, fake_name=nil)
|
20
22
|
raise "#{path} file does not exist" unless File.exist?(file_path(filename))
|
21
|
-
|
23
|
+
|
22
24
|
t = Tempfile.new(filename)
|
23
25
|
FileUtils.copy_file(file_path(filename), t.path)
|
24
|
-
|
26
|
+
|
25
27
|
t.stub!(:original_filename).and_return(fake_name || filename)
|
26
28
|
t.stub!(:content_type).and_return(mime_type)
|
27
29
|
t.stub!(:local_path).and_return(t.path)
|
@@ -48,43 +50,44 @@ def stub_file(filename, mime_type=nil, fake_name=nil)
|
|
48
50
|
end
|
49
51
|
|
50
52
|
module UploadColumnSpecHelper
|
51
|
-
|
53
|
+
|
52
54
|
def disconnected_model(model_class)
|
53
55
|
model_class.stub!(:columns).and_return([])
|
54
56
|
return model_class.new
|
55
57
|
end
|
56
|
-
|
58
|
+
|
57
59
|
def setup_standard_mocking
|
58
60
|
@options = mock('options', :null_object => true)
|
59
61
|
Entry.upload_column :avatar, @options
|
60
62
|
@entry = disconnected_model(Entry)
|
61
63
|
mock_file
|
62
64
|
end
|
63
|
-
|
65
|
+
|
64
66
|
def setup_version_mocking
|
65
67
|
Entry.upload_column :avatar, :versions => [ :thumb, :large ]
|
66
68
|
@entry = disconnected_model(Entry)
|
67
69
|
mock_file
|
68
70
|
end
|
69
|
-
|
71
|
+
|
70
72
|
private
|
71
|
-
|
73
|
+
|
72
74
|
def mock_file
|
73
75
|
@file = mock('file')
|
74
76
|
|
75
77
|
@uploaded_file = mock('uploaded_file')
|
76
|
-
@uploaded_file.stub!(:actual_filename).and_return('monkey.png')
|
78
|
+
@uploaded_file.stub!(:actual_filename).and_return('monkey.png')
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
82
|
module UniversalSpecHelper
|
81
|
-
|
83
|
+
|
82
84
|
def running(&block)
|
83
85
|
lambda(&block)
|
84
86
|
end
|
85
|
-
|
87
|
+
|
86
88
|
end
|
87
89
|
|
88
90
|
Spec::Runner.configure do |config|
|
89
91
|
config.include UniversalSpecHelper
|
90
|
-
end
|
92
|
+
end
|
93
|
+
|
data/spec/uploaded_file_spec.rb
CHANGED
@@ -38,70 +38,70 @@ describe "all uploaded files", :shared => true do
|
|
38
38
|
it "should return the extension" do
|
39
39
|
@file.extension.should == "jpg"
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
after do
|
43
43
|
FileUtils.rm_rf(public_path('*'))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "an uploaded tempfile" do
|
48
|
-
|
48
|
+
|
49
49
|
before do
|
50
50
|
@file = UploadColumn::UploadedFile.upload(stub_tempfile('kerb.jpg'))
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it_should_behave_like "all uploaded files"
|
54
|
-
|
54
|
+
|
55
55
|
it "should return the correct path" do
|
56
56
|
@file.path.should match_path('public', 'tmp', %r{((\d+\.)+\d+)}, 'kerb.jpg')
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "should return the correct relative_path" do
|
60
60
|
@file.relative_path.should =~ %r{^tmp/((\d+\.)+\d+)/kerb.jpg}
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should return correct dir" do
|
64
64
|
@file.dir.should match_path('public', 'tmp', %r{((\d+\.)+\d+)})
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "an uploaded StringIO" do
|
69
|
-
|
69
|
+
|
70
70
|
before do
|
71
71
|
@file = UploadColumn::UploadedFile.upload(stub_stringio('kerb.jpg'))
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it_should_behave_like "all uploaded files"
|
75
|
-
|
75
|
+
|
76
76
|
it "should return the correct path" do
|
77
77
|
@file.path.should match_path('public', 'tmp', %r{((\d+\.)+\d+)}, 'kerb.jpg')
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
it "should return the correct relative_path" do
|
81
81
|
@file.relative_path.should =~ %r{^tmp/((\d+\.)+\d+)/kerb.jpg}
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it "should return correct dir" do
|
85
85
|
@file.dir.should match_path('public', 'tmp', %r{((\d+\.)+\d+)})
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "an uploaded File object" do
|
90
|
-
|
90
|
+
|
91
91
|
before do
|
92
92
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'))
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it_should_behave_like "all uploaded files"
|
96
|
-
|
96
|
+
|
97
97
|
it "should return the correct path" do
|
98
98
|
@file.path.should match_path('public', 'tmp', %r{((\d+\.)+\d+)}, 'kerb.jpg')
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "should return the correct relative_path" do
|
102
102
|
@file.relative_path.should =~ %r{^tmp/((\d+\.)+\d+)/kerb.jpg}
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should return correct dir" do
|
106
106
|
@file.dir.should match_path('public', 'tmp', %r{((\d+\.)+\d+)})
|
107
107
|
end
|
@@ -116,12 +116,12 @@ describe "an uploaded non-empty String" do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
describe "an uploded empty file" do
|
119
|
-
it "should return nil" do
|
119
|
+
it "should return nil" do
|
120
120
|
file = mock('uploaded empty file')
|
121
121
|
file.should_receive(:empty?).and_return(true)
|
122
122
|
upload = mock('upload')
|
123
123
|
UploadColumn::UploadedFile.should_receive(:new).and_return(file)
|
124
|
-
|
124
|
+
|
125
125
|
UploadColumn::UploadedFile.upload(upload).should == nil
|
126
126
|
end
|
127
127
|
end
|
@@ -130,23 +130,23 @@ describe "an UploadedFile" do
|
|
130
130
|
before do
|
131
131
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, :donkey)
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
it "should have the correct relative store dir" do
|
135
135
|
@file.relative_store_dir.should == 'donkey'
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
it "should have the correct store dir" do
|
139
139
|
@file.store_dir.should == File.expand_path('donkey', PUBLIC)
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
it "should have the correct relative tmp dir" do
|
143
143
|
@file.relative_tmp_dir.should == 'tmp'
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
it "should have the correct tmp dir" do
|
147
147
|
@file.tmp_dir.should == File.expand_path('tmp', PUBLIC)
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
it "should return something sensible on inspect" do
|
151
151
|
@file.inspect.should == "<UploadedFile: #{@file.path}>"
|
152
152
|
end
|
@@ -156,11 +156,11 @@ describe "an UploadedFile where store_dir is a String" do
|
|
156
156
|
before do
|
157
157
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, nil, :store_dir => 'monkey')
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it "should have the correct relative store dir" do
|
161
161
|
@file.relative_store_dir.should == 'monkey'
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
it "should have the correct store dir" do
|
165
165
|
@file.store_dir.should == File.expand_path('monkey', PUBLIC)
|
166
166
|
end
|
@@ -170,11 +170,11 @@ describe "an UploadedFile where tmp_dir is a String" do
|
|
170
170
|
before do
|
171
171
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, nil, :tmp_dir => 'monkey')
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
it "should have the correct relative tmp dir" do
|
175
175
|
@file.relative_tmp_dir.should == 'monkey'
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
it "should have the correct tmp dir" do
|
179
179
|
@file.tmp_dir.should == File.expand_path('monkey', PUBLIC)
|
180
180
|
end
|
@@ -184,15 +184,15 @@ describe "an UploadedFile where filename is a String" do
|
|
184
184
|
before do
|
185
185
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, nil, :filename => 'monkey.png', :versions => [:thumb, :large])
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "should have the correct filename" do
|
189
189
|
@file.filename.should == 'monkey.png'
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
it "should remember the actual filename" do
|
193
193
|
@file.actual_filename.should == "kerb.jpg"
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
it "should have versions with the correct filename" do
|
197
197
|
@file.thumb.filename.should == 'monkey.png'
|
198
198
|
@file.large.filename.should == 'monkey.png'
|
@@ -205,15 +205,15 @@ describe "an UploadedFile where filename is a Proc with the record piped in" do
|
|
205
205
|
record.stub!(:name).and_return('quack')
|
206
206
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :versions => [:thumb, :large], :filename => proc{ |r| r.name })
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
it "should have the correct filename" do
|
210
210
|
@file.filename.should == 'quack'
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
it "should remember the actual filename" do
|
214
214
|
@file.actual_filename.should == "kerb.jpg"
|
215
215
|
end
|
216
|
-
|
216
|
+
|
217
217
|
it "should have versions with the correct filename" do
|
218
218
|
@file.thumb.filename.should == 'quack'
|
219
219
|
@file.large.filename.should == 'quack'
|
@@ -226,15 +226,15 @@ describe "an UploadedFile where filename is a Proc with the record and file pipe
|
|
226
226
|
record.stub!(:name).and_return('quack')
|
227
227
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :versions => [:thumb, :large], :filename => proc{ |r, f| "#{r.name}-#{f.basename}-#{f.suffix}quox.#{f.extension}"})
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
it "should have the correct filename" do
|
231
231
|
@file.filename.should == 'quack-kerb-quox.jpg'
|
232
232
|
end
|
233
|
-
|
233
|
+
|
234
234
|
it "should remember the actual filename" do
|
235
235
|
@file.actual_filename.should == "kerb.jpg"
|
236
236
|
end
|
237
|
-
|
237
|
+
|
238
238
|
it "should have versions with the correct filename" do
|
239
239
|
@file.thumb.filename.should == 'quack-kerb-thumbquox.jpg'
|
240
240
|
@file.large.filename.should == 'quack-kerb-largequox.jpg'
|
@@ -246,16 +246,16 @@ describe "an UploadedFile with a filename callback" do
|
|
246
246
|
@instance = mock('instance with filename callback')
|
247
247
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), @instance, :monkey, :versions => [:thumb, :large])
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
it "should have the correct filename" do
|
251
251
|
@instance.should_receive(:monkey_filename).with(@file).and_return("llama")
|
252
252
|
@file.filename.should == 'llama'
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
it "should remember the actual filename" do
|
256
256
|
@file.actual_filename.should == "kerb.jpg"
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
it "should have versions with the correct filename" do
|
260
260
|
@instance.should_receive(:monkey_filename).with(@file.thumb).and_return("barr")
|
261
261
|
@instance.should_receive(:monkey_filename).with(@file.large).and_return("quox")
|
@@ -270,24 +270,24 @@ describe "uploading an UploadedFile where filename is a Proc" do
|
|
270
270
|
record.stub!(:name).and_return('quack')
|
271
271
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), record, nil, :versions => [:thumb, :large], :filename => proc{ |r, f| "#{r.name}-#{f.basename}-#{f.suffix}quox.#{f.extension}"})
|
272
272
|
end
|
273
|
-
|
273
|
+
|
274
274
|
it "should have the correct filename" do
|
275
275
|
@file.filename.should == 'quack-kerb-quox.jpg'
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
it "should remember the actual filename" do
|
279
279
|
@file.actual_filename.should == "kerb.jpg"
|
280
280
|
end
|
281
|
-
|
281
|
+
|
282
282
|
it "should have versions with the correct filename" do
|
283
283
|
@file.thumb.filename.should == 'quack-kerb-thumbquox.jpg'
|
284
284
|
@file.large.filename.should == 'quack-kerb-largequox.jpg'
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
it "should have a correct path" do
|
288
288
|
@file.path.should match_path(PUBLIC, 'tmp', /(?:\d+\.)+\d+/, 'quack-kerb-quox.jpg' )
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
291
|
it "should have versions with correct paths" do
|
292
292
|
@file.thumb.path.should match_path(PUBLIC, 'tmp', /(?:\d+\.)+\d+/, 'quack-kerb-thumbquox.jpg' )
|
293
293
|
@file.large.path.should match_path(PUBLIC, 'tmp', /(?:\d+\.)+\d+/, 'quack-kerb-largequox.jpg' )
|
@@ -298,11 +298,11 @@ describe "an UploadedFile where store_dir is a simple Proc" do
|
|
298
298
|
before do
|
299
299
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, nil, :store_dir => proc{'monkey'})
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
it "should have the correct relative store dir" do
|
303
303
|
@file.relative_store_dir.should == 'monkey'
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
it "should have the correct store dir" do
|
307
307
|
@file.store_dir.should == File.expand_path('monkey', PUBLIC)
|
308
308
|
end
|
@@ -312,11 +312,11 @@ describe "an UploadedFile where tmp_dir is a simple Proc" do
|
|
312
312
|
before do
|
313
313
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, nil, :tmp_dir => proc{'monkey'})
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
it "should have the correct relative tmp dir" do
|
317
317
|
@file.relative_tmp_dir.should == 'monkey'
|
318
318
|
end
|
319
|
-
|
319
|
+
|
320
320
|
it "should have the correct tmp dir" do
|
321
321
|
@file.tmp_dir.should == File.expand_path('monkey', PUBLIC)
|
322
322
|
end
|
@@ -328,11 +328,11 @@ describe "an UploadedFile where store_dir is a Proc and has the record piped in"
|
|
328
328
|
record.stub!(:name).and_return('quack')
|
329
329
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :store_dir => proc{ |record| File.join(record.name, 'monkey')})
|
330
330
|
end
|
331
|
-
|
331
|
+
|
332
332
|
it "should have the correct relative store dir" do
|
333
333
|
@file.relative_store_dir.should == 'quack/monkey'
|
334
334
|
end
|
335
|
-
|
335
|
+
|
336
336
|
it "should have the correct store dir" do
|
337
337
|
@file.store_dir.should == File.expand_path('quack/monkey', PUBLIC)
|
338
338
|
end
|
@@ -341,14 +341,14 @@ end
|
|
341
341
|
describe "an UploadedFile where tmp_dir is a Proc and has the record piped in" do
|
342
342
|
before do
|
343
343
|
record = mock('a record')
|
344
|
-
record.stub!(:name).and_return('quack')
|
344
|
+
record.stub!(:name).and_return('quack')
|
345
345
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :tmp_dir => proc{ |record| File.join(record.name, 'monkey')})
|
346
346
|
end
|
347
|
-
|
347
|
+
|
348
348
|
it "should have the correct relative tmp dir" do
|
349
349
|
@file.relative_tmp_dir.should == 'quack/monkey'
|
350
350
|
end
|
351
|
-
|
351
|
+
|
352
352
|
it "should have the correct tmp dir" do
|
353
353
|
@file.tmp_dir.should == File.expand_path('quack/monkey', PUBLIC)
|
354
354
|
end
|
@@ -361,11 +361,11 @@ describe "an UploadedFile where store_dir is a Proc and has the record and file
|
|
361
361
|
record.stub!(:name).and_return('quack')
|
362
362
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :store_dir => proc{ |r, f| File.join(record.name, f.basename, 'monkey')})
|
363
363
|
end
|
364
|
-
|
364
|
+
|
365
365
|
it "should have the correct relative store dir" do
|
366
366
|
@file.relative_store_dir.should == 'quack/kerb/monkey'
|
367
367
|
end
|
368
|
-
|
368
|
+
|
369
369
|
it "should have the correct store dir" do
|
370
370
|
@file.store_dir.should == File.expand_path('quack/kerb/monkey', PUBLIC)
|
371
371
|
end
|
@@ -374,14 +374,14 @@ end
|
|
374
374
|
describe "an UploadedFile where tmp_dir is a Proc and has the record and file piped in" do
|
375
375
|
before do
|
376
376
|
record = mock('a record')
|
377
|
-
record.stub!(:name).and_return('quack')
|
377
|
+
record.stub!(:name).and_return('quack')
|
378
378
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), record, nil, :tmp_dir => proc{ |r, f| File.join(record.name, f.basename, 'monkey')})
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
it "should have the correct relative tmp dir" do
|
382
382
|
@file.relative_tmp_dir.should == 'quack/kerb/monkey'
|
383
383
|
end
|
384
|
-
|
384
|
+
|
385
385
|
it "should have the correct tmp dir" do
|
386
386
|
@file.tmp_dir.should == File.expand_path('quack/kerb/monkey', PUBLIC)
|
387
387
|
end
|
@@ -394,11 +394,11 @@ describe "an UploadedFile with a store_dir callback" do
|
|
394
394
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), i, :monkey)
|
395
395
|
i.should_receive(:monkey_store_dir).with(@file).and_return('llama')
|
396
396
|
end
|
397
|
-
|
397
|
+
|
398
398
|
it "should have the correct relative store dir" do
|
399
399
|
@file.relative_store_dir.should == 'llama'
|
400
400
|
end
|
401
|
-
|
401
|
+
|
402
402
|
it "should have the correct store dir" do
|
403
403
|
@file.store_dir.should == File.expand_path('llama', PUBLIC)
|
404
404
|
end
|
@@ -410,11 +410,11 @@ describe "an UploadedFile with a tmp_dir callback" do
|
|
410
410
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), i, :monkey)
|
411
411
|
i.should_receive(:monkey_tmp_dir).with(@file).and_return('gorilla')
|
412
412
|
end
|
413
|
-
|
413
|
+
|
414
414
|
it "should have the correct relative tmp dir" do
|
415
415
|
@file.relative_tmp_dir.should == 'gorilla'
|
416
416
|
end
|
417
|
-
|
417
|
+
|
418
418
|
it "should have the correct tmp dir" do
|
419
419
|
@file.tmp_dir.should == File.expand_path('gorilla', PUBLIC)
|
420
420
|
end
|
@@ -425,46 +425,46 @@ describe "an UploadedFile that has just been uploaded" do
|
|
425
425
|
before do
|
426
426
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :monkey)
|
427
427
|
end
|
428
|
-
|
428
|
+
|
429
429
|
it_should_behave_like "all uploaded files"
|
430
|
-
|
430
|
+
|
431
431
|
it "should be new" do
|
432
432
|
@file.should be_new_file
|
433
433
|
end
|
434
|
-
|
434
|
+
|
435
435
|
it "should be a tempfile" do
|
436
436
|
@file.should be_a_tempfile
|
437
437
|
end
|
438
|
-
|
438
|
+
|
439
439
|
it "should exist" do
|
440
440
|
@file.should be_in_existence
|
441
441
|
end
|
442
|
-
|
442
|
+
|
443
443
|
it "should be stored in tmp" do
|
444
444
|
@file.path.should match_path('public', 'tmp', %r{((\d+\.)+\d+)}, 'kerb.jpg')
|
445
445
|
end
|
446
|
-
|
446
|
+
|
447
447
|
end
|
448
448
|
|
449
449
|
describe "saving an UploadedFile" do
|
450
450
|
before do
|
451
451
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :monkey)
|
452
452
|
end
|
453
|
-
|
453
|
+
|
454
454
|
it "should return true" do
|
455
455
|
@file.send(:save).should === true
|
456
456
|
end
|
457
|
-
|
457
|
+
|
458
458
|
it "should copy the file to the correct location" do
|
459
459
|
@file.send(:save)
|
460
460
|
@file.path.should match_path('public', 'monkey', 'kerb.jpg')
|
461
461
|
@file.should be_in_existence
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
after do
|
465
465
|
FileUtils.rm_rf(PUBLIC)
|
466
466
|
end
|
467
|
-
|
467
|
+
|
468
468
|
end
|
469
469
|
|
470
470
|
describe "a saved UploadedFile" do
|
@@ -472,25 +472,25 @@ describe "a saved UploadedFile" do
|
|
472
472
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :monkey)
|
473
473
|
@file.send(:save)
|
474
474
|
end
|
475
|
-
|
475
|
+
|
476
476
|
it_should_behave_like "all uploaded files"
|
477
|
-
|
477
|
+
|
478
478
|
it "should not be new" do
|
479
479
|
@file.should_not be_new_file
|
480
480
|
end
|
481
|
-
|
481
|
+
|
482
482
|
it "should not be a tempfile" do
|
483
483
|
@file.should_not be_a_tempfile
|
484
484
|
end
|
485
|
-
|
485
|
+
|
486
486
|
it "should return the correct path" do
|
487
487
|
@file.path.should match_path('public', 'monkey', 'kerb.jpg')
|
488
488
|
end
|
489
|
-
|
489
|
+
|
490
490
|
it "should return the correct relative_path" do
|
491
491
|
@file.relative_path.should == "monkey/kerb.jpg"
|
492
492
|
end
|
493
|
-
|
493
|
+
|
494
494
|
it "should return the correct dir" do
|
495
495
|
@file.dir.should match_path('public', 'monkey')
|
496
496
|
end
|
@@ -498,7 +498,7 @@ describe "a saved UploadedFile" do
|
|
498
498
|
after do
|
499
499
|
FileUtils.rm_rf(PUBLIC)
|
500
500
|
end
|
501
|
-
|
501
|
+
|
502
502
|
end
|
503
503
|
|
504
504
|
describe "an UploadedFile with a manipulator" do
|
@@ -507,11 +507,11 @@ describe "an UploadedFile with a manipulator" do
|
|
507
507
|
a_manipulator.send(:define_method, :monkey! ) { |stuff| stuff }
|
508
508
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, :donkey, :manipulator => a_manipulator)
|
509
509
|
end
|
510
|
-
|
510
|
+
|
511
511
|
it "should extend the object with the manipulator methods." do
|
512
512
|
@file.should respond_to(:monkey!)
|
513
513
|
end
|
514
|
-
|
514
|
+
|
515
515
|
end
|
516
516
|
|
517
517
|
describe "an UploadedFile with a manipulator and versions" do
|
@@ -520,16 +520,16 @@ describe "an UploadedFile with a manipulator and versions" do
|
|
520
520
|
a_manipulator.send(:define_method, :monkey! ) { |stuff| stuff }
|
521
521
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, :donkey, :versions => [ :thumb, :large ], :manipulator => a_manipulator)
|
522
522
|
end
|
523
|
-
|
523
|
+
|
524
524
|
it "should extend the object with the manipulator methods." do
|
525
525
|
@file.should respond_to(:monkey!)
|
526
526
|
end
|
527
|
-
|
527
|
+
|
528
528
|
it "should extend the versions with the manipulator methods." do
|
529
529
|
@file.thumb.should respond_to(:monkey!)
|
530
530
|
@file.large.should respond_to(:monkey!)
|
531
531
|
end
|
532
|
-
|
532
|
+
|
533
533
|
end
|
534
534
|
|
535
535
|
describe "an UploadedFile with a manipulator with dependencies" do
|
@@ -543,18 +543,18 @@ describe "an UploadedFile with a manipulator with dependencies" do
|
|
543
543
|
# and if process! is called, the process_proxy will be adressed instead.
|
544
544
|
process_proxy.load_manipulator_dependencies
|
545
545
|
end
|
546
|
-
|
546
|
+
|
547
547
|
process_proxy.should_receive(:load_manipulator_dependencies)
|
548
|
-
|
548
|
+
|
549
549
|
@file = UploadColumn::UploadedFile.new(:open, stub_file('kerb.jpg'), nil, :donkey, :manipulator => a_manipulator)
|
550
550
|
|
551
551
|
@file.should respond_to(:monkey!)
|
552
552
|
end
|
553
|
-
|
553
|
+
|
554
554
|
end
|
555
555
|
|
556
556
|
describe "an UploadedFile with a manipulator and process instruction" do
|
557
|
-
|
557
|
+
|
558
558
|
it "should process before iterating versions" do
|
559
559
|
process_proxy = mock('nothing in particular')
|
560
560
|
a_manipulator = Module.new
|
@@ -595,12 +595,12 @@ describe "an UploadedFile with versions" do
|
|
595
595
|
before do
|
596
596
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :monkey, :versions => [ :thumb, :large ])
|
597
597
|
end
|
598
|
-
|
598
|
+
|
599
599
|
it "should respond to version methods" do
|
600
600
|
@file.should respond_to(:thumb)
|
601
601
|
@file.should respond_to(:large)
|
602
602
|
end
|
603
|
-
|
603
|
+
|
604
604
|
it "should return an UploadedFile instance when a version method is called" do
|
605
605
|
@file.thumb.should be_instance_of(UploadColumn::UploadedFile)
|
606
606
|
@file.large.should be_instance_of(UploadColumn::UploadedFile)
|
@@ -622,7 +622,7 @@ describe "all versions of uploaded files", :shared => true do
|
|
622
622
|
@thumb.extension.should == "jpg"
|
623
623
|
@large.extension.should == "jpg"
|
624
624
|
end
|
625
|
-
|
625
|
+
|
626
626
|
it "should return the correct suffix" do
|
627
627
|
@thumb.suffix.should == :thumb
|
628
628
|
@large.suffix.should == :large
|
@@ -635,9 +635,9 @@ describe "a version of an uploaded UploadedFile" do
|
|
635
635
|
@thumb = @file.thumb
|
636
636
|
@large = @file.large
|
637
637
|
end
|
638
|
-
|
638
|
+
|
639
639
|
it_should_behave_like "all versions of uploaded files"
|
640
|
-
|
640
|
+
|
641
641
|
it "should not be empty" do
|
642
642
|
@thumb.should_not be_empty
|
643
643
|
@large.should_not be_empty
|
@@ -655,9 +655,9 @@ describe "a version of an uploaded UploadedFile" do
|
|
655
655
|
end
|
656
656
|
|
657
657
|
describe "uploading a file with versions as a Hash" do
|
658
|
-
|
658
|
+
|
659
659
|
it "should process the files with the manipulator" do
|
660
|
-
|
660
|
+
|
661
661
|
process_proxy = mock('nothing in particular')
|
662
662
|
a_manipulator = Module.new
|
663
663
|
a_manipulator.send(:define_method, :process! ) do |stuff|
|
@@ -665,20 +665,20 @@ describe "uploading a file with versions as a Hash" do
|
|
665
665
|
# and if process! is called, the process_proxy will be adressed instead.
|
666
666
|
process_proxy.process!(self.filename, stuff)
|
667
667
|
end
|
668
|
-
|
668
|
+
|
669
669
|
process_proxy.should_receive(:process!).with('kerb-thumb.jpg', '200x200')
|
670
670
|
process_proxy.should_receive(:process!).with('kerb-large.jpg', '300x300')
|
671
|
-
|
671
|
+
|
672
672
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey, :manipulator => a_manipulator, :versions => { :thumb => '200x200', :large => '300x300' })
|
673
673
|
@thumb = @file.thumb
|
674
674
|
@large = @file.large
|
675
675
|
end
|
676
|
-
|
676
|
+
|
677
677
|
end
|
678
678
|
|
679
679
|
|
680
680
|
describe "an version of an UploadedFile with versions as a hash" do
|
681
|
-
|
681
|
+
|
682
682
|
before(:each) do
|
683
683
|
process_proxy = mock('nothing in particular')
|
684
684
|
a_manipulator = Module.new
|
@@ -687,9 +687,9 @@ describe "an version of an UploadedFile with versions as a hash" do
|
|
687
687
|
@thumb = @file.thumb
|
688
688
|
@large = @file.large
|
689
689
|
end
|
690
|
-
|
690
|
+
|
691
691
|
it_should_behave_like "all versions of uploaded files"
|
692
|
-
|
692
|
+
|
693
693
|
it "should not be empty" do
|
694
694
|
@thumb.should_not be_empty
|
695
695
|
@large.should_not be_empty
|
@@ -703,50 +703,50 @@ describe "an version of an UploadedFile with versions as a hash" do
|
|
703
703
|
end
|
704
704
|
|
705
705
|
describe "a retrieved UploadedFile" do
|
706
|
-
|
706
|
+
|
707
707
|
before do
|
708
708
|
@file = UploadColumn::UploadedFile.retrieve('kerb.jpg', nil, :monkey)
|
709
709
|
@file.stub!(:size).and_return(87582)
|
710
710
|
end
|
711
|
-
|
711
|
+
|
712
712
|
it_should_behave_like "all uploaded files"
|
713
|
-
|
713
|
+
|
714
714
|
it "should not be new" do
|
715
715
|
@file.should_not be_new_file
|
716
716
|
end
|
717
|
-
|
717
|
+
|
718
718
|
it "should not be a tempfile" do
|
719
719
|
@file.should_not be_a_tempfile
|
720
720
|
end
|
721
|
-
|
721
|
+
|
722
722
|
it "should return the correct path" do
|
723
723
|
@file.path.should match_path(public_path('monkey/kerb.jpg'))
|
724
724
|
end
|
725
725
|
end
|
726
726
|
|
727
727
|
describe "a version of a retrieved UploadedFile" do
|
728
|
-
|
728
|
+
|
729
729
|
before do
|
730
730
|
@file = UploadColumn::UploadedFile.retrieve('kerb.jpg', nil, :monkey, :versions => [:thumb, :large])
|
731
731
|
@thumb = @file.thumb
|
732
732
|
@large = @file.large
|
733
733
|
end
|
734
|
-
|
734
|
+
|
735
735
|
it_should_behave_like "all versions of uploaded files"
|
736
|
-
|
736
|
+
|
737
737
|
it "should not be new" do
|
738
738
|
@file.should_not be_new_file
|
739
739
|
end
|
740
|
-
|
740
|
+
|
741
741
|
it "should not be a tempfile" do
|
742
742
|
@file.should_not be_a_tempfile
|
743
743
|
end
|
744
|
-
|
744
|
+
|
745
745
|
it "should return the correct path" do
|
746
746
|
@thumb.path.should match_path(public_path('monkey/kerb-thumb.jpg'))
|
747
747
|
@large.path.should match_path(public_path('monkey/kerb-large.jpg'))
|
748
748
|
end
|
749
|
-
|
749
|
+
|
750
750
|
# Since the files don't exist in fixtures/ it wouldn't make sense to test their size
|
751
751
|
end
|
752
752
|
|
@@ -757,17 +757,17 @@ describe "a version of a saved UploadedFile" do
|
|
757
757
|
@thumb = @file.thumb
|
758
758
|
@large = @file.large
|
759
759
|
end
|
760
|
-
|
760
|
+
|
761
761
|
it_should_behave_like "all versions of uploaded files"
|
762
|
-
|
762
|
+
|
763
763
|
it "should not be new" do
|
764
764
|
@file.should_not be_new_file
|
765
765
|
end
|
766
|
-
|
766
|
+
|
767
767
|
it "should not be a tempfile" do
|
768
768
|
@file.should_not be_a_tempfile
|
769
769
|
end
|
770
|
-
|
770
|
+
|
771
771
|
it "should return the correct path" do
|
772
772
|
@thumb.path.should match_path('public', 'monkey', 'kerb-thumb.jpg')
|
773
773
|
@large.path.should match_path('public', 'monkey', 'kerb-large.jpg')
|
@@ -781,25 +781,25 @@ describe "opening a temporary UploadedFile" do
|
|
781
781
|
@file = UploadColumn::UploadedFile.retrieve_temp(file_path('kerb.jpg'))
|
782
782
|
end.should raise_error(UploadColumn::TemporaryPathMalformedError, "#{file_path('kerb.jpg')} is not a valid temporary path!")
|
783
783
|
end
|
784
|
-
|
784
|
+
|
785
785
|
it "should raise an error if its in a subdirectory" do
|
786
786
|
lambda do
|
787
787
|
@file = UploadColumn::UploadedFile.retrieve_temp('somefolder/1234.56789.1234/donkey.jpg;llama.png')
|
788
788
|
end.should raise_error(UploadColumn::TemporaryPathMalformedError, "somefolder/1234.56789.1234/donkey.jpg;llama.png is not a valid temporary path!")
|
789
789
|
end
|
790
|
-
|
790
|
+
|
791
791
|
it "should raise an error if its relative" do
|
792
792
|
lambda do
|
793
793
|
@file = UploadColumn::UploadedFile.retrieve_temp('../1234.56789.1234/donkey.jpg;llama.png')
|
794
794
|
end.should raise_error(UploadColumn::TemporaryPathMalformedError, "../1234.56789.1234/donkey.jpg;llama.png is not a valid temporary path!")
|
795
795
|
end
|
796
|
-
|
796
|
+
|
797
797
|
it "should raise an error if the filename is omitted" do
|
798
798
|
lambda do
|
799
799
|
@file = UploadColumn::UploadedFile.retrieve_temp('1234.56789.1234;llama.png')
|
800
800
|
end.should raise_error(UploadColumn::TemporaryPathMalformedError, "1234.56789.1234;llama.png is not a valid temporary path!")
|
801
801
|
end
|
802
|
-
|
802
|
+
|
803
803
|
it "should not raise an error on nil" do
|
804
804
|
lambda do
|
805
805
|
@file = UploadColumn::UploadedFile.retrieve_temp(nil)
|
@@ -814,30 +814,30 @@ describe "opening a temporary UploadedFile" do
|
|
814
814
|
end
|
815
815
|
|
816
816
|
describe "a retrieved temporary UploadedFile" do
|
817
|
-
|
817
|
+
|
818
818
|
before(:all) do
|
819
819
|
FileUtils.mkdir_p(public_path('tmp/123455.1233.1233'))
|
820
820
|
FileUtils.cp(file_path('kerb.jpg'), public_path('tmp/123455.1233.1233/kerb.jpg'))
|
821
821
|
end
|
822
|
-
|
822
|
+
|
823
823
|
before do
|
824
824
|
@file = UploadColumn::UploadedFile.retrieve_temp('123455.1233.1233/kerb.jpg')
|
825
825
|
end
|
826
|
-
|
826
|
+
|
827
827
|
it_should_behave_like "all uploaded files"
|
828
|
-
|
828
|
+
|
829
829
|
it "should not be new" do
|
830
830
|
@file.should_not be_new_file
|
831
831
|
end
|
832
|
-
|
832
|
+
|
833
833
|
it "should be a tempfile" do
|
834
834
|
@file.should be_a_tempfile
|
835
835
|
end
|
836
|
-
|
836
|
+
|
837
837
|
it "should return the correct path" do
|
838
838
|
@file.path.should match_path('public', 'tmp', '123455.1233.1233', 'kerb.jpg')
|
839
839
|
end
|
840
|
-
|
840
|
+
|
841
841
|
after(:all) do
|
842
842
|
FileUtils.rm_rf(PUBLIC)
|
843
843
|
end
|
@@ -848,67 +848,67 @@ describe "a retrieved temporary UploadedFile with an appended original filename"
|
|
848
848
|
FileUtils.mkdir_p(public_path('tmp/123455.1233.1233'))
|
849
849
|
FileUtils.cp(file_path('kerb.jpg'), public_path('tmp/123455.1233.1233/kerb.jpg'))
|
850
850
|
end
|
851
|
-
|
851
|
+
|
852
852
|
before do
|
853
853
|
@file = UploadColumn::UploadedFile.retrieve_temp('123455.1233.1233/kerb.jpg;monkey.png')
|
854
854
|
end
|
855
|
-
|
855
|
+
|
856
856
|
it "should not be new" do
|
857
857
|
@file.should_not be_new_file
|
858
858
|
end
|
859
|
-
|
859
|
+
|
860
860
|
it "should be a tempfile" do
|
861
861
|
@file.should be_a_tempfile
|
862
862
|
end
|
863
|
-
|
863
|
+
|
864
864
|
it "should return the correct original filename" do
|
865
865
|
@file.original_filename.should == "monkey.png"
|
866
866
|
end
|
867
|
-
|
867
|
+
|
868
868
|
it "should return the correct path" do
|
869
869
|
@file.path.should match_path('public', 'tmp', '123455.1233.1233', 'kerb.jpg')
|
870
870
|
end
|
871
|
-
|
871
|
+
|
872
872
|
after(:all) do
|
873
873
|
FileUtils.rm_rf(PUBLIC)
|
874
874
|
end
|
875
875
|
end
|
876
876
|
|
877
877
|
describe "a version of a retrieved temporary UploadedFile" do
|
878
|
-
|
878
|
+
|
879
879
|
before(:all) do
|
880
880
|
FileUtils.mkdir_p(public_path('tmp/123455.1233.1233'))
|
881
881
|
FileUtils.cp(file_path('kerb.jpg'), public_path('tmp/123455.1233.1233/kerb.jpg'))
|
882
882
|
end
|
883
|
-
|
883
|
+
|
884
884
|
before do
|
885
885
|
@file = UploadColumn::UploadedFile.retrieve_temp('123455.1233.1233/kerb.jpg', nil, :monkey, :versions => [:thumb, :large])
|
886
886
|
@thumb = @file.thumb
|
887
887
|
@large = @file.large
|
888
888
|
end
|
889
|
-
|
889
|
+
|
890
890
|
it_should_behave_like "all versions of uploaded files"
|
891
|
-
|
891
|
+
|
892
892
|
it "should not be new" do
|
893
893
|
@file.should_not be_new_file
|
894
894
|
end
|
895
|
-
|
895
|
+
|
896
896
|
it "should be a tempfile" do
|
897
897
|
@file.should be_a_tempfile
|
898
898
|
end
|
899
|
-
|
899
|
+
|
900
900
|
it "should return the correct path" do
|
901
901
|
@thumb.path.should match_path(public_path('tmp/123455.1233.1233/kerb-thumb.jpg'))
|
902
902
|
@large.path.should match_path(public_path('tmp/123455.1233.1233/kerb-large.jpg'))
|
903
903
|
end
|
904
|
-
|
904
|
+
|
905
905
|
after(:all) do
|
906
906
|
FileUtils.rm_rf(PUBLIC)
|
907
907
|
end
|
908
908
|
end
|
909
909
|
|
910
910
|
describe "uploading a file with validate_integrity set to true" do
|
911
|
-
|
911
|
+
|
912
912
|
it "should raise an error if no extensions are set" do
|
913
913
|
lambda do
|
914
914
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, nil, :validate_integrity => true)
|
@@ -920,7 +920,7 @@ describe "uploading a file with validate_integrity set to true" do
|
|
920
920
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, nil, :validate_integrity => true, :extensions => %w(jpg gif png))
|
921
921
|
end.should_not raise_error
|
922
922
|
end
|
923
|
-
|
923
|
+
|
924
924
|
it "should raise an error if the extension is not in extensions" do
|
925
925
|
lambda do
|
926
926
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, nil, :validate_integrity => true, :extensions => %w(doc gif png))
|
@@ -932,7 +932,7 @@ describe "An UploadedFile with no web_root set" do
|
|
932
932
|
it "should return the correct URL and to_s" do
|
933
933
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey, :versions => [:thumb, :large])
|
934
934
|
@file.send(:save)
|
935
|
-
|
935
|
+
|
936
936
|
@file.url.should == "/donkey/kerb.jpg"
|
937
937
|
@file.to_s.should == "/donkey/kerb.jpg"
|
938
938
|
@file.thumb.url.should == "/donkey/kerb-thumb.jpg"
|
@@ -943,13 +943,13 @@ end
|
|
943
943
|
describe "An UploadedFile with no web_root set and MS style slashes in its relative path" do
|
944
944
|
it "should return the correct URL and to_s" do
|
945
945
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey, :versions => [:thumb, :large])
|
946
|
-
|
946
|
+
|
947
947
|
@file.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb.jpg')
|
948
948
|
@file.thumb.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb-thumb.jpg')
|
949
949
|
@file.large.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb-large.jpg')
|
950
|
-
|
950
|
+
|
951
951
|
@file.send(:save)
|
952
|
-
|
952
|
+
|
953
953
|
@file.url.should == "/stylesheets/something/monkey/kerb.jpg"
|
954
954
|
@file.to_s.should == "/stylesheets/something/monkey/kerb.jpg"
|
955
955
|
@file.thumb.url.should == "/stylesheets/something/monkey/kerb-thumb.jpg"
|
@@ -961,7 +961,7 @@ describe "An UploadedFile with an absolute web_root set" do
|
|
961
961
|
it "should return the correct URL and to_s" do
|
962
962
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey, :web_root => 'http://ape.com', :versions => [:thumb, :large])
|
963
963
|
@file.send(:save)
|
964
|
-
|
964
|
+
|
965
965
|
@file.url.should == "http://ape.com/donkey/kerb.jpg"
|
966
966
|
@file.to_s.should == "http://ape.com/donkey/kerb.jpg"
|
967
967
|
@file.thumb.url.should == "http://ape.com/donkey/kerb-thumb.jpg"
|
@@ -975,9 +975,9 @@ describe "An UploadedFile with an absolute web_root set and MS style slashes in
|
|
975
975
|
@file.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb.jpg')
|
976
976
|
@file.thumb.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb-thumb.jpg')
|
977
977
|
@file.large.should_receive(:relative_path).at_least(:once).and_return('stylesheets\something\monkey\kerb-large.jpg')
|
978
|
-
|
978
|
+
|
979
979
|
@file.send(:save)
|
980
|
-
|
980
|
+
|
981
981
|
@file.url.should == "http://ape.com/stylesheets/something/monkey/kerb.jpg"
|
982
982
|
@file.to_s.should == "http://ape.com/stylesheets/something/monkey/kerb.jpg"
|
983
983
|
@file.thumb.url.should == "http://ape.com/stylesheets/something/monkey/kerb-thumb.jpg"
|
@@ -989,7 +989,7 @@ describe "An UploadedFile with a web_root set" do
|
|
989
989
|
it "should return the correct URL" do
|
990
990
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey, :web_root => '/ape', :versions => [:thumb, :large])
|
991
991
|
@file.send(:save)
|
992
|
-
|
992
|
+
|
993
993
|
@file.url.should == "/ape/donkey/kerb.jpg"
|
994
994
|
@file.to_s.should == "/ape/donkey/kerb.jpg"
|
995
995
|
@file.thumb.url.should == "/ape/donkey/kerb-thumb.jpg"
|
@@ -998,56 +998,57 @@ describe "An UploadedFile with a web_root set" do
|
|
998
998
|
end
|
999
999
|
|
1000
1000
|
describe "the temp_value of an UploadedFile without an original filename" do
|
1001
|
-
|
1002
|
-
|
1001
|
+
|
1002
|
+
before do
|
1003
1003
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey)
|
1004
1004
|
@file.should_receive(:original_filename).and_return(nil)
|
1005
1005
|
end
|
1006
|
-
|
1006
|
+
|
1007
1007
|
it "should match the TempValueRegexp" do
|
1008
1008
|
@file.temp_value.should match(::UploadColumn::TempValueRegexp)
|
1009
1009
|
end
|
1010
|
-
|
1010
|
+
|
1011
1011
|
it "should end in the filename" do
|
1012
1012
|
@file.temp_value.should match(/\/kerb\.jpg$/)
|
1013
1013
|
end
|
1014
1014
|
end
|
1015
1015
|
|
1016
1016
|
describe "the temp_value of an UploadedFile with a different orignal filename" do
|
1017
|
-
|
1018
|
-
|
1017
|
+
|
1018
|
+
before do
|
1019
1019
|
@file = UploadColumn::UploadedFile.upload(stub_file('kerb.jpg'), nil, :donkey)
|
1020
1020
|
@file.should_receive(:original_filename).at_least(:once).and_return('monkey.png')
|
1021
1021
|
end
|
1022
|
-
|
1022
|
+
|
1023
1023
|
it "should match the TempValueRegexp" do
|
1024
1024
|
@file.temp_value.should match(::UploadColumn::TempValueRegexp)
|
1025
1025
|
end
|
1026
|
-
|
1026
|
+
|
1027
1027
|
it "should append the original_filename" do
|
1028
1028
|
@file.temp_value.should match(/kerb\.jpg;monkey\.png$/)
|
1029
1029
|
end
|
1030
1030
|
end
|
1031
1031
|
|
1032
1032
|
describe "the temp_value of a retrieved temporary UploadedFile" do
|
1033
|
-
|
1034
|
-
|
1033
|
+
|
1034
|
+
before do
|
1035
1035
|
@file = UploadColumn::UploadedFile.retrieve_temp('12345.1234.12345/kerb.jpg', nil, :donkey)
|
1036
1036
|
@file.should_receive(:original_filename).at_least(:once).and_return(nil)
|
1037
1037
|
end
|
1038
|
-
|
1038
|
+
|
1039
1039
|
it "should be mainatained" do
|
1040
1040
|
@file.temp_value.should == '12345.1234.12345/kerb.jpg'
|
1041
1041
|
end
|
1042
1042
|
end
|
1043
1043
|
|
1044
1044
|
describe "the temp_value of an UploadedFile that is not temporary" do
|
1045
|
-
|
1046
|
-
|
1045
|
+
|
1046
|
+
before do
|
1047
1047
|
@file = UploadColumn::UploadedFile.retrieve('kerb.jpg', nil, :donkey)
|
1048
1048
|
end
|
1049
|
-
|
1049
|
+
|
1050
1050
|
it "should be mainatained" do
|
1051
1051
|
@file.temp_value.should be_nil
|
1052
1052
|
end
|
1053
|
-
end
|
1053
|
+
end
|
1054
|
+
|