dragonfly 0.8.1 → 0.8.2

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.

@@ -159,7 +159,7 @@ describe Item do
159
159
  end
160
160
 
161
161
  it "should return the url for the data" do
162
- @app.should_receive(:url_for).with(an_instance_of(Dragonfly::Job)).and_return('some.url')
162
+ @app.should_receive(:url_for).with(an_instance_of(Dragonfly::Job), {}).and_return('some.url')
163
163
  @item.preview_image.url.should == 'some.url'
164
164
  end
165
165
 
@@ -44,7 +44,7 @@ describe Dragonfly::Analysis::FileCommandAnalyser do
44
44
  :tif => 'image/tiff'
45
45
  }.each do |format, mime_type|
46
46
  it "should work properly (without a broken pipe error) for big files of format #{format}" do
47
- data = Dragonfly::Generation::RMagickGenerator.new.plasma(1000, 1000, format).first
47
+ data = Dragonfly::Generation::ImageMagickGenerator.new.plasma(1000, 1000, format).first
48
48
  temp_object = Dragonfly::TempObject.new(data)
49
49
  @analyser.mime_type(temp_object).should == mime_type
50
50
  end
@@ -1,27 +1,31 @@
1
- require 'spec_helper'
2
- require 'dragonfly/analysis/shared_analyser_spec'
1
+ unless ENV['IGNORE_RMAGICK']
3
2
 
4
- describe Dragonfly::Analysis::RMagickAnalyser do
5
-
6
- before(:each) do
7
- image_path = File.dirname(__FILE__) + '/../../../samples/beach.png'
8
- @image = Dragonfly::TempObject.new(File.new(image_path))
9
- @analyser = Dragonfly::Analysis::RMagickAnalyser.new
10
- @analyser.log = Logger.new(LOG_FILE)
11
- end
3
+ require 'spec_helper'
4
+ require 'dragonfly/analysis/shared_analyser_spec'
5
+
6
+ describe Dragonfly::Analysis::RMagickAnalyser do
12
7
 
13
- describe "when using the filesystem" do
14
8
  before(:each) do
15
- @analyser.use_filesystem = true
9
+ image_path = File.dirname(__FILE__) + '/../../../samples/beach.png'
10
+ @image = Dragonfly::TempObject.new(File.new(image_path))
11
+ @analyser = Dragonfly::Analysis::RMagickAnalyser.new
12
+ @analyser.log = Logger.new(LOG_FILE)
16
13
  end
17
- it_should_behave_like "image analyser methods"
18
- end
19
14
 
20
- describe "when not using the filesystem" do
21
- before(:each) do
22
- @analyser.use_filesystem = false
15
+ describe "when using the filesystem" do
16
+ before(:each) do
17
+ @analyser.use_filesystem = true
18
+ end
19
+ it_should_behave_like "image analyser methods"
20
+ end
21
+
22
+ describe "when not using the filesystem" do
23
+ before(:each) do
24
+ @analyser.use_filesystem = false
25
+ end
26
+ it_should_behave_like "image analyser methods"
23
27
  end
24
- it_should_behave_like "image analyser methods"
25
- end
26
28
 
27
- end
29
+ end
30
+
31
+ end
@@ -1,25 +1,29 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ unless ENV['IGNORE_RMAGICK']
2
2
 
3
- describe Dragonfly::Config::RMagick do
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
- before(:each) do
6
- @app = test_app
7
- end
5
+ describe Dragonfly::Config::RMagick do
8
6
 
