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
@@ -59,17 +59,17 @@ describe Dragonfly::DataStorage::S3DataStore do
|
|
59
59
|
@data_store.store(temp_object).should_not == @data_store.store(temp_object2)
|
60
60
|
end
|
61
61
|
|
62
|
-
it "should use the name
|
63
|
-
temp_object = Dragonfly::TempObject.new('eggheads')
|
64
|
-
uid = @data_store.store(temp_object
|
62
|
+
it "should use the name from the temp_object if set" do
|
63
|
+
temp_object = Dragonfly::TempObject.new('eggheads', :name => 'doobie')
|
64
|
+
uid = @data_store.store(temp_object)
|
65
65
|
uid.should =~ /doobie$/
|
66
66
|
data, meta = @data_store.retrieve(uid)
|
67
67
|
data.should == 'eggheads'
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should work ok with files with funny names" do
|
71
|
-
temp_object = Dragonfly::TempObject.new('eggheads')
|
72
|
-
uid = @data_store.store(temp_object
|
71
|
+
temp_object = Dragonfly::TempObject.new('eggheads', :name => 'A Picture with many spaces in its name (at 20:00 pm).png')
|
72
|
+
uid = @data_store.store(temp_object)
|
73
73
|
uid.should =~ /A_Picture_with_many_spaces_in_its_name_at_20_00_pm_\.png$/
|
74
74
|
data, meta = @data_store.retrieve(uid)
|
75
75
|
data.should == 'eggheads'
|
@@ -224,6 +224,13 @@ describe Dragonfly::DataStorage::S3DataStore do
|
|
224
224
|
end
|
225
225
|
@data_store.store(@temp_object, :headers => {'hello' => 'there'})
|
226
226
|
end
|
227
|
+
|
228
|
+
it "should store with the content-type if passed in" do
|
229
|
+
@data_store.storage.should_receive(:put_object) do |_, __, ___, headers|
|
230
|
+
headers['Content-Type'].should == 'text/plain'
|
231
|
+
end
|
232
|
+
@data_store.store(@temp_object, :mime_type => 'text/plain')
|
233
|
+
end
|
227
234
|
end
|
228
235
|
|
229
236
|
describe "urls for serving directly" do
|
@@ -245,6 +252,15 @@ describe Dragonfly::DataStorage::S3DataStore do
|
|
245
252
|
@data_store.url_for(@uid, :expires => 1301476942).should =~
|
246
253
|
%r{^https://#{@data_store.domain}/#{BUCKET_NAME}/some/path/on/s3\?AWSAccessKeyId=#{@data_store.access_key_id}&Signature=[\w%]+&Expires=1301476942$}
|
247
254
|
end
|
255
|
+
|
256
|
+
it "should allow for using https" do
|
257
|
+
@data_store.url_for(@uid, :scheme => 'https').should == "https://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should allow for always using https" do
|
261
|
+
@data_store.url_scheme = 'https'
|
262
|
+
@data_store.url_for(@uid).should == "https://#{BUCKET_NAME}.s3.amazonaws.com/some/path/on/s3"
|
263
|
+
end
|
248
264
|
|
249
265
|
end
|
250
266
|
|
@@ -44,8 +44,8 @@ shared_examples_for "data_store" do
|
|
44
44
|
|
45
45
|
describe "when meta is given" do
|
46
46
|
before(:each) do
|
47
|
-
temp_object = Dragonfly::TempObject.new('gollum')
|
48
|
-
@uid = @data_store.store(temp_object
|
47
|
+
temp_object = Dragonfly::TempObject.new('gollum', :bitrate => '35', :name => 'danny.boy')
|
48
|
+
@uid = @data_store.store(temp_object)
|
49
49
|
@obj, @meta = @data_store.retrieve(@uid)
|
50
50
|
end
|
51
51
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dragonfly::HasFilename do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@obj = Object.new
|
7
|
+
class << @obj
|
8
|
+
include Dragonfly::HasFilename
|
9
|
+
attr_accessor :name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "basename" do
|
14
|
+
it "should define basename" do
|
15
|
+
@obj.name = 'meat.balls'
|
16
|
+
@obj.basename.should == 'meat'
|
17
|
+
end
|
18
|
+
it "should all but the last bit" do
|
19
|
+
@obj.name = 'tooting.meat.balls'
|
20
|
+
@obj.basename.should == 'tooting.meat'
|
21
|
+
end
|
22
|
+
it "should be nil if name not set" do
|
23
|
+
@obj.basename.should be_nil
|
24
|
+
end
|
25
|
+
it "should be the whole name if it has no ext" do
|
26
|
+
@obj.name = 'eggs'
|
27
|
+
@obj.basename.should == 'eggs'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "basename=" do
|
32
|
+
it "should set the whole name if there isn't one" do
|
33
|
+
@obj.basename = 'doog'
|
34
|
+
@obj.name.should == 'doog'
|
35
|
+
end
|
36
|
+
it "should replace the whole name if there's no ext" do
|
37
|
+
@obj.name = 'lungs'
|
38
|
+
@obj.basename = 'doog'
|
39
|
+
@obj.name.should == 'doog'
|
40
|
+
end
|
41
|
+
it "should replace all but the last bit" do
|
42
|
+
@obj.name = 'bong.lungs.pig'
|
43
|
+
@obj.basename = 'smeeg'
|
44
|
+
@obj.name.should == 'smeeg.pig'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "ext" do
|
49
|
+
it "should define ext" do
|
50
|
+
@obj.name = 'meat.balls'
|
51
|
+
@obj.ext.should == 'balls'
|
52
|
+
end
|
53
|
+
it "should only use the last bit" do
|
54
|
+
@obj.name = 'tooting.meat.balls'
|
55
|
+
@obj.ext.should == 'balls'
|
56
|
+
end
|
57
|
+
it "should be nil if name not set" do
|
58
|
+
@obj.ext.should be_nil
|
59
|
+
end
|
60
|
+
it "should be nil if name has no ext" do
|
61
|
+
@obj.name = 'eggs'
|
62
|
+
@obj.ext.should be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "ext=" do
|
67
|
+
it "should use a default basename if there is no name" do
|
68
|
+
@obj.ext = 'doog'
|
69
|
+
@obj.name.should == 'file.doog'
|
70
|
+
end
|
71
|
+
it "should append the ext if name has none already" do
|
72
|
+
@obj.name = 'lungs'
|
73
|
+
@obj.ext = 'doog'
|
74
|
+
@obj.name.should == 'lungs.doog'
|
75
|
+
end
|
76
|
+
it "should replace the ext if name has one already" do
|
77
|
+
@obj.name = 'lungs.pig'
|
78
|
+
@obj.ext = 'doog'
|
79
|
+
@obj.name.should == 'lungs.doog'
|
80
|
+
end
|
81
|
+
it "should only replace the last bit" do
|
82
|
+
@obj.name = 'long.lungs.pig'
|
83
|
+
@obj.ext = 'doog'
|
84
|
+
@obj.name.should == 'long.lungs.doog'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -64,5 +64,15 @@ describe Dragonfly::ImageMagick::Analyser do
|
|
64
64
|
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('white pixel.png'))
|
65
65
|
@analyser.width(image).should == 1
|
66
66
|
end
|
67
|
+
|
68
|
+
it "should work (width) for images with capital letter extensions" do
|
69
|
+
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('DSC02119.JPG'))
|
70
|
+
@analyser.width(image).should == 1
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should work (width) for images with numbers in the format" do
|
74
|
+
image = Dragonfly::TempObject.new(SAMPLES_DIR.join('a.jp2'))
|
75
|
+
@analyser.width(image).should == 1
|
76
|
+
end
|
67
77
|
|
68
78
|
end
|
@@ -237,6 +237,17 @@ describe Dragonfly::ImageMagick::Processor do
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
|
+
describe "auto-orient" do
|
241
|
+
it "should rotate an image according to exif information" do
|
242
|
+
@image = Dragonfly::TempObject.new(SAMPLES_DIR.join('beach.jpg'))
|
243
|
+
@image.should have_width(355)
|
244
|
+
@image.should have_height(280)
|
245
|
+
image = @processor.auto_orient(@image)
|
246
|
+
image.should have_width(280)
|
247
|
+
image.should have_height(355)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
240
251
|
describe "flip" do
|
241
252
|
it "should flip the image, leaving the same dimensions" do
|
242
253
|
image = @processor.flip(@image)
|
data/spec/dragonfly/job_spec.rb
CHANGED
@@ -45,18 +45,18 @@ describe Dragonfly::Job do
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should allow initializing with content" do
|
49
|
+
job = Dragonfly::Job.new(@app, 'eggheads')
|
50
|
+
job.data.should == 'eggheads'
|
51
|
+
end
|
52
|
+
|
48
53
|
describe "without content" do
|
49
54
|
|
50
55
|
before(:each) do
|
51
|
-
@app =
|
56
|
+
@app = test_app
|
52
57
|
@job = Dragonfly::Job.new(@app)
|
53
58
|
end
|
54
59
|
|
55
|
-
it "should allow initializing with content" do
|
56
|
-
job = Dragonfly::Job.new(@app, 'eggheads')
|
57
|
-
job.data.should == 'eggheads'
|
58
|
-
end
|
59
|
-
|
60
60
|
describe "fetch" do
|
61
61
|
before(:each) do
|
62
62
|
@job.fetch!('some_uid')
|
@@ -74,6 +74,10 @@ describe Dragonfly::Job do
|
|
74
74
|
@job.data.should == 'HELLO'
|
75
75
|
@job.meta.should == {:name => 'test.txt'}
|
76
76
|
end
|
77
|
+
|
78
|
+
it "shouldn't set any url_attrs" do
|
79
|
+
@job.url_attrs.should == {}
|
80
|
+
end
|
77
81
|
end
|
78
82
|
|
79
83
|
describe "process" do
|
@@ -95,10 +99,19 @@ describe Dragonfly::Job do
|
|
95
99
|
end
|
96
100
|
|
97
101
|
describe "analyse" do
|
98
|
-
it "should raise
|
102
|
+
it "should raise a NoContent error" do
|
103
|
+
job = @app.new_job # This will define #analyser on it
|
104
|
+
lambda{
|
105
|
+
job.analyse(:width)
|
106
|
+
}.should raise_error(Dragonfly::Job::NoContent)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "data" do
|
111
|
+
it "should raise a NoContent error" do
|
99
112
|
lambda{
|
100
|
-
@job.
|
101
|
-
}.should raise_error(Dragonfly::Job::
|
113
|
+
@job.data
|
114
|
+
}.should raise_error(Dragonfly::Job::NoContent)
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
@@ -119,6 +132,10 @@ describe Dragonfly::Job do
|
|
119
132
|
@job.data.should == 'hi'
|
120
133
|
@job.meta.should == {:name => 'plasma.png'}
|
121
134
|
end
|
135
|
+
|
136
|
+
it "shouldn't set any url_attrs" do
|
137
|
+
@job.url_attrs.should == {}
|
138
|
+
end
|
122
139
|
end
|
123
140
|
|
124
141
|
describe "fetch_file" do
|
@@ -132,6 +149,10 @@ describe Dragonfly::Job do
|
|
132
149
|
@job.size.should == 62664
|
133
150
|
end
|
134
151
|
|
152
|
+
it "should set the url_attrs" do
|
153
|
+
@job.url_attrs.should == {:name => 'egg.png'}
|
154
|
+
end
|
155
|
+
|
135
156
|
it "should set the name" do
|
136
157
|
@job.meta[:name].should == 'egg.png'
|
137
158
|
end
|
@@ -139,7 +160,7 @@ describe Dragonfly::Job do
|
|
139
160
|
|
140
161
|
describe "fetch_url" do
|
141
162
|
before(:each) do
|
142
|
-
stub_request(:get,
|
163
|
+
stub_request(:get, %r{http://some\.place\.com/.*}).to_return(:body => 'result!')
|
143
164
|
stub_request(:get, 'https://some.place.com').to_return(:body => 'secure result!')
|
144
165
|
end
|
145
166
|
|
@@ -167,12 +188,22 @@ describe Dragonfly::Job do
|
|
167
188
|
@job.fetch_url!('some.place.com/dung.beetle')
|
168
189
|
@job.meta[:name].should == 'dung.beetle'
|
169
190
|
end
|
191
|
+
|
192
|
+
it "should set the name url_attr if there is one" do
|
193
|
+
@job.fetch_url!('some.place.com/dung.beetle')
|
194
|
+
@job.url_attrs.should == {:name =>'dung.beetle'}
|
195
|
+
end
|
170
196
|
|
171
197
|
["some.place.com", "some.place.com/", "some.place.com/eggs/"].each do |url|
|
172
198
|
it "should not set the name if there isn't one, e.g. #{url}" do
|
173
199
|
@job.fetch_url!(url)
|
174
200
|
@job.meta[:name].should be_nil
|
175
201
|
end
|
202
|
+
|
203
|
+
it "should not set the name url_attr if there isn't one, e.g. #{url}" do
|
204
|
+
@job.fetch_url!(url)
|
205
|
+
@job.url_attrs[:name].should be_nil
|
206
|
+
end
|
176
207
|
end
|
177
208
|
end
|
178
209
|
|
@@ -194,6 +225,7 @@ describe Dragonfly::Job do
|
|
194
225
|
|
195
226
|
describe "process" do
|
196
227
|
before(:each) do
|
228
|
+
@job.url_attrs = {:some => 'thing'}
|
197
229
|
@job.process!(:resize, '20x30')
|
198
230
|
end
|
199
231
|
|
@@ -206,10 +238,13 @@ describe Dragonfly::Job do
|
|
206
238
|
|
207
239
|
it "should maintain the meta attributes" do
|
208
240
|
@app.processor.should_receive(:process).with(@temp_object, :resize, '20x30').and_return('hi')
|
209
|
-
@job.data.should == 'hi'
|
210
241
|
@job.meta.should == {:name => 'hello.txt', :a => :b}
|
211
242
|
end
|
212
243
|
|
244
|
+
it "should maintain the url_attrs" do
|
245
|
+
@job.url_attrs.should == {:some => 'thing'}
|
246
|
+
end
|
247
|
+
|
213
248
|
it "should allow returning an array with extra attributes from the processor" do
|
214
249
|
@app.processor.should_receive(:process).with(@temp_object, :resize, '20x30').and_return(['hi', {:name => 'hello_20x30.txt', :eggs => 'asdf'}])
|
215
250
|
@job.data.should == 'hi'
|
@@ -219,6 +254,7 @@ describe Dragonfly::Job do
|
|
219
254
|
|
220
255
|
describe "encode" do
|
221
256
|
before(:each) do
|
257
|
+
@job.url_attrs = {:name => 'boid'}
|
222
258
|
@job.encode!(:gif, :bitrate => 'mumma')
|
223
259
|
end
|
224
260
|
|
@@ -231,13 +267,12 @@ describe Dragonfly::Job do
|
|
231
267
|
|
232
268
|
it "should maintain the meta and update the format" do
|
233
269
|
@app.encoder.should_receive(:encode).with(@temp_object, :gif, :bitrate => 'mumma').and_return('alo')
|
234
|
-
@job.data.should == 'alo'
|
235
270
|
@job.meta.should == {:name => 'hello.txt', :a => :b, :format => :gif}
|
236
271
|
end
|
237
272
|
|
238
|
-
it "should update the format
|
273
|
+
it "should update the format on the url_attrs" do
|
239
274
|
@app.encoder.should_not_receive(:encode)
|
240
|
-
@job.
|
275
|
+
@job.url_attrs[:format].should == :gif
|
241
276
|
end
|
242
277
|
|
243
278
|
it "should allow returning an array with extra attributes form the encoder" do
|
@@ -250,6 +285,11 @@ describe Dragonfly::Job do
|
|
250
285
|
@app.encoder.should_receive(:encode).with(@temp_object, :gif, :bitrate => 'mumma').and_return(['alo', {:format => :png}])
|
251
286
|
@job.apply.meta[:format].should == :gif
|
252
287
|
end
|
288
|
+
|
289
|
+
it "should maintain the url_attrs" do
|
290
|
+
@job.url_attrs[:name].should == 'boid'
|
291
|
+
end
|
292
|
+
|
253
293
|
end
|
254
294
|
end
|
255
295
|
|
@@ -522,7 +562,7 @@ describe Dragonfly::Job do
|
|
522
562
|
@job.url.should be_nil
|
523
563
|
end
|
524
564
|
|
525
|
-
describe "using
|
565
|
+
describe "using url_attrs in the url" do
|
526
566
|
before(:each) do
|
527
567
|
@app.server.url_format = '/media/:job/:zoo'
|
528
568
|
@job.generate!(:fish)
|
@@ -533,33 +573,29 @@ describe Dragonfly::Job do
|
|
533
573
|
it "should add given params" do
|
534
574
|
@job.url(:zoo => 'jokes', :on => 'me').should == "/media/#{@job.serialize}/jokes?on=me"
|
535
575
|
end
|
536
|
-
it "should use the
|
537
|
-
@job.
|
576
|
+
it "should use the url_attr if it exists" do
|
577
|
+
@job.url_attrs[:zoo] = 'hair'
|
538
578
|
@job.url.should == "/media/#{@job.serialize}/hair"
|
539
579
|
end
|
540
|
-
it "should not add
|
541
|
-
@job.
|
580
|
+
it "should not add any url_attrs that aren't needed" do
|
581
|
+
@job.url_attrs[:gump] = 'flub'
|
542
582
|
@job.url.should == "/media/#{@job.serialize}"
|
543
583
|
end
|
544
584
|
it "should override if a param is passed in" do
|
545
|
-
@job.
|
585
|
+
@job.url_attrs[:zoo] = 'hair'
|
546
586
|
@job.url(:zoo => 'dare').should == "/media/#{@job.serialize}/dare"
|
547
587
|
end
|
548
588
|
|
549
589
|
describe "basename" do
|
550
590
|
before(:each) do
|
551
591
|
@app.server.url_format = '/:job/:basename'
|
552
|
-
@job.meta = {:name => 'hello.egg', :basename => 'hi'}
|
553
|
-
end
|
554
|
-
it "should use the meta if it exists" do
|
555
|
-
@job.url.should == "/#{@job.serialize}/hi"
|
556
592
|
end
|
557
|
-
it "should use the name
|
558
|
-
@job.
|
593
|
+
it "should use the name" do
|
594
|
+
@job.url_attrs = {:name => 'hello.egg'}
|
559
595
|
@job.url.should == "/#{@job.serialize}/hello"
|
560
596
|
end
|
561
597
|
it "should not set if neither exist" do
|
562
|
-
@job.
|
598
|
+
@job.url_attrs = {}
|
563
599
|
@job.url.should == "/#{@job.serialize}"
|
564
600
|
end
|
565
601
|
end
|
@@ -567,17 +603,14 @@ describe Dragonfly::Job do
|
|
567
603
|
describe "ext" do
|
568
604
|
before(:each) do
|
569
605
|
@app.server.url_format = '/:job.:ext'
|
570
|
-
@job.
|
606
|
+
@job.url_attrs = {:name => 'hello.egg', :ext => 'hi'}
|
571
607
|
end
|
572
|
-
it "should use the
|
573
|
-
@job.
|
574
|
-
end
|
575
|
-
it "should use the name if ext meta doesn't exist" do
|
576
|
-
@job.meta.delete(:ext)
|
608
|
+
it "should use the name" do
|
609
|
+
@job.url_attrs = {:name => 'hello.egg'}
|
577
610
|
@job.url.should == "/#{@job.serialize}.egg"
|
578
611
|
end
|
579
612
|
it "should not set if neither exist" do
|
580
|
-
@job.
|
613
|
+
@job.url_attrs = {}
|
581
614
|
@job.url.should == "/#{@job.serialize}"
|
582
615
|
end
|
583
616
|
end
|
@@ -585,21 +618,22 @@ describe Dragonfly::Job do
|
|
585
618
|
describe "format" do
|
586
619
|
before(:each) do
|
587
620
|
@app.server.url_format = '/:job.:format'
|
588
|
-
@job.stub!(:ext).and_return("hi")
|
589
621
|
end
|
590
|
-
it "should use the
|
591
|
-
@job.
|
622
|
+
it "should use the url_attr if it exists" do
|
623
|
+
@job.url_attrs = {:ext => 'hi', :format => :txt}
|
592
624
|
@job.url.should == "/#{@job.serialize}.txt"
|
593
625
|
end
|
594
|
-
it "should use the ext if format
|
626
|
+
it "should use the ext if format url_attr doesn't exist" do
|
627
|
+
@job.url_attrs = {:name => 'hup.hi'}
|
595
628
|
@job.url.should == "/#{@job.serialize}.hi"
|
596
629
|
end
|
597
630
|
it "should not use the ext if format meta doesn't exist and trust_file_extensions is switched off" do
|
631
|
+
@job.url_attrs = {:name => 'hup.hi'}
|
598
632
|
@app.trust_file_extensions = false
|
599
633
|
@job.url.should == "/#{@job.serialize}"
|
600
634
|
end
|
601
635
|
it "should not set if neither exist" do
|
602
|
-
@job.
|
636
|
+
@job.url_attrs = {}
|
603
637
|
@job.url.should == "/#{@job.serialize}"
|
604
638
|
end
|
605
639
|
end
|
@@ -624,6 +658,11 @@ describe Dragonfly::Job do
|
|
624
658
|
new_job = @job.to_fetched_job('some_uid')
|
625
659
|
new_job.meta.should == {:right => 'said fred'}
|
626
660
|
end
|
661
|
+
it "should maintain the url_attrs" do
|
662
|
+
@job.url_attrs = {:dang => 'that dawg'}
|
663
|
+
new_job = @job.to_fetched_job('some_uid')
|
664
|
+
new_job.url_attrs.should == {:dang => 'that dawg'}
|
665
|
+
end
|
627
666
|
end
|
628
667
|
|
629
668
|
describe "to_unique_s" do
|
@@ -811,7 +850,8 @@ describe Dragonfly::Job do
|
|
811
850
|
describe "meta" do
|
812
851
|
before(:each) do
|
813
852
|
@app = test_app
|
814
|
-
@
|
853
|
+
@app.generator.add(:gollum){|t| "OK"}
|
854
|
+
@job = @app.new_job("Goo")
|
815
855
|
end
|
816
856
|
it "should default meta to an empty hash" do
|
817
857
|
@job.meta.should == {}
|
@@ -820,10 +860,13 @@ describe Dragonfly::Job do
|
|
820
860
|
@job.meta = {:a => :b}
|
821
861
|
@job.meta.should == {:a => :b}
|
822
862
|
end
|
823
|
-
it "should
|
824
|
-
|
825
|
-
|
826
|
-
|
863
|
+
it "should apply the job" do
|
864
|
+
@job.should_receive :apply
|
865
|
+
@job.meta
|
866
|
+
end
|
867
|
+
it "should apply the job before setting (for consistency)" do
|
868
|
+
@job.should_receive :apply
|
869
|
+
@job.meta = {}
|
827
870
|
end
|
828
871
|
it "should allow setting on initialize" do
|
829
872
|
job = @app.new_job('asdf', :b => :c)
|
@@ -835,157 +878,120 @@ describe Dragonfly::Job do
|
|
835
878
|
end
|
836
879
|
end
|
837
880
|
|
838
|
-
describe "name" do
|
881
|
+
describe "sanity check for name, basename, ext" do
|
839
882
|
before(:each) do
|
840
883
|
@app = test_app
|
884
|
+
@job = @app.new_job('asdf')
|
841
885
|
end
|
886
|
+
|
842
887
|
it "should default to nil" do
|
843
|
-
job
|
844
|
-
job.name.should be_nil
|
888
|
+
@job.name.should be_nil
|
845
889
|
end
|
846
|
-
|
847
|
-
|
848
|
-
job.meta[:name] = 'monkey.egg'
|
849
|
-
job.name.should == 'monkey.egg'
|
890
|
+
|
891
|
+
it "reflect the meta" do
|
892
|
+
@job.meta[:name] = 'monkey.egg'
|
893
|
+
@job.name.should == 'monkey.egg'
|
894
|
+
@job.basename.should == 'monkey'
|
895
|
+
@job.ext.should == 'egg'
|
850
896
|
end
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
897
|
+
end
|
898
|
+
|
899
|
+
describe "format" do
|
900
|
+
before(:each) do
|
901
|
+
@app = test_app
|
855
902
|
end
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
@job = @app.new_job('asdf')
|
860
|
-
end
|
861
|
-
it "should use the correct extension from name" do
|
862
|
-
@job.name = 'hello.there.mate'
|
863
|
-
@job.ext.should == 'mate'
|
864
|
-
end
|
865
|
-
it "should be nil if name has none" do
|
866
|
-
@job.name = 'hello'
|
867
|
-
@job.ext.should be_nil
|
868
|
-
end
|
869
|
-
it "should be nil if name is nil" do
|
870
|
-
@job.name = nil
|
871
|
-
@job.ext.should be_nil
|
872
|
-
end
|
873
|
-
it "should use the meta first if set" do
|
874
|
-
@job.meta[:ext] = 'duggs'
|
875
|
-
@job.name = 'hello.there.mate'
|
876
|
-
@job.ext.should == 'duggs'
|
877
|
-
end
|
903
|
+
it "should default to nil" do
|
904
|
+
job = @app.new_job("HELLO")
|
905
|
+
job.format.should be_nil
|
878
906
|
end
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
end
|
884
|
-
it "should use the correct basename from name" do
|
885
|
-
@job.name = 'hello.there.mate'
|
886
|
-
@job.basename.should == 'hello.there'
|
887
|
-
end
|
888
|
-
it "should be the name if it has no ext" do
|
889
|
-
@job.name = 'hello'
|
890
|
-
@job.basename.should == 'hello'
|
891
|
-
end
|
892
|
-
it "should be nil if name is nil" do
|
893
|
-
@job.name = nil
|
894
|
-
@job.basename.should be_nil
|
895
|
-
end
|
896
|
-
it "should use the meta first if set" do
|
897
|
-
@job.meta[:basename] = 'duggs'
|
898
|
-
@job.name = 'hello.there.mate'
|
899
|
-
@job.basename.should == 'duggs'
|
900
|
-
end
|
907
|
+
it "should use the meta format if it exists" do
|
908
|
+
job = @app.new_job("HELLO")
|
909
|
+
job.meta[:format] = :txt
|
910
|
+
job.format.should == :txt
|
901
911
|
end
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
@app = test_app
|
906
|
-
end
|
907
|
-
it "should default to nil" do
|
908
|
-
job = @app.new_job("HELLO")
|
909
|
-
job.format.should be_nil
|
910
|
-
end
|
911
|
-
it "should use the meta format if it exists" do
|
912
|
-
job = @app.new_job("HELLO")
|
913
|
-
job.meta[:format] = :txt
|
914
|
-
job.format.should == :txt
|
915
|
-
end
|
916
|
-
it "should use the analyser format if it exists" do
|
917
|
-
@app.analyser.add :format do |temp_object|
|
918
|
-
:egg
|
919
|
-
end
|
920
|
-
job = @app.new_job("HELLO")
|
921
|
-
job.format.should == :egg
|
922
|
-
end
|
923
|
-
it "should use the file extension if it has no format" do
|
924
|
-
@job = @app.new_job("HIMATE", :name => 'test.pdf')
|
925
|
-
@job.format.should == :pdf
|
912
|
+
it "should use the analyser format if it exists" do
|
913
|
+
@app.analyser.add :format do |temp_object|
|
914
|
+
:egg
|
926
915
|
end
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
job.format.should == :burton
|
947
|
-
job.should be_applied
|
916
|
+
job = @app.new_job("HELLO")
|
917
|
+
job.format.should == :egg
|
918
|
+
end
|
919
|
+
it "should use the file extension if it has no format" do
|
920
|
+
job = @app.new_job("HIMATE", :name => 'test.pdf')
|
921
|
+
job.format.should == :pdf
|
922
|
+
end
|
923
|
+
it "should not use the file extension if it's been switched off" do
|
924
|
+
@app.trust_file_extensions = false
|
925
|
+
job = @app.new_job("HIMATE", :name => 'test.pdf')
|
926
|
+
job.format.should be_nil
|
927
|
+
end
|
928
|
+
it "should prefer the set format over the file extension" do
|
929
|
+
job = @app.new_job("HELLO", :name => 'test.pdf', :format => :txt)
|
930
|
+
job.format.should == :txt
|
931
|
+
end
|
932
|
+
it "should prefer the file extension over the analysed format" do
|
933
|
+
@app.analyser.add :format do |temp_object|
|
934
|
+
:egg
|
948
935
|
end
|
936
|
+
job = @app.new_job("HELLO", :name => 'test.pdf')
|
937
|
+
job.format.should == :pdf
|
938
|
+
end
|
939
|
+
it "should apply the job" do
|
940
|
+
@app.generator.add(:test){ ["skid marks", {:name => 'terry.burton'}] }
|
941
|
+
job = @app.generate(:test)
|
942
|
+
job.format.should == :burton
|
943
|
+
job.should be_applied
|
949
944
|
end
|
945
|
+
end
|
950
946
|
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
end
|
964
|
-
@job = @app.new_job("HIMATE")
|
965
|
-
@job.mime_type.should == 'image/jpeg'
|
966
|
-
end
|
967
|
-
it "should fall back to the fallback mime_type if neither format or analyser exist" do
|
968
|
-
@app.new_job("HIMATE").mime_type.should == 'application/octet-stream'
|
947
|
+
describe "mime_type" do
|
948
|
+
before(:each) do
|
949
|
+
@app = test_app
|
950
|
+
end
|
951
|
+
it "should return the correct mime_type if the format is given" do
|
952
|
+
@job = @app.new_job("HIMATE")
|
953
|
+
@job.should_receive(:format).and_return(:tiff)
|
954
|
+
@job.mime_type.should == 'image/tiff'
|
955
|
+
end
|
956
|
+
it "should fall back to the mime_type analyser if the format is nil" do
|
957
|
+
@app.analyser.add :mime_type do |temp_object|
|
958
|
+
'image/jpeg'
|
969
959
|
end
|
960
|
+
@job = @app.new_job("HIMATE")
|
961
|
+
@job.mime_type.should == 'image/jpeg'
|
962
|
+
end
|
963
|
+
it "should fall back to the fallback mime_type if neither format or analyser exist" do
|
964
|
+
@app.new_job("HIMATE").mime_type.should == 'application/octet-stream'
|
970
965
|
end
|
971
|
-
|
972
966
|
end
|
973
|
-
|
967
|
+
|
974
968
|
describe "store" do
|
975
969
|
before(:each) do
|
976
970
|
@app = test_app
|
977
971
|
@app.generator.add(:test){ ["Toes", {:name => 'doogie.txt'}] }
|
978
972
|
@job = @app.generate(:test)
|
979
973
|
end
|
980
|
-
it "should store its data along with the meta" do
|
974
|
+
it "should store its data along with the meta and mime_type" do
|
981
975
|
@job.meta[:eggs] = 'doolally'
|
982
|
-
@app.datastore.should_receive(:store).with
|
976
|
+
@app.datastore.should_receive(:store).with do |temp_object, opts|
|
977
|
+
temp_object.data.should == "Toes"
|
978
|
+
temp_object.name.should == 'doogie.txt'
|
979
|
+
temp_object.meta[:eggs].should == 'doolally'
|
980
|
+
opts[:mime_type].should == 'text/plain'
|
981
|
+
end
|
983
982
|
@job.store
|
984
983
|
end
|
985
984
|
it "should add extra opts" do
|
986
|
-
@app.datastore.should_receive(:store).with(
|
985
|
+
@app.datastore.should_receive(:store).with(anything, hash_including(:path => 'blah', :mime_type => 'text/plain'))
|
987
986
|
@job.store(:path => 'blah')
|
988
987
|
end
|
988
|
+
it "should pass in its meta, for deprecated datastores" do
|
989
|
+
@job.meta[:beans] = 5
|
990
|
+
@app.datastore.should_receive(:store).with do |temp_object, opts|
|
991
|
+
opts[:meta].should == {:beans => 5, :name => 'doogie.txt'}
|
992
|
+
end
|
993
|
+
@job.store
|
994
|
+
end
|
989
995
|
end
|
990
996
|
|
991
997
|
describe "dealing with original_filename" do
|