dragonfly 0.7.5 → 0.7.6

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.

@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  describe Dragonfly::TempObject do
4
-
4
+
5
5
  ####### Helper Methods #######
6
6
 
7
7
  def sample_path(filename)
@@ -14,23 +14,23 @@ describe Dragonfly::TempObject do
14
14
  tempfile.rewind
15
15
  tempfile
16
16
  end
17
-
17
+
18
18
  def new_file(data='HELLO')
19
19
  File.open('/tmp/test_file', 'w') do |f|
20
20
  f.write(data)
21
21
  end
22
22
  File.new('/tmp/test_file')
23
23
  end
24
-
24
+
25
25
  def new_temp_object(data, opts={})
26
26
  klass = opts.delete(:class) || Dragonfly::TempObject
27
27
  klass.new(initialization_object(data), opts)
28
28
  end
29
-
29
+
30
30
  def initialization_object(data)
31
31
  raise NotImplementedError, "This should be implemented in the describe block!"
32
32
  end
33
-
33
+
34
34
  def get_parts(temp_object)
35
35
  parts = []
36
36
  temp_object.each do |bytes|
@@ -39,15 +39,15 @@ describe Dragonfly::TempObject do
39
39
  parts.length.should >= 2 # Sanity check to check that the sample file is adequate for this test
40
40
  parts
41
41
  end
42
-
42
+
43
43
  ###############################
44
-
44
+
45
45
  it "should raise an error if initialized with a non-string/file/tempfile" do
46
46
  lambda{
47
47
  Dragonfly::TempObject.new(3)
48
48
  }.should raise_error(ArgumentError)
49
49
  end
50
-
50
+
51
51
  describe "common behaviour", :shared => true do
52
52
 
53
53
  describe "simple initialization" do
@@ -91,13 +91,13 @@ describe Dragonfly::TempObject do
91
91
  @temp_object.tempfile.open.read.should == 'HELLO'
92
92
  end
93
93
  end
94
-
94
+
95
95
  describe "path" do
96
96
  it "should return the absolute file path" do
97
97
  @temp_object.path.should == @temp_object.tempfile.path
98
98
  end
99
99
  end
100
-
100
+
101
101
  describe "size" do
102
102
  it "should return the size in bytes" do
103
103
  @temp_object.size.should == 5
@@ -126,7 +126,7 @@ describe Dragonfly::TempObject do
126
126
  file.read.should == 'HELLO'
127
127
  end
128
128
  end
129
-
129
+
130
130
  end
131
131
 
132
132
  describe "initializing attributes too" do
@@ -169,10 +169,10 @@ describe Dragonfly::TempObject do
169
169
  parts.last.length.should <= 3001
170
170
  end
171
171
  end
172
-
172
+
173
173
 
174
174
  end
175
-
175
+
176
176
  describe "initializing from a string" do
177
177
 
178
178
  def initialization_object(data)
@@ -187,7 +187,7 @@ describe Dragonfly::TempObject do
187
187
  temp_object.each{}
188
188
  end
189
189
  end
190
-
190
+
191
191
  describe "initializing from a tempfile" do
192
192
 
193
193
  def initialization_object(data)
@@ -202,7 +202,7 @@ describe Dragonfly::TempObject do
202
202
  temp_object.each{}
203
203
  end
204
204
  end
205
-
205
+
206
206
  describe "initializing from a file" do
207
207
 
208
208
  def initialization_object(data)
@@ -217,7 +217,7 @@ describe Dragonfly::TempObject do
217
217
  temp_object.each{}
218
218
  end
219
219
  end
220
-
220
+
221
221
  describe "initializing from another temp object" do
222
222
  before(:each) do
223
223
  @temp_object1 = Dragonfly::TempObject.new(new_tempfile('hello'))
@@ -233,7 +233,7 @@ describe Dragonfly::TempObject do
233
233
  @temp_object1.path.should_not == @temp_object2.path
234
234
  end
235
235
  end
236
-
236
+
237
237
  describe "name" do
238
238
  before(:each) do
239
239
  @obj = new_tempfile
@@ -256,8 +256,13 @@ describe Dragonfly::TempObject do
256
256
  temp_object = Dragonfly::TempObject.new('sdf', :name => '')
257
257
  temp_object.name.should be_nil
258
258
  end
259
+ it "should allow setting" do
260
+ temp_object = Dragonfly::TempObject.new('sdf')
261
+ temp_object.name = "jonny.briggs"
262
+ temp_object.name.should == 'jonny.briggs'
263
+ end
259
264
  end
260
-
265
+
261
266
  describe "ext" do
262
267
  it "should use the correct extension from name" do
263
268
  temp_object = Dragonfly::TempObject.new('asfsadf', :name => 'hello.there.mate')
@@ -287,7 +292,7 @@ describe Dragonfly::TempObject do
287
292
  temp_object.basename.should be_nil
288
293
  end
289
294
  end
290
-
295
+
291
296
  describe "meta" do
292
297
  before(:each) do
293
298
  @temp_object = Dragonfly::TempObject.new('get outta here!')
@@ -296,11 +301,11 @@ describe Dragonfly::TempObject do
296
301
  @temp_object.meta.should == {}
