uploadcolumn 0.3.1 → 0.3.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -8,129 +8,129 @@ require File.join(File.dirname(__FILE__), '../lib/upload_column')
8
8
  class Entry < ActiveRecord::Base; end # setup a basic AR class for testing
9
9
 
10
10
  describe "an ActiveRecord class" do
11
-
11
+
12
12
  include UploadColumnSpecHelper
13
-
13
+
14
14
  it "should respond to upload_column" do
15
15
  Entry.should respond_to(:upload_column)
16
16
  end
17
-
17
+
18
18
  it "should reflect on upload_columns" do
19
19
  Entry.send(:reset_upload_columns)
20
-
20
+
21
21
  Entry.upload_column(:avatar)
22
-
22
+
23
23
  Entry.reflect_on_upload_columns[:avatar].should be_an_instance_of(UploadColumn::Column)
24
24
  Entry.reflect_on_upload_columns[:monkey].should == nil
25
-
25
+
26
26
  Entry.upload_column(:monkey)
27
-
27
+
28
28
  Entry.reflect_on_upload_columns[:avatar].should be_an_instance_of(UploadColumn::Column)
29
29
  Entry.reflect_on_upload_columns[:monkey].should be_an_instance_of(UploadColumn::Column)
30
30
  end
31
-
31
+
32
32
  it "should reset upload columns" do
33
33
  Entry.upload_column(:avatar)
34
-
34
+
35
35
  Entry.reflect_on_upload_columns[:avatar].should be_an_instance_of(UploadColumn::Column)
36
-
36
+
37
37
  Entry.send(:reset_upload_columns)
38
-
38
+
39
39
  Entry.reflect_on_upload_columns[:avatar].should == nil
40
40
  end
41
-
41
+
42
42
  end
43
43
 
44
44
  describe "an Active Record class with an upload_column" do
45
-
45
+
46
46
  include UploadColumnSpecHelper
47
-
47
+
48
48
  it "should add accessor methods" do
49
- # use a name that hasn't been used before!
49
+ # use a name that hasn't been used before!
50
50
  entry = disconnected_model(Entry)
51
51
  entry.should_not respond_to(:llama)
52
52
  entry.should_not respond_to(:llama_temp)
53
53
  entry.should_not respond_to(:llama=)
54
- entry.should_not respond_to(:llama_temp=)
55
-
54
+ entry.should_not respond_to(:llama_temp=)
55
+
56
56
  Entry.upload_column(:llama)
57
-
57
+
58
58
  entry = disconnected_model(Entry)
59
-
59
+
60
60
  entry.should respond_to(:llama)
61
61
  entry.should respond_to(:llama_temp)
62
62
  entry.should respond_to(:llama=)
63
63
  entry.should respond_to(:llama_temp=)
64
64
  end
65
-
65
+
66
66
  it "should save the name of the column to be reflected upon" do
67
67
  Entry.upload_column(:walruss)
68
68
  Entry.reflect_on_upload_columns[:walruss].name.should == :walruss
69
69
  end
70
-
70
+
71
71
  it "should save the options to be reflected upon" do
72
72
  options = { :donkey => true }
73
-
73
+
74
74
  Entry.upload_column(:walruss, options)
75
-
75
+
76
76
  Entry.reflect_on_upload_columns[:walruss].options.should == options
77
77
  end
78
78
  end
79
79
 
80
80
  describe "an Active Record with no upload_column" do
81
-
81
+
82
82
  before(:all) do
83
83
  class Monkey < ActiveRecord::Base; end
84
84
  end
85
-
85
+
86
86
  it "should have no uploads_column" do
87
87
  Monkey.reflect_on_upload_columns.should == {}
88
88
  end
89
-
89
+
90
90
  it "should be instantiable" do
91
91
  Monkey.stub!(:columns).and_return([])
92
92
  Monkey.new
93
93
  end
94
-
94
+
95
95
  end
96
96
 
97
97
  describe "uploading a file" do
98
-
98
+
99
99
  include UploadColumnSpecHelper