9
- it "should configure all to use the filesystem by default" do
10
- @app.configure_with(Dragonfly::Config::RMagick)
11
- @app.analyser.get_registered(Dragonfly::Analysis::RMagickAnalyser).use_filesystem.should be_true
12
- @app.processor.get_registered(Dragonfly::Processing::RMagickProcessor).use_filesystem.should be_true
13
- @app.encoder.get_registered(Dragonfly::Encoding::RMagickEncoder).use_filesystem.should be_true
14
- @app.generator.get_registered(Dragonfly::Generation::RMagickGenerator).use_filesystem.should be_true
15
- end
7
+ before(:each) do
8
+ @app = test_app
9
+ end
10
+
11
+ it "should configure all to use the filesystem by default" do
12
+ @app.configure_with(Dragonfly::Config::RMagick)
13
+ @app.analyser.get_registered(Dragonfly::Analysis::RMagickAnalyser).use_filesystem.should be_true
14
+ @app.processor.get_registered(Dragonfly::Processing::RMagickProcessor).use_filesystem.should be_true
15
+ @app.encoder.get_registered(Dragonfly::Encoding::RMagickEncoder).use_filesystem.should be_true
16
+ @app.generator.get_registered(Dragonfly::Generation::RMagickGenerator).use_filesystem.should be_true
17
+ end
18
+
19
+ it "should configure all not to use the filesystem if requested" do
20
+ @app.configure_with(Dragonfly::Config::RMagick, :use_filesystem => false)
21
+ @app.analyser.get_registered(Dragonfly::Analysis::RMagickAnalyser).use_filesystem.should be_false
22
+ @app.processor.get_registered(Dragonfly::Processing::RMagickProcessor).use_filesystem.should be_false
23
+ @app.encoder.get_registered(Dragonfly::Encoding::RMagickEncoder).use_filesystem.should be_false
24
+ @app.generator.get_registered(Dragonfly::Generation::RMagickGenerator).use_filesystem.should be_false
25
+ end
16
26
 
17
- it "should configure all not to use the filesystem if requested" do
18
- @app.configure_with(Dragonfly::Config::RMagick, :use_filesystem => false)
19
- @app.analyser.get_registered(Dragonfly::Analysis::RMagickAnalyser).use_filesystem.should be_false
20
- @app.processor.get_registered(Dragonfly::Processing::RMagickProcessor).use_filesystem.should be_false
21
- @app.encoder.get_registered(Dragonfly::Encoding::RMagickEncoder).use_filesystem.should be_false
22
- @app.generator.get_registered(Dragonfly::Generation::RMagickGenerator).use_filesystem.should be_false
23
27
  end
24
28
 
25
- end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+
5
+ describe "to_dragonfly_unique_s" do
6
+ it "should concatenate the to_s's of each of the elements" do
7
+ [:a, true, 2, 5.2, "hello"].to_dragonfly_unique_s.should == 'atrue25.2hello'
8
+ end
9
+
10
+ it "should nest arrays" do
11
+ [:a, [:b, :c], :d].to_dragonfly_unique_s.should == 'abcd'
12
+ end
13
+
14
+ it "should be empty if empty" do
15
+ [].to_dragonfly_unique_s.should == ''
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+
5
+ describe "to_dragonfly_unique_s" do
6
+ it "should concatenate the to_s's of each of the elements, sorted alphabetically" do
7
+ {'z' => nil, :a => 4, false => 'ice', 5 => 6.2}.to_dragonfly_unique_s.should == '56.2a4falseicez'
8
+ end
9
+
10
+ it "should nest correctly" do
11
+ {:m => 1, :a => {:c => 2, :b => 3}, :z => 4}.to_dragonfly_unique_s.should == 'ab3c2m1z4'
12
+ end
13
+
14
+ it "should be empty if empty" do
15
+ {}.to_dragonfly_unique_s.should == ''
16
+ end
17
+ end
18
+
19
+ end
@@ -1,37 +1,41 @@
1
- require 'spec_helper'
1
+ unless ENV['IGNORE_RMAGICK']
2
2
 
3
- describe Dragonfly::Encoding::RMagickEncoder do
3
+ require 'spec_helper'
4
+
5
+ describe Dragonfly::Encoding::RMagickEncoder do
4
6
 
