dragonfly 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/Gemfile +1 -1
- data/History.md +32 -0
- data/README.md +54 -32
- data/VERSION +1 -1
- data/dragonfly.gemspec +23 -21
- data/extra_docs/Configuration.md +0 -8
- data/extra_docs/DataStorage.md +13 -5
- data/extra_docs/ExampleUseCases.md +4 -1
- data/extra_docs/Heroku.md +14 -6
- data/extra_docs/Models.md +5 -1
- data/extra_docs/Rails3.md +1 -1
- data/extra_docs/URLs.md +8 -1
- data/lib/dragonfly.rb +7 -8
- data/lib/dragonfly/active_model_extensions/attachment.rb +37 -17
- data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +1 -1
- data/lib/dragonfly/active_model_extensions/validations.rb +53 -26
- data/lib/dragonfly/analyser.rb +1 -1
- data/lib/dragonfly/app.rb +1 -1
- data/lib/dragonfly/config/heroku.rb +7 -0
- data/lib/dragonfly/configurable.rb +19 -20
- data/lib/dragonfly/data_storage/couch_data_store.rb +2 -3
- data/lib/dragonfly/data_storage/file_data_store.rb +2 -9
- data/lib/dragonfly/data_storage/mongo_data_store.rb +1 -1
- data/lib/dragonfly/data_storage/s3data_store.rb +17 -10
- data/lib/dragonfly/function_manager.rb +4 -8
- data/lib/dragonfly/has_filename.rb +24 -0
- data/lib/dragonfly/image_magick/analyser.rb +1 -1
- data/lib/dragonfly/image_magick/generator.rb +1 -1
- data/lib/dragonfly/image_magick/processor.rb +5 -0
- data/lib/dragonfly/image_magick/utils.rb +1 -2
- data/lib/dragonfly/job.rb +52 -71
- data/lib/dragonfly/railtie.rb +1 -1
- data/lib/dragonfly/temp_object.rb +32 -14
- data/lib/dragonfly/url_attributes.rb +30 -0
- data/lib/dragonfly/url_mapper.rb +2 -2
- data/samples/DSC02119.JPG +0 -0
- data/samples/a.jp2 +0 -0
- data/samples/beach.jpg +0 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +63 -40
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +4 -0
- data/spec/dragonfly/app_spec.rb +11 -3
- data/spec/dragonfly/configurable_spec.rb +38 -20
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +24 -36
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +21 -5
- data/spec/dragonfly/data_storage/shared_data_store_examples.rb +2 -2
- data/spec/dragonfly/has_filename_spec.rb +88 -0
- data/spec/dragonfly/image_magick/analyser_spec.rb +10 -0
- data/spec/dragonfly/image_magick/processor_spec.rb +11 -0
- data/spec/dragonfly/job_spec.rb +173 -167
- data/spec/dragonfly/temp_object_spec.rb +82 -10
- data/spec/dragonfly/url_attributes.rb +47 -0
- data/spec/dragonfly/url_mapper_spec.rb +9 -1
- data/spec/functional/model_urls_spec.rb +36 -1
- metadata +179 -250
- data/lib/dragonfly/core_ext/string.rb +0 -9
- data/lib/dragonfly/core_ext/symbol.rb +0 -9
- data/spec/dragonfly/core_ext/string_spec.rb +0 -17
- data/spec/dragonfly/core_ext/symbol_spec.rb +0 -17
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dragonfly
|
2
|
+
|
3
|
+
# UrlAttributes is like a normal hash, but treats
|
4
|
+
# :name, :ext and :basename specially -
|
5
|
+
# updating ext/basename also updates the name
|
6
|
+
class UrlAttributes < Hash
|
7
|
+
|
8
|
+
SPECIAL_KEYS = [:name, :basename, :ext]
|
9
|
+
|
10
|
+
include HasFilename
|
11
|
+
|
12
|
+
def name
|
13
|
+
self[:name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def name=(name)
|
17
|
+
self[:name] = name
|
18
|
+
end
|
19
|
+
|
20
|
+
def slice(*keys)
|
21
|
+
keys.inject({}) do |hash, key|
|
22
|
+
key = key.to_sym
|
23
|
+
hash[key] = SPECIAL_KEYS.include?(key) ? send(key) : self[key]
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/dragonfly/url_mapper.rb
CHANGED
@@ -30,7 +30,7 @@ module Dragonfly
|
|
30
30
|
params = Rack::Utils.parse_query(query)
|
31
31
|
params_in_url.each_with_index do |var, i|
|
32
32
|
value = md[i+1][1..-1] if md[i+1]
|
33
|
-
params[var] = value
|
33
|
+
params[var] = value && URI.unescape(value)
|
34
34
|
end
|
35
35
|
params
|
36
36
|
end
|
@@ -45,7 +45,7 @@ module Dragonfly
|
|
45
45
|
url = url_format.dup
|
46
46
|
segments.each do |seg|
|
47
47
|
value = params[seg.param]
|
48
|
-
value ? url.sub!(/:[\w_]+/, value.to_s) : url.sub!(/.:[\w_]+/, '')
|
48
|
+
value ? url.sub!(/:[\w_]+/, URI.escape(value.to_s)) : url.sub!(/.:[\w_]+/, '')
|
49
49
|
params.delete(seg.param)
|
50
50
|
end
|
51
51
|
url << "?#{Rack::Utils.build_query(params)}" if params.any?
|
Binary file
|
data/samples/a.jp2
ADDED
Binary file
|
data/samples/beach.jpg
ADDED
Binary file
|
@@ -190,16 +190,14 @@ describe Item do
|
|
190
190
|
@item.destroy
|
191
191
|
end
|
192
192
|
|
193
|
-
it "should return the url for the data" do
|
194
|
-
@item.preview_image.url.should =~ %r<^/\w+$>
|
195
|
-
end
|
196
|
-
|
197
193
|
it "should destroy the old data when the uid is set manually" do
|
198
194
|
@app.datastore.should_receive(:destroy).with('some_uid')
|
199
195
|
@item.preview_image_uid = 'some_known_uid'
|
200
196
|
@item.save!
|
201
197
|
end
|
202
198
|
|
199
|
+
# SEE model_urls_spec.rb for urls
|
200
|
+
|
203
201
|
describe "when accessed by a new model object" do
|
204
202
|
before(:each) do
|
205
203
|
@item = Item.find(@item.id)
|
@@ -222,6 +220,7 @@ describe Item do
|
|
222
220
|
@app.datastore.should_receive(:destroy).with('some_uid')
|
223
221
|
@item.save!
|
224
222
|
end
|
223
|
+
|
225
224
|
it "should not try to destroy the old data if saved again" do
|
226
225
|
@app.datastore.should_receive(:destroy).with('some_uid')
|
227
226
|
@item.save!
|
@@ -257,6 +256,10 @@ describe Item do
|
|
257
256
|
it "should return the new data" do
|
258
257
|
@item.preview_image.data.should == 'ANEWDATASTRING'
|
259
258
|
end
|
259
|
+
|
260
|
+
it 'should mark the attribute as changed' do
|
261
|
+
@item.preview_image_uid_changed?.should be_true
|
262
|
+
end
|
260
263
|
end
|
261
264
|
|
262
265
|
describe "when it is set to nil" do
|
@@ -278,6 +281,11 @@ describe Item do
|
|
278
281
|
@app.datastore.should_receive(:destroy).with('some_uid')
|
279
282
|
@item.destroy
|
280
283
|
end
|
284
|
+
|
285
|
+
it 'should mark the attribute as changed' do
|
286
|
+
@item.preview_image_uid_changed?.should be_true
|
287
|
+
end
|
288
|
+
|
281
289
|
end
|
282
290
|
|
283
291
|
describe "when the data can't be found" do
|
@@ -496,6 +504,24 @@ describe Item do
|
|
496
504
|
@item.should be_valid
|
497
505
|
end
|
498
506
|
|
507
|
+
it "should allow case sensitivity to be turned off when :as is specified" do
|
508
|
+
@item.should_receive(:its_friday).and_return(false)
|
509
|
+
Item.class_eval do
|
510
|
+
validates_property :mime_type, :of => :preview_image, :as => 'WronG/TypE', :case_sensitive => false
|
511
|
+
end
|
512
|
+
@item.preview_image = "WRONG TYPE"
|
513
|
+
@item.should be_valid
|
514
|
+
end
|
515
|
+
|
516
|
+
it "should allow case sensitivity to be turned off when :in is specified" do
|
517
|
+
@item.should_receive(:its_friday).and_return(false)
|
518
|
+
Item.class_eval do
|
519
|
+
validates_property :mime_type, :of => :preview_image, :in => ['WronG/TypE'], :case_sensitive => false
|
520
|
+
end
|
521
|
+
@item.preview_image = "WRONG TYPE"
|
522
|
+
@item.should be_valid
|
523
|
+
end
|
524
|
+
|
499
525
|
it "should require either :as or :in as an argument" do
|
500
526
|
lambda{
|
501
527
|
Item.class_eval do
|
@@ -598,27 +624,6 @@ describe Item do
|
|
598
624
|
|
599
625
|
describe "meta from magic attributes" do
|
600
626
|
|
601
|
-
it "should set the meta for the magic attribute when assigned" do
|
602
|
-
@item.preview_image = '123'
|
603
|
-
@item.preview_image.meta[:some_analyser_method].should == 'abc1'
|
604
|
-
end
|
605
|
-
|
606
|
-
it "should not set meta for non-magic attributes with the same prefix when assigned" do
|
607
|
-
@item.preview_image = '123'
|
608
|
-
@item.preview_image.meta[:blah_blah].should be_nil
|
609
|
-
end
|
610
|
-
|
611
|
-
it "should update the meta for the magic attribute when something else is assigned" do
|
612
|
-
@item.preview_image = '123'
|
613
|
-
@item.preview_image = '456'
|
614
|
-
@item.preview_image.meta[:some_analyser_method].should == 'abc4'
|
615
|
-
end
|
616
|
-
|
617
|
-
it "should include the meta for size too" do
|
618
|
-
@item.preview_image = '123'
|
619
|
-
@item.preview_image.meta[:size].should == 3
|
620
|
-
end
|
621
|
-
|
622
627
|
it "should store the meta for the original file name if it exists" do
|
623
628
|
data = 'jasdlkf sadjl'
|
624
629
|
data.stub!(:original_filename).and_return('hello.png')
|
@@ -626,11 +631,16 @@ describe Item do
|
|
626
631
|
@item.preview_image.meta[:name].should == 'hello.png'
|
627
632
|
end
|
628
633
|
|
629
|
-
it "should
|
634
|
+
it "should include magic attributes in the saved meta" do
|
630
635
|
@item.preview_image = '123'
|
631
636
|
@item.save!
|
632
|
-
|
633
|
-
|
637
|
+
@app.fetch(@item.preview_image_uid).meta[:some_analyser_method].should == 'abc1'
|
638
|
+
end
|
639
|
+
|
640
|
+
it "should include the size in the saved meta" do
|
641
|
+
@item.preview_image = '123'
|
642
|
+
@item.save!
|
643
|
+
@app.fetch(@item.preview_image_uid).meta[:size].should == 3
|
634
644
|
end
|
635
645
|
|
636
646
|
end
|
@@ -646,10 +656,10 @@ describe Item do
|
|
646
656
|
@item.preview_image.respond_to?(:number_of_As).should be_true
|
647
657
|
end
|
648
658
|
it "should include analyser methods in methods" do
|
649
|
-
@item.preview_image.methods.include
|
659
|
+
@item.preview_image.methods.map{|m| m.to_sym }.should include(:number_of_As)
|
650
660
|
end
|
651
661
|
it "should include analyser methods in public_methods" do
|
652
|
-
@item.preview_image.public_methods.include
|
662
|
+
@item.preview_image.public_methods.map{|m| m.to_sym }.should include(:number_of_As)
|
653
663
|
end
|
654
664
|
|
655
665
|
it "should update when something new is assigned" do
|
@@ -679,6 +689,12 @@ describe Item do
|
|
679
689
|
@item.preview_image.size.should == 17
|
680
690
|
end
|
681
691
|
|
692
|
+
it "should use the magic attribute for name if there is one, and not the job object" do
|
693
|
+
@item.preview_image.send(:job).should_not_receive(:name)
|
694
|
+
@item.should_receive("preview_image_name").and_return('jeffrey.bungle')
|
695
|
+
@item.preview_image.name.should == 'jeffrey.bungle'
|
696
|
+
end
|
697
|
+
|
682
698
|
it "should delegate 'size' to the job object if there is no magic attribute for it" do
|
683
699
|
@item.other_image = 'blahdata'
|
684
700
|
@item.other_image.send(:job).should_receive(:size).and_return 54
|
@@ -751,7 +767,7 @@ describe Item do
|
|
751
767
|
it "should save it correctly" do
|
752
768
|
@item.save!
|
753
769
|
item = Item.find(@item.id)
|
754
|
-
item.preview_image.
|
770
|
+
item.preview_image.meta.should include_hash(:slime => 'balls')
|
755
771
|
end
|
756
772
|
it "should include meta info about the model" do
|
757
773
|
@item.save!
|
@@ -1220,7 +1236,16 @@ describe Item do
|
|
1220
1236
|
it "should return the saved stuff if assigned and retained" do
|
1221
1237
|
@item.preview_image = 'hello'
|
1222
1238
|
@item.preview_image.name = 'dog.biscuit'
|
1223
|
-
@app.datastore.should_receive(:store).with
|
1239
|
+
@app.datastore.should_receive(:store).with do |temp_object, opts|
|
1240
|
+
temp_object.data.should == 'hello'
|
1241
|
+
temp_object.meta.should == {
|
1242
|
+
:name => "dog.biscuit",
|
1243
|
+
:some_analyser_method => "HELLO",
|
1244
|
+
:size => 5,
|
1245
|
+
:model_class => "Item",
|
1246
|
+
:model_attachment => :preview_image
|
1247
|
+
}
|
1248
|
+
end.and_return('new/uid')
|
1224
1249
|
@item.preview_image.retain!
|
1225
1250
|
Dragonfly::Serializer.marshal_decode(@item.retained_preview_image).should == {
|
1226
1251
|
:uid => 'new/uid',
|
@@ -1267,6 +1292,11 @@ describe Item do
|
|
1267
1292
|
)
|
1268
1293
|
@item = Item.new
|
1269
1294
|
end
|
1295
|
+
|
1296
|
+
it "should be retained" do
|
1297
|
+
@item.dragonfly_attachments[:preview_image].should_receive(:retain!)
|
1298
|
+
@item.retained_preview_image = @pending_string
|
1299
|
+
end
|
1270
1300
|
|
1271
1301
|
it "should update the attributes" do
|
1272
1302
|
@item.retained_preview_image = @pending_string
|
@@ -1276,19 +1306,12 @@ describe Item do
|
|
1276
1306
|
@item.preview_image_name.should == 'dog.biscuit'
|
1277
1307
|
end
|
1278
1308
|
|
1279
|
-
it "should update the attachment meta" do
|
1280
|
-
@item.retained_preview_image = @pending_string
|
1281
|
-
@item.preview_image.meta[:some_analyser_method].should == 'HELLO'
|
1282
|
-
@item.preview_image.meta[:size].should == 5
|
1283
|
-
@item.preview_image.meta[:name].should == 'dog.biscuit'
|
1284
|
-
end
|
1285
|
-
|
1286
1309
|
it "should be a normal fetch job" do
|
1287
1310
|
@item.retained_preview_image = @pending_string
|
1288
1311
|
@app.datastore.should_receive(:retrieve).with('new/uid').and_return(Dragonfly::TempObject.new('retrieved yo'))
|
1289
1312
|
@item.preview_image.data.should == 'retrieved yo'
|
1290
1313
|
end
|
1291
|
-
|
1314
|
+
|
1292
1315
|
it "should give the correct url" do
|
1293
1316
|
@item.retained_preview_image = @pending_string
|
1294
1317
|
@item.preview_image.url.should =~ %r{^/\w+/dog.biscuit$}
|
@@ -11,6 +11,7 @@ class MyModel
|
|
11
11
|
define_model_callbacks :save, :destroy
|
12
12
|
|
13
13
|
include ActiveModel::Validations
|
14
|
+
include ActiveModel::Dirty
|
14
15
|
|
15
16
|
class << self
|
16
17
|
def create!(attrs={})
|
@@ -73,6 +74,7 @@ class Item < MyModel
|
|
73
74
|
:created_at,
|
74
75
|
:updated_at
|
75
76
|
]
|
77
|
+
define_attribute_methods ATTRIBUTES
|
76
78
|
attr_accessor *ATTRIBUTES
|
77
79
|
end
|
78
80
|
|
@@ -82,10 +84,12 @@ class Car < MyModel
|
|
82
84
|
:reliant_image_uid,
|
83
85
|
:type
|
84
86
|
]
|
87
|
+
define_attribute_methods ATTRIBUTES
|
85
88
|
attr_accessor *ATTRIBUTES
|
86
89
|
end
|
87
90
|
|
88
91
|
class Photo < MyModel
|
89
92
|
ATTRIBUTES = [:image_uid]
|
93
|
+
define_attribute_methods ATTRIBUTES
|
90
94
|
attr_accessor *ATTRIBUTES
|
91
95
|
end
|
data/spec/dragonfly/app_spec.rb
CHANGED
@@ -101,9 +101,17 @@ describe Dragonfly::App do
|
|
101
101
|
@app.store(temp_object)
|
102
102
|
end
|
103
103
|
it "should allow storing with extra stuff" do
|
104
|
-
@app.datastore.should_receive(:store).with
|
105
|
-
|
106
|
-
|
104
|
+
@app.datastore.should_receive(:store).with do |temp_object, opts|
|
105
|
+
temp_object.data.should == 'HELLO'
|
106
|
+
temp_object.meta.should == {:egg => :head}
|
107
|
+
opts[:option].should == :blarney
|
108
|
+
end
|
109
|
+
@app.store("HELLO", :meta => {:egg => :head}, :option => :blarney)
|
110
|
+
end
|
111
|
+
it "should still pass in meta in the opts arg, for deprecated use of meta" do
|
112
|
+
@app.datastore.should_receive(:store).with do |temp_object, opts|
|
113
|
+
opts[:meta].should == {:egg => :head}
|
114
|
+
end
|
107
115
|
@app.store("HELLO", :meta => {:egg => :head}, :option => :blarney)
|
108
116
|
end
|
109
117
|
end
|
@@ -119,18 +119,6 @@ describe Dragonfly::Configurable do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
describe "using in the singleton class" do
|
123
|
-
it "should work" do
|
124
|
-
class OneOff
|
125
|
-
class << self
|
126
|
-
include Dragonfly::Configurable
|
127
|
-
configurable_attr :food, 'bread'
|
128
|
-
end
|
129
|
-
end
|
130
|
-
OneOff.food.should == 'bread'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
122
|
describe "configuration method" do
|
135
123
|
|
136
124
|
before(:each) do
|
@@ -270,11 +258,11 @@ describe Dragonfly::Configurable do
|
|
270
258
|
|
271
259
|
describe "falling back to another config" do
|
272
260
|
before(:each) do
|
273
|
-
|
274
|
-
class << @garage
|
261
|
+
class Garage
|
275
262
|
include Dragonfly::Configurable
|
276
263
|
configurable_attr :top_speed, 100
|
277
264
|
end
|
265
|
+
@garage = Garage.new
|
278
266
|
@car.use_as_fallback_config(@garage)
|
279
267
|
end
|
280
268
|
|
@@ -364,15 +352,15 @@ describe Dragonfly::Configurable do
|
|
364
352
|
|
365
353
|
describe "objects with different methods" do
|
366
354
|
before(:each) do
|
367
|
-
|
368
|
-
class << @dad
|
355
|
+
class Dad
|
369
356
|
include Dragonfly::Configurable
|
370
357
|
end
|
371
|
-
@
|
372
|
-
class
|
358
|
+
@dad = Dad.new
|
359
|
+
class Kid
|
373
360
|
include Dragonfly::Configurable
|
374
361
|
configurable_attr :lug, 'default-lug'
|
375
362
|
end
|
363
|
+
@kid = Kid.new
|
376
364
|
@kid.use_as_fallback_config(@dad)
|
377
365
|
end
|
378
366
|
|
@@ -394,11 +382,11 @@ describe Dragonfly::Configurable do
|
|
394
382
|
end
|
395
383
|
|
396
384
|
it "should work when a grandchild config is added later" do
|
397
|
-
|
398
|
-
class << grandkid
|
385
|
+
class Grandkid
|
399
386
|
include Dragonfly::Configurable
|
400
387
|
configurable_attr :oogie, 'boogie'
|
401
388
|
end
|
389
|
+
grandkid = Grandkid.new
|
402
390
|
grandkid.use_as_fallback_config(@kid)
|
403
391
|
@dad.configure{|c| c.oogie = 'duggen' }
|
404
392
|
grandkid.oogie.should == 'duggen'
|
@@ -458,4 +446,34 @@ describe Dragonfly::Configurable do
|
|
458
446
|
end
|
459
447
|
|
460
448
|
end
|
449
|
+
|
450
|
+
describe "inheriting configurable_attrs from multiple places" do
|
451
|
+
before(:each) do
|
452
|
+
module A
|
453
|
+
include Dragonfly::Configurable
|
454
|
+
configurable_attr :a
|
455
|
+
end
|
456
|
+
module B
|
457
|
+
include Dragonfly::Configurable
|
458
|
+
configurable_attr :b
|
459
|
+
end
|
460
|
+
class K
|
461
|
+
include Dragonfly::Configurable
|
462
|
+
include A
|
463
|
+
include B
|
464
|
+
configurable_attr :c
|
465
|
+
end
|
466
|
+
class L < K
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
it "should include configuration from all of its mixins" do
|
471
|
+
l = L.new
|
472
|
+
l.configure do |c|
|
473
|
+
c.a = 'something'
|
474
|
+
c.b = 'something'
|
475
|
+
c.c = 'something'
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
461
479
|
end
|
@@ -7,10 +7,15 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
7
7
|
FileUtils.mkdir_p(File.dirname(filename))
|
8
8
|
FileUtils.touch(filename)
|
9
9
|
end
|
10
|
+
|
11
|
+
def assert_exists(path)
|
12
|
+
File.exists?(path).should be_true
|
13
|
+
end
|
10
14
|
|
11
15
|
before(:each) do
|
12
16
|
@data_store = Dragonfly::DataStorage::FileDataStore.new
|
13
17
|
@data_store.root_path = 'tmp/file_data_store_test'
|
18
|
+
@temp_object = Dragonfly::TempObject.new('goobydoo')
|
14
19
|
end
|
15
20
|
|
16
21
|
after(:each) do
|
@@ -20,16 +25,8 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
20
25
|
|
21
26
|
it_should_behave_like 'data_store'
|
22
27
|
|
23
|
-
before(:each) do
|
24
|
-
@temp_object = Dragonfly::TempObject.new('goobydoo')
|
25
|
-
end
|
26
|
-
|
27
28
|
describe "store" do
|
28
29
|
|
29
|
-
def it_should_write_to_file(storage_path, temp_object)
|
30
|
-
temp_object.should_receive(:to_file).with(storage_path).and_return(mock('file', :close => nil))
|
31
|
-
end
|
32
|
-
|
33
30
|
before(:each) do
|
34
31
|
# Set 'now' to a date in the past
|
35
32
|
Time.stub!(:now).and_return Time.mktime(1984,"may",4,14,28,1)
|
@@ -38,31 +35,20 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
38
35
|
end
|
39
36
|
|
40
37
|
it "should store the file in a folder based on date, with default filename" do
|
41
|
-
it_should_write_to_file("#{@file_pattern_prefix}file", @temp_object)
|
42
38
|
@data_store.store(@temp_object)
|
39
|
+
assert_exists "#{@file_pattern_prefix}file"
|
43
40
|
end
|
44
41
|
|
45
|
-
it "should use the temp_object
|
46
|
-
@temp_object.should_receive(:
|
47
|
-
it_should_write_to_file("#{@file_pattern_prefix}hello.there", @temp_object)
|
42
|
+
it "should use the temp_object name if it exists" do
|
43
|
+
@temp_object.should_receive(:name).at_least(:once).and_return('hello.there')
|
48
44
|
@data_store.store(@temp_object)
|
45
|
+
assert_exists "#{@file_pattern_prefix}hello.there"
|
49
46
|
end
|
50
47
|
|
51
|
-
it "should
|
52
|
-
|
53
|
-
@data_store.store(@temp_object, :meta => {:name => 'damp.squib'})
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should prefer the meta name to the original filename" do
|
57
|
-
@temp_object.stub!(:original_filename).and_return('hello.there')
|
58
|
-
it_should_write_to_file("#{@file_pattern_prefix}damp.squib", @temp_object)
|
59
|
-
@data_store.store(@temp_object, :meta => {:name => 'damp.squib'})
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should get rid of funny characters in the temp_object original filename" do
|
63
|
-
@temp_object.should_receive(:original_filename).at_least(:once).and_return('A Picture with many spaces in its name (at 20:00 pm).png')
|
64
|
-
it_should_write_to_file("#{@file_pattern_prefix}A_Picture_with_many_spaces_in_its_name_at_20_00_pm_.png", @temp_object)
|
48
|
+
it "should get rid of funny characters in the temp_object name" do
|
49
|
+
@temp_object.should_receive(:name).at_least(:once).and_return('A Picture with many spaces in its name (at 20:00 pm).png')
|
65
50
|
@data_store.store(@temp_object)
|
51
|
+
assert_exists "#{@file_pattern_prefix}A_Picture_with_many_spaces_in_its_name_at_20_00_pm_.png"
|
66
52
|
end
|
67
53
|
|
68
54
|
describe "when the filename already exists" do
|
@@ -70,12 +56,12 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
70
56
|
it "should use a different filename" do
|
71
57
|
touch_file("#{@file_pattern_prefix}file")
|
72
58
|
@data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file").and_return("#{@file_pattern_prefix}file_2")
|
73
|
-
it_should_write_to_file("#{@file_pattern_prefix}file_2", @temp_object)
|
74
59
|
@data_store.store(@temp_object)
|
60
|
+
assert_exists "#{@file_pattern_prefix}file_2"
|
75
61
|
end
|
76
62
|
|
77
63
|
it "should use a different filename taking into account the name and ext" do
|
78
|
-
@temp_object.should_receive(:
|
64
|
+
@temp_object.should_receive(:name).at_least(:once).and_return('hello.png')
|
79
65
|
touch_file("#{@file_pattern_prefix}hello.png")
|
80
66
|
@data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}hello.png").and_return("#{@file_pattern_prefix}blah.png")
|
81
67
|
@data_store.store(@temp_object)
|
@@ -86,20 +72,20 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
86
72
|
touch_file("#{@file_pattern_prefix}file_2")
|
87
73
|
@data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file").and_return("#{@file_pattern_prefix}file_2")
|
88
74
|
@data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file_2").and_return("#{@file_pattern_prefix}file_3")
|
89
|
-
it_should_write_to_file("#{@file_pattern_prefix}file_3", @temp_object)
|
90
75
|
@data_store.store(@temp_object)
|
76
|
+
assert_exists "#{@file_pattern_prefix}file_3"
|
91
77
|
end
|
92
78
|
|
93
79
|
describe "specifying the uid" do
|
94
80
|
it "should allow for specifying the path to use" do
|
95
|
-
it_should_write_to_file("#{@data_store.root_path}/hello/there/mate.png", @temp_object)
|
96
81
|
@data_store.store(@temp_object, :path => 'hello/there/mate.png')
|
82
|
+
assert_exists "#{@data_store.root_path}/hello/there/mate.png"
|
97
83
|
end
|
98
84
|
it "should correctly disambiguate if the file exists" do
|
99
85
|
touch_file("#{@data_store.root_path}/hello/there/mate.png")
|
100
86
|
@data_store.should_receive(:disambiguate).with("#{@data_store.root_path}/hello/there/mate.png").and_return("#{@data_store.root_path}/hello/there/mate_2.png")
|
101
|
-
it_should_write_to_file("#{@data_store.root_path}/hello/there/mate_2.png", @temp_object)
|
102
87
|
@data_store.store(@temp_object, :path => 'hello/there/mate.png')
|
88
|
+
assert_exists "#{@data_store.root_path}/hello/there/mate_2.png"
|
103
89
|
end
|
104
90
|
end
|
105
91
|
|
@@ -112,7 +98,7 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
112
98
|
end
|
113
99
|
|
114
100
|
it "should return the filepath without the root of the stored file when a file name is provided" do
|
115
|
-
@temp_object.should_receive(:
|
101
|
+
@temp_object.should_receive(:name).at_least(:once).and_return('hello.you.png')
|
116
102
|
@data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}hello.you.png"
|
117
103
|
end
|
118
104
|
|
@@ -162,10 +148,11 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
162
148
|
end
|
163
149
|
|
164
150
|
it "should work even if meta is stored in old .extra file" do
|
165
|
-
|
151
|
+
@temp_object.meta = {:dog => 'foog'}
|
152
|
+
uid = @data_store.store(@temp_object)
|
166
153
|
FileUtils.mv("#{@data_store.root_path}/#{uid}.meta", "#{@data_store.root_path}/#{uid}.extra")
|
167
154
|
pathname, meta = @data_store.retrieve(uid)
|
168
|
-
meta.should == {:dog => '
|
155
|
+
meta.should == {:dog => 'foog'}
|
169
156
|
end
|
170
157
|
|
171
158
|
it "should raise a BadUID error if the file path has ../ in it" do
|
@@ -239,16 +226,17 @@ describe Dragonfly::DataStorage::FileDataStore do
|
|
239
226
|
describe "turning meta off" do
|
240
227
|
before(:each) do
|
241
228
|
@data_store.store_meta = false
|
229
|
+
@temp_object.meta = {:bitrate => '35', :name => 'danny.boy'}
|
242
230
|
end
|
243
231
|
|
244
232
|
it "should not write a meta file" do
|
245
|
-
uid = @data_store.store(@temp_object
|
233
|
+
uid = @data_store.store(@temp_object)
|
246
234
|
path = File.join(@data_store.root_path, uid) + '.meta'
|
247
235
|
File.exist?(path).should be_false
|
248
236
|
end
|
249
237
|
|
250
238
|
it "should return an empty hash on retrieve" do
|
251
|
-
uid = @data_store.store(@temp_object
|
239
|
+
uid = @data_store.store(@temp_object)
|
252
240
|
obj, meta = @data_store.retrieve(uid)
|
253
241
|
meta.should == {}
|
254
242
|
end
|