100
-
100
+
101
101
  before do
102
102
  setup_standard_mocking
103
103
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
104
104
  end
105
-
105
+
106
106
  it "should pass it to UploadedFile and remember it" do
107
107
  @entry.avatar.should == nil
108
108
  @entry.avatar = @file
109
109
  @entry.avatar.should == @uploaded_file
110
110
  end
111
-
111
+
112
112
  it "should set the attribute on the ActiveRecord" do
113
113
  @entry.should_receive(:[]=).with(:avatar, 'monkey.png')
114
114
  @entry.avatar = @file
115
115
  end
116
-
116
+
117
117
  end
118
118
 
119
119
  describe "uploading an empty String" do
120
-
120
+
121
121
  include UploadColumnSpecHelper
122
-
122
+
123
123
  before do
124
124
  setup_standard_mocking
125
125
  end
126
-
126
+
127
127
  it "should do nothing" do
128
128
  UploadColumn::UploadedFile.should_receive(:upload).with("", @entry, :avatar, @options).and_return(nil)
129
129
  @entry.avatar.should == nil
130
130
  @entry.avatar = ""
131
131
  @entry.avatar.should == nil
132
132
  end
133
-
133
+
134
134
  it "shouldn't affect an already uploaded file" do
135
135
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
136
136
  @entry.avatar = @file
@@ -140,17 +140,17 @@ describe "uploading an empty String" do
140
140
  @entry.avatar = ""
141
141
  @entry.avatar.should == @uploaded_file
142
142
  end
143
-
143
+
144
144
  end
145
145
 
146
146
  describe "setting nil explicitly" do
147
-
147
+
148
148
  include UploadColumnSpecHelper
149
-
149
+
150
150
  before do
151
151
  setup_standard_mocking
152
152
  end
153
-
153
+
154
154
  it "should reset the column" do
155
155
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
156
156
  @entry.avatar = @file
@@ -162,155 +162,155 @@ describe "setting nil explicitly" do
162
162
  end
163
163
 
164
164
  describe "an upload_column with a value stored in the database and no uploaded_file" do
165
-
165
+
166
166
  include UploadColumnSpecHelper
167
-
167
+
168
168
  before do
169
169
  @options = mock('options', :null_object => true)
170
170
  Entry.upload_column(:avatar, @options)
171
-
171
+
172
172
  @entry = disconnected_model(Entry)
173
173
  @entry.stub!(:inspect).and_return('<#Entry>')
174
174
  @string = mock('some string')
175
175
  @entry.should_receive(:[]).with(:avatar).at_least(:once).and_return(@string)
176
176
  end
177
-
177
+
178
178
  it "should retrieve the file from the database" do
179
179
  uploaded_file = mock('uploaded file')
180
-
180
+
181
181
  UploadColumn::UploadedFile.should_receive(:retrieve).with(@string, @entry, :avatar, @options).and_return(uploaded_file)
182
-
182
+
183
183
  @entry.avatar.should == uploaded_file
184
184
  end
185
185
  end
186
186
 
187
187
  describe "saving uploaded files" do
188
-
188
+
189
189
  include UploadColumnSpecHelper
190
-
190
+
191
191
  before do
192
192
  setup_standard_mocking
193
193
  end
194
-
194
+
195
195
  it "should call save on the uploaded file if they are temporary files" do
196
196
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
197
-
197
+
198
198
  @uploaded_file.should_receive(:tempfile?).and_return(true)
199
199
  @uploaded_file.should_receive(:save)
200
200
  @entry.avatar = @file
201
-
201
+
202
202
  @entry.send(:save_uploaded_files)
203
203
  end
204
-
204
+
205
205
  it "should not call save on the uploaded file if they are not temporary files" do
206
206
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
207
-
207
+
208
208
  @uploaded_file.should_receive(:tempfile?).and_return(false)
209
209
  @uploaded_file.should_not_receive(:save)
210
210
  @entry.avatar = @file
211
-
211
+
212
212
  @entry.send(:save_uploaded_files)