5
- before(:all) do
6
- sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
7
- @image = Dragonfly::TempObject.new(File.new(sample_file))
8
- @encoder = Dragonfly::Encoding::RMagickEncoder.new
9
- end
7
+ before(:all) do
8
+ sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
9
+ @image = Dragonfly::TempObject.new(File.new(sample_file))
10
+ @encoder = Dragonfly::Encoding::RMagickEncoder.new
11
+ end
10
12
 
11
- describe "#encode" do
13
+ describe "#encode" do
12
14
 
13
- it "should encode the image to the correct format" do
14
- image = @encoder.encode(@image, :gif)
15
- image.should have_format('gif')
16
- end
15
+ it "should encode the image to the correct format" do
16
+ image = @encoder.encode(@image, :gif)
17
+ image.should have_format('gif')
18
+ end
17
19
 
18
- it "should throw :unable_to_handle if the format is not handleable" do
19
- lambda{
20
- @encoder.encode(@image, :goofy)
21
- }.should throw_symbol(:unable_to_handle)
22
- end
20
+ it "should throw :unable_to_handle if the format is not handleable" do
21
+ lambda{
22
+ @encoder.encode(@image, :goofy)
23
+ }.should throw_symbol(:unable_to_handle)
24
+ end
23
25
 
24
- it "should do nothing if the image is already in the correct format" do
25
- image = @encoder.encode(@image, :png)
26
- image.should == @image
27
- end
26
+ it "should do nothing if the image is already in the correct format" do
27
+ image = @encoder.encode(@image, :png)
28
+ image.should == @image
29
+ end
28
30
 
29
- it "should work when not using the filesystem" do
30
- @encoder.use_filesystem = false
31
- image = @encoder.encode(@image, :gif)
32
- image.should have_format('gif')
33
- end
31
+ it "should work when not using the filesystem" do
32
+ @encoder.use_filesystem = false
33
+ image = @encoder.encode(@image, :gif)
34
+ image.should have_format('gif')
35
+ end
34
36
 
35
- end
37
+ end
36
38
 
39
+ end
40
+
37
41
  end
@@ -1,24 +1,28 @@
1
- require 'spec_helper'
2
- require 'dragonfly/generation/shared_generator_spec'
1
+ unless ENV['IGNORE_RMAGICK']
3
2
 
4
- describe Dragonfly::Generation::RMagickGenerator do
3
+ require 'spec_helper'
4
+ require 'dragonfly/generation/shared_generator_spec'
5
5
 
6
- before(:each) do
7
- @generator = Dragonfly::Generation::RMagickGenerator.new
8
- end
6
+ describe Dragonfly::Generation::RMagickGenerator do
9
7
 
10
- describe "when using the filesystem" do
11
8
  before(:each) do
12
- @generator.use_filesystem = true
9
+ @generator = Dragonfly::Generation::RMagickGenerator.new
10
+ end
11
+
12
+ describe "when using the filesystem" do
13
+ before(:each) do
14
+ @generator.use_filesystem = true
15
+ end
16
+ it_should_behave_like 'image generator'
13
17
  end
14
- it_should_behave_like 'image generator'
15
- end
16
18
 
17
- describe "when not using the filesystem" do
18
- before(:each) do
19
- @generator.use_filesystem = false
19
+ describe "when not using the filesystem" do
20
+ before(:each) do
21
+ @generator.use_filesystem = false
22
+ end
23
+ it_should_behave_like 'image generator'
20
24
  end
21
- it_should_behave_like 'image generator'
22
- end
23
25
 
24
- end
26
+ end
27
+
28
+ end
@@ -3,11 +3,41 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
4
  ## General tests for Response go here as it's a pretty simple wrapper around that
5
5
 
