fog-dragonfly 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fog-dragonfly might be problematic. Click here for more details.
- data/.specopts +2 -0
- data/.yardopts +23 -0
- data/Gemfile +23 -0
- data/Gemfile.rails.2.3.5 +14 -0
- data/History.md +266 -0
- data/LICENSE +20 -0
- data/README.md +88 -0
- data/Rakefile +92 -0
- data/VERSION +1 -0
- data/config.ru +13 -0
- data/docs.watchr +1 -0
- data/dragonfly.gemspec +293 -0
- data/extra_docs/Analysers.md +108 -0
- data/extra_docs/Caching.md +23 -0
- data/extra_docs/Configuration.md +138 -0
- data/extra_docs/DataStorage.md +136 -0
- data/extra_docs/Encoding.md +96 -0
- data/extra_docs/GeneralUsage.md +121 -0
- data/extra_docs/Generators.md +102 -0
- data/extra_docs/Heroku.md +50 -0
- data/extra_docs/Index.md +36 -0
- data/extra_docs/MimeTypes.md +40 -0
- data/extra_docs/Models.md +266 -0
- data/extra_docs/Mongo.md +45 -0
- data/extra_docs/Processing.md +130 -0
- data/extra_docs/Rack.md +52 -0
- data/extra_docs/Rails2.md +55 -0
- data/extra_docs/Rails3.md +62 -0
- data/extra_docs/Sinatra.md +25 -0
- data/extra_docs/URLs.md +169 -0
- data/features/3.0.3.feature +8 -0
- data/features/images.feature +47 -0
- data/features/no_processing.feature +14 -0
- data/features/rails_2.3.5.feature +7 -0
- data/features/steps/common_steps.rb +8 -0
- data/features/steps/dragonfly_steps.rb +66 -0
- data/features/steps/rails_steps.rb +39 -0
- data/features/support/env.rb +40 -0
- data/fixtures/files/app/models/album.rb +3 -0
- data/fixtures/files/app/views/albums/new.html.erb +4 -0
- data/fixtures/files/app/views/albums/show.html.erb +4 -0
- data/fixtures/files/config/initializers/dragonfly.rb +4 -0
- data/fixtures/files/features/manage_album_images.feature +12 -0
- data/fixtures/files/features/step_definitions/image_steps.rb +15 -0
- data/fixtures/files/features/support/paths.rb +15 -0
- data/fixtures/files/features/text_images.feature +7 -0
- data/fixtures/rails_2.3.5/template.rb +10 -0
- data/fixtures/rails_3.0.3/template.rb +20 -0
- data/irbrc.rb +17 -0
- data/lib/dragonfly.rb +45 -0
- data/lib/dragonfly/active_model_extensions.rb +13 -0
- data/lib/dragonfly/active_model_extensions/attachment.rb +169 -0
- data/lib/dragonfly/active_model_extensions/class_methods.rb +45 -0
- data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
- data/lib/dragonfly/active_model_extensions/validations.rb +37 -0
- data/lib/dragonfly/analyser.rb +59 -0
- data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
- data/lib/dragonfly/analysis/image_magick_analyser.rb +47 -0
- data/lib/dragonfly/analysis/r_magick_analyser.rb +63 -0
- data/lib/dragonfly/app.rb +182 -0
- data/lib/dragonfly/config/heroku.rb +19 -0
- data/lib/dragonfly/config/image_magick.rb +41 -0
- data/lib/dragonfly/config/r_magick.rb +46 -0
- data/lib/dragonfly/config/rails.rb +17 -0
- data/lib/dragonfly/configurable.rb +119 -0
- data/lib/dragonfly/core_ext/object.rb +8 -0
- data/lib/dragonfly/core_ext/string.rb +9 -0
- data/lib/dragonfly/core_ext/symbol.rb +9 -0
- data/lib/dragonfly/data_storage.rb +9 -0
- data/lib/dragonfly/data_storage/file_data_store.rb +114 -0
- data/lib/dragonfly/data_storage/mongo_data_store.rb +82 -0
- data/lib/dragonfly/data_storage/s3data_store.rb +115 -0
- data/lib/dragonfly/encoder.rb +13 -0
- data/lib/dragonfly/encoding/image_magick_encoder.rb +57 -0
- data/lib/dragonfly/encoding/r_magick_encoder.rb +61 -0
- data/lib/dragonfly/function_manager.rb +69 -0
- data/lib/dragonfly/generation/hash_with_css_style_keys.rb +23 -0
- data/lib/dragonfly/generation/image_magick_generator.rb +140 -0
- data/lib/dragonfly/generation/r_magick_generator.rb +155 -0
- data/lib/dragonfly/generator.rb +9 -0
- data/lib/dragonfly/image_magick_utils.rb +81 -0
- data/lib/dragonfly/job.rb +371 -0
- data/lib/dragonfly/job_builder.rb +39 -0
- data/lib/dragonfly/job_definitions.rb +26 -0
- data/lib/dragonfly/job_endpoint.rb +15 -0
- data/lib/dragonfly/loggable.rb +28 -0
- data/lib/dragonfly/middleware.rb +34 -0
- data/lib/dragonfly/processing/image_magick_processor.rb +99 -0
- data/lib/dragonfly/processing/r_magick_processor.rb +126 -0
- data/lib/dragonfly/processor.rb +9 -0
- data/lib/dragonfly/r_magick_utils.rb +48 -0
- data/lib/dragonfly/rails/images.rb +22 -0
- data/lib/dragonfly/response.rb +82 -0
- data/lib/dragonfly/routed_endpoint.rb +40 -0
- data/lib/dragonfly/serializer.rb +32 -0
- data/lib/dragonfly/simple_cache.rb +23 -0
- data/lib/dragonfly/simple_endpoint.rb +63 -0
- data/lib/dragonfly/temp_object.rb +220 -0
- data/samples/beach.png +0 -0
- data/samples/egg.png +0 -0
- data/samples/round.gif +0 -0
- data/samples/sample.docx +0 -0
- data/samples/taj.jpg +0 -0
- data/spec/argument_matchers.rb +19 -0
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +723 -0
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
- data/spec/dragonfly/analyser_spec.rb +123 -0
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +57 -0
- data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +15 -0
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +27 -0
- data/spec/dragonfly/analysis/shared_analyser_spec.rb +51 -0
- data/spec/dragonfly/app_spec.rb +280 -0
- data/spec/dragonfly/config/r_magick_spec.rb +25 -0
- data/spec/dragonfly/configurable_spec.rb +220 -0
- data/spec/dragonfly/core_ext/string_spec.rb +17 -0
- data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
- data/spec/dragonfly/data_storage/data_store_spec.rb +76 -0
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +169 -0
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +38 -0
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +94 -0
- data/spec/dragonfly/deprecation_spec.rb +20 -0
- data/spec/dragonfly/encoding/image_magick_encoder_spec.rb +41 -0
- data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +37 -0
- data/spec/dragonfly/function_manager_spec.rb +154 -0
- data/spec/dragonfly/generation/hash_with_css_style_keys_spec.rb +24 -0
- data/spec/dragonfly/generation/image_magick_generator_spec.rb +12 -0
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +24 -0
- data/spec/dragonfly/generation/shared_generator_spec.rb +91 -0
- data/spec/dragonfly/image_magick_utils_spec.rb +16 -0
- data/spec/dragonfly/job_builder_spec.rb +37 -0
- data/spec/dragonfly/job_definitions_spec.rb +35 -0
- data/spec/dragonfly/job_endpoint_spec.rb +120 -0
- data/spec/dragonfly/job_spec.rb +773 -0
- data/spec/dragonfly/loggable_spec.rb +80 -0
- data/spec/dragonfly/middleware_spec.rb +68 -0
- data/spec/dragonfly/processing/image_magick_processor_spec.rb +29 -0
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +26 -0
- data/spec/dragonfly/processing/shared_processing_spec.rb +215 -0
- data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
- data/spec/dragonfly/serializer_spec.rb +61 -0
- data/spec/dragonfly/simple_cache_spec.rb +27 -0
- data/spec/dragonfly/simple_endpoint_spec.rb +89 -0
- data/spec/dragonfly/temp_object_spec.rb +352 -0
- data/spec/image_matchers.rb +47 -0
- data/spec/simple_matchers.rb +44 -0
- data/spec/spec_helper.rb +58 -0
- data/yard/handlers/configurable_attr_handler.rb +38 -0
- data/yard/setup.rb +15 -0
- data/yard/templates/default/fulldoc/html/css/common.css +107 -0
- data/yard/templates/default/layout/html/layout.erb +87 -0
- data/yard/templates/default/module/html/configuration_summary.erb +31 -0
- data/yard/templates/default/module/setup.rb +17 -0
- metadata +550 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'active_model'
|
5
|
+
rescue LoadError => e
|
6
|
+
# When there's NO active_model
|
7
|
+
require File.dirname(__FILE__) + '/active_record_setup'
|
8
|
+
else
|
9
|
+
# When there IS active model
|
10
|
+
require File.dirname(__FILE__) + '/active_model_setup'
|
11
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Dragonfly::Analyser do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@analyser = Dragonfly::Analyser.new
|
7
|
+
@analyser.log = Logger.new(LOG_FILE)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "analysis_methods module" do
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@analyser.add(:num_letters){|temp_object, letter| temp_object.data.count(letter) }
|
14
|
+
@obj = Object.new
|
15
|
+
@obj.extend @analyser.analysis_methods
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return a module" do
|
19
|
+
@analyser.analysis_methods.should be_a(Module)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should provide the object with the analyser method" do
|
23
|
+
@obj.analyser.should == @analyser
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should provide the object with the direct analysis method, provided that analyse method exists" do
|
27
|
+
def @obj.analyse(meth, *args)
|
28
|
+
analyser.analyse Dragonfly::TempObject.new('HELLO'), meth, *args
|
29
|
+
end
|
30
|
+
@obj.num_letters('L').should == 2
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "analyse" do
|
36
|
+
it "should return nil if the function isn't defined" do
|
37
|
+
@analyser.analyse(Dragonfly::TempObject.new("Hello"), :width).should be_nil
|
38
|
+
end
|
39
|
+
it "should return nil if the function can't be handled" do
|
40
|
+
@analyser.add(:width){ throw :unable_to_handle }
|
41
|
+
@analyser.analyse(Dragonfly::TempObject.new("Hello"), :width).should be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "analysis_method_names" do
|
46
|
+
it "should return the analysis methods" do
|
47
|
+
@analyser.add(:width){}
|
48
|
+
@analyser.add(:height){}
|
49
|
+
@analyser.analysis_method_names.should == [:width, :height]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "cache" do
|
54
|
+
before(:each) do
|
55
|
+
@temp_object = Dragonfly::TempObject.new('HELLO')
|
56
|
+
end
|
57
|
+
|
58
|
+
def it_should_analyse_using(meth, temp_object, *args)
|
59
|
+
result = mock('result')
|
60
|
+
@analyser.should_receive(:call_last).with(meth, temp_object, *args).exactly(:once).and_return result
|
61
|
+
@analyser.analyse(temp_object, meth, *args).should == result
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should do the analysis the first time" do
|
66
|
+
it_should_analyse_using(:blah, @temp_object, :arg1)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "when already called" do
|
70
|
+
before(:each) do
|
71
|
+
@result = it_should_analyse_using(:blah, @temp_object, :arg1)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not do it subsequent times but still return the result" do
|
75
|
+
@analyser.should_not_receive(:call_last)
|
76
|
+
@analyser.analyse(@temp_object, :blah, :arg1).should == @result
|
77
|
+
@analyser.analyse(@temp_object, :blah, :arg1).should == @result
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not use the cache if the temp_object is different" do
|
81
|
+
temp_object = Dragonfly::TempObject.new('aaa')
|
82
|
+
it_should_analyse_using(:blah, temp_object, :arg1)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not use the cache if the method name is different" do
|
86
|
+
it_should_analyse_using(:egghead, @temp_object, :arg1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not use the cache if the args are different" do
|
90
|
+
it_should_analyse_using(:blah, @temp_object, :arg2)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should do it again if the cache has been cleared" do
|
94
|
+
@analyser.clear_cache!
|
95
|
+
it_should_analyse_using(:blah, @temp_object, :arg1)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not use the cache if it has been turned off" do
|
99
|
+
@analyser.enable_cache = false
|
100
|
+
it_should_analyse_using(:blah, @temp_object, :arg1)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "cache size" do
|
106
|
+
it "should not exceed the cache size" do
|
107
|
+
@analyser.cache_size = 2
|
108
|
+
|
109
|
+
res1 = it_should_analyse_using(:blah, @temp_object, :arg1)
|
110
|
+
res2 = it_should_analyse_using(:blah, @temp_object, :arg2)
|
111
|
+
res3 = it_should_analyse_using(:blah, @temp_object, :arg3) # Should kick out first one
|
112
|
+
|
113
|
+
it_should_analyse_using(:blah, @temp_object, :arg1)
|
114
|
+
|
115
|
+
# Third analysis should still be cached
|
116
|
+
@analyser.should_not_receive(:call_last)
|
117
|
+
@analyser.analyse(@temp_object, :blah, :arg3).should == res3
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
png_path = File.dirname(__FILE__) + '/../../../samples/egg.png'
|
4
|
+
|
5
|
+
describe Dragonfly::Analysis::FileCommandAnalyser do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@analyser = Dragonfly::Analysis::FileCommandAnalyser.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "mime_type" do
|
12
|
+
|
13
|
+
describe "when using the filesystem" do
|
14
|
+
before(:each) do
|
15
|
+
@analyser.use_filesystem = true
|
16
|
+
@temp_object = Dragonfly::TempObject.new(File.new(png_path))
|
17
|
+
end
|
18
|
+
it "should give the mime-type" do
|
19
|
+
@analyser.mime_type(@temp_object).should == 'image/png'
|
20
|
+
end
|
21
|
+
it "should not have initialized the data string" do
|
22
|
+
@analyser.mime_type(@temp_object)
|
23
|
+
@temp_object.instance_eval{@data}.should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when not using the filesystem" do
|
28
|
+
before(:each) do
|
29
|
+
@analyser.use_filesystem = false
|
30
|
+
@temp_object = Dragonfly::TempObject.new(File.read(png_path))
|
31
|
+
end
|
32
|
+
it "should give the mime-type" do
|
33
|
+
@analyser.mime_type(@temp_object).should == 'image/png'
|
34
|
+
end
|
35
|
+
it "should not have initialized the file" do
|
36
|
+
@analyser.mime_type(@temp_object)
|
37
|
+
@temp_object.instance_eval{@tempfile}.should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
{
|
41
|
+
:jpg => 'image/jpeg',
|
42
|
+
:png => 'image/png',
|
43
|
+
:gif => 'image/gif',
|
44
|
+
:tif => 'image/tiff'
|
45
|
+
}.each do |format, mime_type|
|
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
|
48
|
+
temp_object = Dragonfly::TempObject.new(data)
|
49
|
+
@analyser.mime_type(temp_object).should == mime_type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dragonfly/analysis/shared_analyser_spec'
|
3
|
+
|
4
|
+
describe Dragonfly::Analysis::ImageMagickAnalyser 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::ImageMagickAnalyser.new
|
10
|
+
@analyser.log = Logger.new(LOG_FILE)
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "image analyser methods"
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'dragonfly/analysis/shared_analyser_spec'
|
3
|
+
|
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
|
12
|
+
|
13
|
+
describe "when using the filesystem" do
|
14
|
+
before(:each) do
|
15
|
+
@analyser.use_filesystem = true
|
16
|
+
end
|
17
|
+
it_should_behave_like "image analyser methods"
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "when not using the filesystem" do
|
21
|
+
before(:each) do
|
22
|
+
@analyser.use_filesystem = false
|
23
|
+
end
|
24
|
+
it_should_behave_like "image analyser methods"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# NEEDS:
|
2
|
+
#
|
3
|
+
# @image
|
4
|
+
# @processor
|
5
|
+
#
|
6
|
+
describe "image analyser methods", :shared => true do
|
7
|
+
|
8
|
+
it "should return the width" do
|
9
|
+
@analyser.width(@image).should == 280
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return the height" do
|
13
|
+
@analyser.height(@image).should == 355
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return the aspect ratio" do
|
17
|
+
@analyser.aspect_ratio(@image).should == (280.0/355.0)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should say if it's portrait" do
|
21
|
+
@analyser.portrait?(@image).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should say if it's landscape" do
|
25
|
+
@analyser.landscape?(@image).should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the number of colours" do
|
29
|
+
@analyser.number_of_colours(@image).should == 34703
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return the depth" do
|
33
|
+
@analyser.depth(@image).should == 8
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the format" do
|
37
|
+
@analyser.format(@image).should == :png
|
38
|
+
end
|
39
|
+
|
40
|
+
%w(width height aspect_ratio number_of_colours depth format portrait? landscape?).each do |meth|
|
41
|
+
it "should throw unable_to_handle in #{meth.inspect} if it's not an image file" do
|
42
|
+
suppressing_stderr do
|
43
|
+
temp_object = Dragonfly::TempObject.new('blah')
|
44
|
+
lambda{
|
45
|
+
@analyser.send(meth, temp_object)
|
46
|
+
}.should throw_symbol(:unable_to_handle)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
|
4
|
+
def request(app, path)
|
5
|
+
Rack::MockRequest.new(app).get(path)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Dragonfly::App do
|
9
|
+
|
10
|
+
describe ".instance" do
|
11
|
+
|
12
|
+
it "should create a new instance if it didn't already exist" do
|
13
|
+
app = Dragonfly::App.instance(:images)
|
14
|
+
app.should be_a(Dragonfly::App)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return an existing instance if called by name" do
|
18
|
+
app = Dragonfly::App.instance(:images)
|
19
|
+
Dragonfly::App.instance(:images).should == app
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should also work using square brackets" do
|
23
|
+
Dragonfly[:images].should == Dragonfly::App.instance(:images)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".new" do
|
29
|
+
it "should not be callable" do
|
30
|
+
lambda{
|
31
|
+
Dragonfly::App.new
|
32
|
+
}.should raise_error(NoMethodError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "mime types" do
|
37
|
+
describe "#mime_type_for" do
|
38
|
+
before(:each) do
|
39
|
+
@app = test_app
|
40
|
+
end
|
41
|
+
it "should return the correct mime type for a symbol" do
|
42
|
+
@app.mime_type_for(:png).should == 'image/png'
|
43
|
+
end
|
44
|
+
it "should work for strings" do
|
45
|
+
@app.mime_type_for('png').should == 'image/png'
|
46
|
+
end
|
47
|
+
it "should work with uppercase strings" do
|
48
|
+
@app.mime_type_for('PNG').should == 'image/png'
|
49
|
+
end
|
50
|
+
it "should work with a dot" do
|
51
|
+
@app.mime_type_for('.png').should == 'image/png'
|
52
|
+
end
|
53
|
+
it "should return nil if not known" do
|
54
|
+
@app.mime_type_for(:mark).should be_nil
|
55
|
+
end
|
56
|
+
it "should allow for configuring extra mime types" do
|
57
|
+
@app.register_mime_type 'mark', 'application/mark'
|
58
|
+
@app.mime_type_for(:mark).should == 'application/mark'
|
59
|
+
end
|
60
|
+
it "should override existing mime types when registered" do
|
61
|
+
@app.register_mime_type :png, 'ping/pong'
|
62
|
+
@app.mime_type_for(:png).should == 'ping/pong'
|
63
|
+
end
|
64
|
+
it "should have a per-app mime-type configuration" do
|
65
|
+
other_app = Dragonfly[:other_app]
|
66
|
+
@app.register_mime_type(:mark, 'first/one')
|
67
|
+
other_app.register_mime_type(:mark, 'second/one')
|
68
|
+
@app.mime_type_for(:mark).should == 'first/one'
|
69
|
+
other_app.mime_type_for(:mark).should == 'second/one'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#resolve_mime_type" do
|
74
|
+
before(:each) do
|
75
|
+
@app = test_app
|
76
|
+
@app.analyser.add :format do |temp_object|
|
77
|
+
:png
|
78
|
+
end
|
79
|
+
@app.analyser.add :mime_type do |temp_object|
|
80
|
+
'image/jpeg'
|
81
|
+
end
|
82
|
+
@app.encoder.add do |temp_object|
|
83
|
+
'ENCODED DATA YO'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return the correct mime_type if the temp_object has a format" do
|
88
|
+
temp_object = Dragonfly::TempObject.new("HIMATE", :format => :tiff, :name => 'test.pdf')
|
89
|
+
@app.resolve_mime_type(temp_object).should == 'image/tiff'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should use the file extension if it has no format" do
|
93
|
+
temp_object = Dragonfly::TempObject.new("HIMATE", :name => 'test.pdf')
|
94
|
+
@app.resolve_mime_type(temp_object).should == 'application/pdf'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not use the file extension if it's been switched off (fall back to mime_type analyser)" do
|
98
|
+
@app.infer_mime_type_from_file_ext = false
|
99
|
+
temp_object = Dragonfly::TempObject.new("HIMATE", :name => 'test.pdf')
|
100
|
+
@app.resolve_mime_type(temp_object).should == 'image/jpeg'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should fall back to the mime_type analyser if the temp_object has no ext" do
|
104
|
+
temp_object = Dragonfly::TempObject.new("HIMATE", :name => 'test')
|
105
|
+
@app.resolve_mime_type(temp_object).should == 'image/jpeg'
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "when the temp_object has no name" do
|
109
|
+
|
110
|
+
before(:each) do
|
111
|
+
@temp_object = Dragonfly::TempObject.new("HIMATE")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should fall back to the mime_type analyser" do
|
115
|
+
@app.resolve_mime_type(@temp_object).should == 'image/jpeg'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should fall back to the format analyser if the mime_type analyser doesn't exist" do
|
119
|
+
@app.analyser.functions.delete(:mime_type)
|
120
|
+
@app.resolve_mime_type(@temp_object).should == 'image/png'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should fall back to the app's fallback mime_type if no mime_type/format analyser exists" do
|
124
|
+
@app.analyser.functions.delete(:mime_type)
|
125
|
+
@app.analyser.functions.delete(:format)
|
126
|
+
@app.resolve_mime_type(@temp_object).should == 'application/octet-stream'
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "without path prefix or DOS protection" do
|
136
|
+
before(:each) do
|
137
|
+
@app = test_app
|
138
|
+
@job = Dragonfly::Job.new(@app).fetch('some_uid')
|
139
|
+
@app.datastore.stub!(:retrieve).with('some_uid').and_return "Hi there"
|
140
|
+
@app.configure{|c| c.protect_from_dos_attacks = false }
|
141
|
+
end
|
142
|
+
it "should correctly respond with the job data" do
|
143
|
+
response = request(@app, "/#{@job.serialize}")
|
144
|
+
response.status.should == 200
|
145
|
+
response.body.should == "Hi there"
|
146
|
+
end
|
147
|
+
it "should generate the correct url" do
|
148
|
+
@app.url_for(@job).should == "/#{@job.serialize}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "url_path_prefix" do
|
153
|
+
before(:each) do
|
154
|
+
@app = test_app
|
155
|
+
@job = Dragonfly::Job.new(@app)
|
156
|
+
end
|
157
|
+
it "should add the path prefix to the url if configured" do
|
158
|
+
@app.url_path_prefix = '/media'
|
159
|
+
@app.url_for(@job).should =~ %r{^/media/\w+$}
|
160
|
+
end
|
161
|
+
it "should add the path prefix to the url if passed in" do
|
162
|
+
@app.url_for(@job, :path_prefix => '/eggs').should =~ %r{^/eggs/\w+$}
|
163
|
+
end
|
164
|
+
it "should favour the passed in one" do
|
165
|
+
@app.url_path_prefix = '/media'
|
166
|
+
@app.url_for(@job, :path_prefix => '/bacon').should =~ %r{^/bacon/\w+$}
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "url_host" do
|
171
|
+
before(:each) do
|
172
|
+
@app = test_app
|
173
|
+
@job = Dragonfly::Job.new(@app)
|
174
|
+
end
|
175
|
+
it "should add the host to the url if configured" do
|
176
|
+
@app.url_host = 'http://some.server:4000'
|
177
|
+
@app.url_for(@job).should =~ %r{^http://some\.server:4000/\w+$}
|
178
|
+
end
|
179
|
+
it "should add the host to the url if passed in" do
|
180
|
+
@app.url_for(@job, :host => 'https://bungle.com').should =~ %r{^https://bungle\.com/\w+$}
|
181
|
+
end
|
182
|
+
it "should favour the passed in one" do
|
183
|
+
@app.url_host = 'http://some.server:4000'
|
184
|
+
@app.url_for(@job, :host => 'https://smeedy').should =~ %r{^https://smeedy/\w+$}
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "url_suffix" do
|
189
|
+
before(:each) do
|
190
|
+
@app = test_app
|
191
|
+
@job = Dragonfly::Job.new(@app)
|
192
|
+
end
|
193
|
+
it "should add the suffix to the url if configured" do
|
194
|
+
@app.url_suffix = 'hellodudes'
|
195
|
+
@app.url_for(@job).should =~ /\w+hellodudes$/
|
196
|
+
end
|
197
|
+
it "should add the suffix to the url if passed in" do
|
198
|
+
@app.url_for(@job, :suffix => '/howdy.pardner').should =~ /\w+\/howdy\.pardner$/
|
199
|
+
end
|
200
|
+
it "should favour the passed in one" do
|
201
|
+
@app.url_suffix = 'hellodudes'
|
202
|
+
@app.url_for(@job, :suffix => '/howdy.pardner').should =~ /\w+\/howdy\.pardner$/
|
203
|
+
end
|
204
|
+
it "should accept a proc yielding the job" do
|
205
|
+
@app.url_suffix = proc{|job| job.uid }
|
206
|
+
@job.fetch!('some_uid')
|
207
|
+
@app.url_for(@job).should =~ /\w+some_uid$/
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "url params" do
|
212
|
+
before(:each) do
|
213
|
+
@app = test_app
|
214
|
+
@job = Dragonfly::Job.new(@app)
|
215
|
+
end
|
216
|
+
it "should add extra params to the url query string" do
|
217
|
+
@app.url_for(@job, :suffix => '/suffix', :a => 'thing', :b => 'nuther').should =~ /\w+\/suffix\?a=thing&b=nuther$/
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "Denial of Service protection" do
|
222
|
+
before(:each) do
|
223
|
+
@app = test_app
|
224
|
+
@app.protect_from_dos_attacks = true
|
225
|
+
@job = Dragonfly::Job.new(@app).fetch('some_uid')
|
226
|
+
end
|
227
|
+
it "should generate the correct url" do
|
228
|
+
@app.url_for(@job).should == "/#{@job.serialize}?s=#{@job.sha}"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "configuring with saved configurations" do
|
233
|
+
before(:each) do
|
234
|
+
@app = test_app
|
235
|
+
end
|
236
|
+
|
237
|
+
{
|
238
|
+
:imagemagick => Dragonfly::Config::ImageMagick,
|
239
|
+
:image_magick => Dragonfly::Config::ImageMagick,
|
240
|
+
:rmagick => Dragonfly::Config::RMagick,
|
241
|
+
:r_magick => Dragonfly::Config::RMagick,
|
242
|
+
:rails => Dragonfly::Config::Rails,
|
243
|
+
:heroku => Dragonfly::Config::Heroku,
|
244
|
+
}.each do |key, klass|
|
245
|
+
it "should map #{key} to #{klass}" do
|
246
|
+
klass.should_receive(:apply_configuration).with(@app)
|
247
|
+
@app.configure_with(key)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should description" do
|
252
|
+
lambda {
|
253
|
+
@app.configure_with(:eggs)
|
254
|
+
}.should raise_error(ArgumentError)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "#store" do
|
259
|
+
before(:each) do
|
260
|
+
@app = test_app
|
261
|
+
end
|
262
|
+
it "should allow just storing content" do
|
263
|
+
@app.datastore.should_receive(:store).with(a_temp_object_with_data("HELLO"), {})
|
264
|
+
@app.store("HELLO")
|
265
|
+
end
|
266
|
+
it "should allow storing using a TempObject" do
|
267
|
+
temp_object = Dragonfly::TempObject.new("HELLO")
|
268
|
+
@app.datastore.should_receive(:store).with(temp_object, {})
|
269
|
+
@app.store(temp_object)
|
270
|
+
end
|
271
|
+
it "should allow storing with extra stuff" do
|
272
|
+
@app.datastore.should_receive(:store).with(
|
273
|
+
a_temp_object_with_data("HELLO", :meta => {:egg => :head}),
|
274
|
+
{:option => :blarney}
|
275
|
+
)
|
276
|
+
@app.store("HELLO", :meta => {:egg => :head}, :option => :blarney)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|