213
213
  end
214
-
214
+
215
215
  it "should happen automatically" do
216
216
  # TODO: hmmm, how to test this? do we have to rely on an integration test?
217
217
  #@entry.should_receive(:save_uploaded_files)
218
218
  #@entry.save
219
219
  end
220
-
220
+
221
221
  end
222
222
 
223
223
  describe "fetching a temp value" do
224
-
224
+
225
225
  include UploadColumnSpecHelper
226
-
227
- setup do
226
+
227
+ before do
228
228
  setup_standard_mocking
229
-
229
+
230
230
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
231
-
231
+
232
232
  @temp_value = '12345.1234.12345/somewhere.png'
233
-
233
+
234
234
  @uploaded_file.should_receive(:temp_value).and_return(@temp_value)
235
235
  @entry.avatar = @file
236
236
  end
237
-
237
+
238
238
  it "should fetch the value from the uploaded file" do
239
239
  @entry.avatar_temp.should == @temp_value
240
240
  end
241
-
241
+
242
242
  end
243
243
 
244
244
  describe "assigning a tempfile" do
245
-
245
+
246
246
  include UploadColumnSpecHelper
247
-
248
- setup do
247
+
248
+ before do
249
249
  setup_standard_mocking
250
250
  end
251
-
251
+
252
252
  it "should not override a new file" do
253
253
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
254
254
  @uploaded_file.stub!(:new_file?).and_return(true)
255
255
  @entry.avatar = @file
256
-
256
+
257
257
  temp_value = '12345.1234.12345/somewhere.png'
258
-
258
+
259
259
  UploadColumn::UploadedFile.should_not_receive(:retrieve_temp)
260
260
  @entry.avatar_temp = temp_value
261
-
261
+
262
262
  @entry.avatar.should == @uploaded_file
263
263
  end
264
-
264
+
265
265
  it "should override a file that is not new" do
266
266
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
267
267
  @uploaded_file.stub!(:new_file?).and_return(false)
268
268
  @entry.avatar = @file
269
-
269
+
270
270
  temp_value = '12345.1234.12345/somewhere.png'
271
-
271
+
272
272
  retrieved_file = mock('a retrieved file')
273
273
  retrieved_file.should_receive(:actual_filename).and_return('walruss.png')
274
274
  UploadColumn::UploadedFile.should_receive(:retrieve_temp).with(temp_value, @entry, :avatar, @options).and_return(retrieved_file)
275
275
  @entry.should_receive(:[]=).with(:avatar, 'walruss.png')
276
-
276
+
277
277
  @entry.avatar_temp = temp_value
278
-
278
+
279
279
  @entry.avatar.should == retrieved_file
280
280
  end
281
-
281
+
282
282
  it "should set the file if there is none" do
283
-
283
+
284
284
  temp_value = '12345.1234.12345/somewhere.png'
285
-
285
+
286
286
  retrieved_file = mock('a retrieved file')
287
287
  retrieved_file.should_receive(:actual_filename).and_return('walruss.png')
288
288
  UploadColumn::UploadedFile.should_receive(:retrieve_temp).with(temp_value, @entry, :avatar, @options).and_return(retrieved_file)
289
289
  @entry.should_receive(:[]=).with(:avatar, 'walruss.png')
290
-
290
+
291
291
  @entry.avatar_temp = temp_value
292
-
292
+
293
293
  @entry.avatar.should == retrieved_file
294
294
  end
295
-
295
+
296
296
  end
297
297
 
298
298
  describe "assigning nil to temp" do
299
-
299
+
300
300
  include UploadColumnSpecHelper
301
-
301
+
302
302
  before(:each) do
303
303
  setup_standard_mocking
304
304
  end
305
-
305
+
306
306
  it "should do nothing" do
307
307
  UploadColumn::UploadedFile.stub!(:upload).and_return(@uploaded_file)
308
308
  @uploaded_file.stub!(:new_file?).and_return(false)
309
309
  @entry.avatar = @file