6
+ describe "Dragonfly::JobEndpoint Rack::Lint tests" do
7
+ before(:each) do
8
+ @app = test_app
9
+ @app.generator.add(:test_data){ "Test Data" }
10
+ @job = Dragonfly::Job.new(@app).generate(:test_data)
11
+ @endpoint = Rack::Lint.new(Dragonfly::JobEndpoint.new(@job))
12
+ end
13
+
14
+ it "should pass for HEAD requests" do
15
+ Rack::MockRequest.new(@endpoint).request("HEAD", '')
16
+ end
17
+
18
+ it "should pass for GET requests" do
19
+ Rack::MockRequest.new(@endpoint).request("GET", '')
20
+ end
21
+
22
+ it "should pass for POST requests" do
23
+ Rack::MockRequest.new(@endpoint).request("POST", '')
24
+ end
25
+
26
+ it "should pass for PUT requests" do
27
+ Rack::MockRequest.new(@endpoint).request("PUT", '')
28
+ end
29
+
30
+ it "should pass for DELETE requests" do
31
+ Rack::MockRequest.new(@endpoint).request("DELETE", '')
32
+ end
33
+ end
34
+
6
35
  describe Dragonfly::JobEndpoint do
7
36
 
8
37
  def make_request(job, opts={})
9
38
  endpoint = Dragonfly::JobEndpoint.new(job)
10
- Rack::MockRequest.new(endpoint).get('', opts)
39
+ method = (opts.delete(:method) || :get).to_s.upcase
40
+ Rack::MockRequest.new(endpoint).request(method, '', opts)
11
41
  end
12
42
 
13
43
  before(:each) do
@@ -16,7 +46,7 @@ describe Dragonfly::JobEndpoint do
16
46
  @job = Dragonfly::Job.new(@app).fetch('egg')
17
47
  end
18
48
 
19
- it "should return a correct response if successful" do
49
+ it "should return a correct response to a successful GET request" do
20
50
  response = make_request(@job)
21
51
  response.status.should == 200
22
52
  response['ETag'].should =~ /^"\w+"$/
@@ -27,6 +57,29 @@ describe Dragonfly::JobEndpoint do
27
57
  response.body.should == 'GUNGLE'
28
58
  end
29
59
 
60
+ it "should return the correct headers and no content to a successful HEAD request" do
61
+ response = make_request(@job, :method => :head)
62
+ response.status.should == 200
63
+ response['ETag'].should =~ /^"\w+"$/
64
+ response['Cache-Control'].should == "public, max-age=31536000"
65
+ response['Content-Type'].should == 'text/plain'
66
+ response['Content-Length'].should == '6'
67
+ response['Content-Disposition'].should == 'filename="gung.txt"'
68
+ response.body.should == ''
69
+ end
70
+
71
+ %w(POST PUT DELETE CUSTOM_METHOD).each do |method|
72
+
73
+ it "should return a 405 error for a #{method} request" do
74
+ response = make_request(@job, :method => method)
75
+ response.status.should == 405
76
+ response['Allow'].should == "GET, HEAD"
77
+ response['Content-Type'].should == 'text/plain'
78
+ response.body.should == "#{method} method not allowed"
79
+ end
80
+
81
+ end
82
+
30
83
  it "should return 404 if the datastore raises data not found" do
31
84
  @job.should_receive(:apply).and_raise(Dragonfly::DataStorage::DataNotFound)
32
85
  response = make_request(@job)
@@ -100,7 +153,7 @@ describe Dragonfly::JobEndpoint do
100
153
  response['Content-Disposition'].should be_nil
101
154
  end
102
155
  end
103
-
156
+
104
157
  describe "content disposition" do
105
158
  it "should use the app's configured content-disposition" do
106
159
  @app.content_disposition = :attachment
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  # Matchers
4
4
  Spec::Matchers.define :match_steps do |steps|
@@ -530,7 +530,7 @@ describe Dragonfly::Job do
530
530
  describe "serialization" do
531
531
  before(:each) do
532
532
  @app = test_app
533
- @job = Dragonfly::Job.new(@app).fetch('mumma').process(:resize, '1x50')
533
+ @job = Dragonfly::Job.new(@app).fetch('uid').process(:resize_and_crop, :width => 270, :height => 92, :gravity => 'n')
534
534
  end
535
535
  it "should serialize itself" do
536
536
  @job.serialize.should =~ /^\w{1,}$/