297
302
  end
298
303
  it "should allow setting" do
299
- @temp_object.meta[:teeth] = 'many'
304
+ @temp_object.meta = {:teeth => 'many'}
300
305
  @temp_object.meta.should == {:teeth => 'many'}
301
306
  end
302
307
  end
303
-
308
+
304
309
  describe "format" do
305
310
  it "should return nil if not set" do
306
311
  temp_object = Dragonfly::TempObject.new('wassin my belly??!')
@@ -310,19 +315,28 @@ describe Dragonfly::TempObject do
310
315
  temp_object = Dragonfly::TempObject.new('wassin my belly??!', :format => :jpg)
311
316
  temp_object.format.should == :jpg
312
317
  end
318
+ it "should allow setting" do
319
+ temp_object = Dragonfly::TempObject.new('jo*ida pero contenta')
320
+ temp_object.format = :tiff
321
+ temp_object.format.should == :tiff
322
+ end
313
323
  end
314
-
324
+
315
325
  describe "extract_attributes_from" do
316
326
  before(:each) do
317
327
  @temp_object = Dragonfly::TempObject.new("ne'er gonna give you up",
318
328
  :meta => {:a => 4},
319
- :name => 'fred.txt'
329
+ :name => 'fred.txt',
330
+ :format => :txt
320
331
  )
321
- @attributes = {:meta => {:b => 5}, :ogle => 'bogle'}
332
+ @attributes = {:meta => {:b => 5}, :ogle => 'bogle', :format => :dungbats}
322
333
  @temp_object.extract_attributes_from(@attributes)
323
334
  end
324
335
  it "should overwrite its own attributes if specified" do
325
- @temp_object.meta.should == {:b => 5}
336
+ @temp_object.format.should == :dungbats
337
+ end
338
+ it "should merge its own meta if specified" do
339
+ @temp_object.meta.should == {:a => 4, :b => 5}
326
340
  end
327
341
  it "should leave non-specified attributes untouched" do
328
342
  @temp_object.name.should == 'fred.txt'
@@ -2,7 +2,7 @@ def match_url(url)
2
2
  simple_matcher("match url #{url}") do |given|
3
3
  given_path, given_query_string = given.split('?')
4
4
  path, query_string = url.split('?')
5
-
5
+
6
6
  path == given_path && given_query_string.split('&').sort == query_string.split('&').sort
7
7
  end
8
8
  end
@@ -22,7 +22,7 @@ def match_ar_error(string)
22
22
  end
23
23
 
24
24
  def include_hash(hash)
25
- simple_matcher("include hash #{hash}") do |given|
25
+ simple_matcher("include hash #{hash.inspect}") do |given|
26
26
  given.merge(hash) == given
27
27
  end
28
28
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 5
9
- version: 0.7.5
8
+ - 6
9
+ version: 0.7.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Evans
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-01 00:00:00 +01:00
17
+ date: 2010-09-12 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -113,7 +113,6 @@ files:
113
113
  - lib/dragonfly/data_storage/s3data_store.rb
114
114
  - lib/dragonfly/encoder.rb
115
115
  - lib/dragonfly/encoding/r_magick_encoder.rb
116
- - lib/dragonfly/endpoint.rb
117
116
  - lib/dragonfly/function_manager.rb
118
117
  - lib/dragonfly/generation/r_magick_generator.rb
119
118
  - lib/dragonfly/generator.rb
@@ -127,6 +126,7 @@ files:
127
126
  - lib/dragonfly/processor.rb
128
127
  - lib/dragonfly/r_magick_utils.rb
129
128
  - lib/dragonfly/rails/images.rb
129
+ - lib/dragonfly/response.rb
130
130
  - lib/dragonfly/routed_endpoint.rb
131
131
  - lib/dragonfly/serializer.rb
132
132
  - lib/dragonfly/simple_cache.rb
@@ -1,43 +0,0 @@
1
- module Dragonfly
2
- module Endpoint
3
-
4
- class EmptyJob < StandardError; end
5
-
6
- private
7
-
8
- def response_for_job(job, env)
9
- if etag_matches?(job, env)
10
- [304, cache_headers(job), []]
11
- else
12
- [200, success_headers(job), job.result] # Successful response
13
- end
14
- rescue DataStorage::DataNotFound => e
15
- [404, {"Content-Type" => 'text/plain'}, [e.message]]
16
- end
17
-
18
- def cache_headers(job)
19
- {
20
- "Cache-Control" => "public, max-age=#{job.app.cache_duration}",
21
- "ETag" => %("#{job.unique_signature}")
22
- }
23
- end
24
-
25
- def etag_matches?(job, env)
26
- if_none_match = env['HTTP_IF_NONE_MATCH']
27
- if if_none_match
28
- if_none_match.tr!('"','')
29
- if_none_match.split(',').include?(job.unique_signature) || if_none_match == '*'
30
- else
31
- false
32
- end
33
- end
34
-
35
- def success_headers(job)
36
- {
37
- "Content-Type" => job.app.resolve_mime_type(job.result),
38
- "Content-Length" => job.size.to_s,
39
- }.merge(cache_headers(job))
40
- end
41
-
42
- end
43
- end