310
-
310
+
311
311
  UploadColumn::UploadedFile.should_not_receive(:retrieve_temp)
312
312
  @entry.should_not_receive(:[]=)
313
-
313
+
314
314
  lambda {
315
315
  @entry.avatar_temp = nil
316
316
  }.should_not change(@entry, :avatar)
@@ -318,21 +318,21 @@ describe "assigning nil to temp" do
318
318
  end
319
319
 
320
320
  describe "assigning a blank string to temp" do
321
-
321
+
322
322
  include UploadColumnSpecHelper
323
-
323
+
324
324
  before(:each) do
325
325
  setup_standard_mocking
326
326
  end
327
-
327
+
328
328
  it "should do nothing" do
329
329
  UploadColumn::UploadedFile.should_receive(:upload).with(@file, @entry, :avatar, @options).and_return(@uploaded_file)
330
330
  @uploaded_file.stub!(:new_file?).and_return(false)
331
331
  @entry.avatar = @file
332
-
332
+
333
333
  UploadColumn::UploadedFile.should_not_receive(:retrieve_temp)
334
334
  @entry.should_not_receive(:[]=)
335
-
335
+
336
336
  lambda {
337
337
  @entry.avatar_temp = ""
338
338
  }.should_not change(@entry, :avatar)
@@ -340,25 +340,25 @@ describe "assigning a blank string to temp" do
340
340
  end
341
341
 
342
342
  describe "an upload column with no file" do
343
-
343
+
344
344
  include UploadColumnSpecHelper
345
-
345
+
346
346
  before(:each) do
347
347
  setup_standard_mocking
348
348
  end
349
-
349
+
350
350
  it "should return no value" do
351
351
  @entry.avatar.should be_nil
352
352
  end
353
-
353
+
354
354
  it "should return no temp_value" do
355
355
  @entry.avatar_temp.should be_nil
356
356
  end
357
-
357
+
358
358
  it "should return nothing in the _public_path method" do
359
359
  @entry.avatar_public_path.should == nil
360
360
  end
361
-
361
+
362
362
  it "should return nothing in the _path method" do
363
363
  @entry.avatar_path.should == nil
364
364
  end
@@ -373,17 +373,17 @@ describe "an upload column with an uploaded file" do
373
373
  UploadColumn::UploadedFile.stub!(:upload).and_return(@uploaded_file)
374
374
  @entry.avatar = @file
375
375
  end
376
-
376
+
377
377
  it "should delegate the _public_path method to the column" do
378
378
  @uploaded_file.should_receive(:public_path).and_return('/url/to/file.exe')
379
379
  @entry.avatar_public_path.should == '/url/to/file.exe'
380
380
  end
381
-
381
+
382
382
  it "should delegate the _path method to the column" do
383
383
  @uploaded_file.should_receive(:path).and_return('/path/to/file.exe')
384
384
  @entry.avatar_path.should == '/path/to/file.exe'
385
385
  end
386
-
386
+
387
387
  end
388
388
 
389
389
  describe "an upload column with different versions and no uploaded file" do
@@ -393,23 +393,23 @@ describe "an upload column with different versions and no uploaded file" do
393
393
  before(:each) do
394
394
  setup_version_mocking # sets up a column with thumb and large versions
395
395
  end
396
-
396
+
397
397
  it "should return nil for the _thumb method" do
398
398
  @entry.avatar_thumb.should == nil
399
399
  end
400
-
400
+
401
401
  it "should return nil for the _large method" do
402
402
  @entry.avatar_large.should == nil
403
403
  end
404
-
404
+
405
405
  it "should return nil for the _thumb_url method" do
406
406
  @entry.avatar_thumb_public_path.should == nil
407
407
  end
408
-
408
+
409
409
  it "should return nil for the _large_path method" do
410
410
  @entry.avatar_large_path.should == nil
411
411
  end
412
-
412
+
413
413
  end
414
414
 
415
415
  describe "an upload column with different versions and an uploaded file" do