@@ -539,6 +539,14 @@ describe Dragonfly::Job do
539
539
  new_job = Dragonfly::Job.deserialize(@job.serialize, @app)
540
540
  new_job.to_a.should == @job.to_a
541
541
  end
542
+ it "should correctly deserialize a string serialized with ruby 1.8.7" do
543
+ job = Dragonfly::Job.deserialize('BAhbB1sHOgZmSSIIdWlkBjoGRVRbCDoGcDoUcmVzaXplX2FuZF9jcm9wewg6CndpZHRoaQIOAToLaGVpZ2h0aWE6DGdyYXZpdHlJIgZuBjsGVA', @app)
544
+ job.to_a.should == @job.to_a
545
+ end
546
+ it "should correctly deserialize a string serialized with ruby 1.9.2" do
547
+ job = Dragonfly::Job.deserialize('BAhbB1sHOgZmIgh1aWRbCDoGcDoUcmVzaXplX2FuZF9jcm9wewg6CndpZHRoaQIOAToLaGVpZ2h0aWE6DGdyYXZpdHkiBm4', @app)
548
+ job.to_a.should == @job.to_a
549
+ end
542
550
  end
543
551
 
544
552
  describe "to_app" do
@@ -608,6 +616,32 @@ describe Dragonfly::Job do
608
616
  end
609
617
  end
610
618
 
619
+ describe "to_unique_s" do
620
+ it "should use the arrays of args to create the string" do
621
+ job = test_app.fetch('uid').process(:gug, 4, :some => 'arg', :and => 'more')
622
+ job.to_unique_s.should == 'fuidpgug4andmoresomearg'
623
+ end
624
+ end
625
+
626
+ describe "sha" do
627
+ before(:each) do
628
+ @app = test_app
629
+ @job = @app.fetch('eggs')
630
+ end
631
+
632
+ it "should be of the correct format" do
633
+ @job.sha.should =~ /^\w{8}$/
634
+ end
635
+
636
+ it "should be the same for the same job steps" do
637
+ @app.fetch('eggs').sha.should == @job.sha
638
+ end
639
+
640
+ it "should be different for different jobs" do
641
+ @app.fetch('figs').sha.should_not == @job.sha
642
+ end
643
+ end
644
+
611
645
  describe "validate_sha!" do
612
646
  before(:each) do
613
647
  @app = test_app
@@ -1,26 +1,30 @@
1
- require 'spec_helper'
2
- require 'dragonfly/processing/shared_processing_spec'
1
+ unless ENV['IGNORE_RMAGICK']
3
2
 
4
- describe Dragonfly::Processing::RMagickProcessor do
5
-
6
- before(:each) do
7
- sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
8
- @image = Dragonfly::TempObject.new(File.new(sample_file))
9
- @processor = Dragonfly::Processing::RMagickProcessor.new
10
- end
3
+ require 'spec_helper'
4
+ require 'dragonfly/processing/shared_processing_spec'
11
5
 
12
- describe "when using the filesystem" do
6
+ describe Dragonfly::Processing::RMagickProcessor do
7
+
13
8
  before(:each) do
14
- @processor.use_filesystem = true
9
+ sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
10
+ @image = Dragonfly::TempObject.new(File.new(sample_file))
11
+ @processor = Dragonfly::Processing::RMagickProcessor.new
15
12
  end
16
- it_should_behave_like "processing methods"
17
- end
18
13
 
19
- describe "when not using the filesystem" do
20
- before(:each) do
21
- @processor.use_filesystem = false
14
+ describe "when using the filesystem" do
15
+ before(:each) do
16
+ @processor.use_filesystem = true
17
+ end
18
+ it_should_behave_like "processing methods"
19
+ end
20
+
21
+ describe "when not using the filesystem" do
22
+ before(:each) do
23
+ @processor.use_filesystem = false
24
+ end
25
+ it_should_behave_like "processing methods"
22
26
  end
23
- it_should_behave_like "processing methods"
24
- end
25
27
 
28
+ end
29
+
26
30
  end