@@ -421,74 +421,74 @@ describe "an upload column with different versions and an uploaded file" do
421
421
  UploadColumn::UploadedFile.stub!(:upload).and_return(@uploaded_file)
422
422
  @entry.avatar = @file
423
423
  end
424
-
424
+
425
425
  it "should delegate the _thumb method to the column" do
426
426
  thumb = mock('thumb')
427
427
  @uploaded_file.should_receive(:thumb).and_return(thumb)
428
428
  @entry.avatar_thumb.should == thumb
429
429
  end
430
-
430
+
431
431
  it "should delegate the _large method to the column" do
432
432
  large = mock('large')
433
433
  @uploaded_file.should_receive(:large).and_return(large)
434
434
  @entry.avatar_large.should == large
435
435
  end
436
-
436
+
437
437
  it "should delegate the _thumb_url method to the column" do
438
438
  thumb = mock('thumb')
439
439
  thumb.should_receive(:public_path).and_return('/url/to/file.exe')
440
440
  @uploaded_file.should_receive(:thumb).and_return(thumb)
441
-
441
+
442
442
  @entry.avatar_thumb_public_path.should == '/url/to/file.exe'
443
443
  end
444
-
444
+
445
445
  it "should delegate the _large_path method to the column" do
446
446
  large = mock('large')
447
447
  large.should_receive(:path).and_return('/path/to/file.exe')
448
448
  @uploaded_file.should_receive(:large).and_return(large)
449
-
449
+
450
450
  @entry.avatar_large_path.should == '/path/to/file.exe'
451
451
  end
452
-
452
+
453
453
  end
454
454
 
455
455
  describe "uploading a file that fails an integrity check" do
456
-
456
+
457
457
  include UploadColumnSpecHelper
458
-
458
+
459
459
  before(:all) do
460
460
  Entry.validates_integrity_of :avatar
461
461
  end
462
-
462
+
463
463
  before(:each) do
464
464
  setup_standard_mocking
465
465
  end
466
-
466
+
467
467
  it "should set the column to nil" do
468
468
  UploadColumn::UploadedFile.should_receive(:upload).and_raise(UploadColumn::IntegrityError.new('something'))
469
469
  @entry.avatar = @file
470
-
470
+
471
471
  @entry.avatar.should be_nil
472
472
  end
473
-
473
+
474
474
  it "should fail an integrity validation" do
475
475
  UploadColumn::UploadedFile.should_receive(:upload).and_raise(UploadColumn::IntegrityError.new('something'))
476
476
  @entry.avatar = @file
477
-
477
+
478
478
  @entry.should_not be_valid
479
479
  @entry.errors.on(:avatar).should == 'something'
480
480
  end
481
481
  end
482
482
 
483
483
  describe UploadColumn::ActiveRecordExtension::ClassMethods, ".image_column" do
484
-
484
+
485
485
  include UploadColumnSpecHelper
486
-
486
+
487
487
  before(:each) do
488
488
  @class = Class.new(ActiveRecord::Base)
489
489
  @class.send(:include, UploadColumn)
490
490
  end
491
-
491
+
492
492
  it "should call an upload column with some specialized options" do
493
493
  @class.should_receive(:upload_column).with(:sicada,
494
494
  :manipulator => UploadColumn::Manipulators::RMagick,
@@ -502,13 +502,14 @@ describe UploadColumn::ActiveRecordExtension::ClassMethods, ".image_column" do
502
502
  end
503
503
 
504
504
  describe UploadColumn::ActiveRecordExtension::ClassMethods, ".validate_integrity" do
505
-
505
+
506
506
  include UploadColumnSpecHelper
507
-
507
+
508
508
  it "should change the options for this upload_column" do
509
509
  Entry.upload_column :avatar
510
510
  Entry.reflect_on_upload_columns[:avatar].options[:validate_integrity].should be_nil
511
511
  Entry.validates_integrity_of :avatar
512
512
  Entry.reflect_on_upload_columns[:avatar].options[:validate_integrity].should == true
513
513
  end
514
- end
514
+ end
515
+