dragonfly 0.6.2 → 0.7.0

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.

Files changed (157) hide show
  1. data/.gitignore +2 -0
  2. data/.specopts +2 -0
  3. data/.yardopts +11 -5
  4. data/Gemfile +22 -0
  5. data/Gemfile.rails.2.3.5 +13 -0
  6. data/History.md +49 -0
  7. data/README.md +18 -28
  8. data/Rakefile +24 -36
  9. data/VERSION +1 -1
  10. data/config.ru +4 -1
  11. data/dragonfly.gemspec +85 -99
  12. data/extra_docs/Analysers.md +66 -30
  13. data/extra_docs/Caching.md +22 -0
  14. data/extra_docs/Configuration.md +116 -0
  15. data/extra_docs/DataStorage.md +114 -14
  16. data/extra_docs/Encoding.md +62 -37
  17. data/extra_docs/GeneralUsage.md +118 -0
  18. data/extra_docs/Generators.md +92 -0
  19. data/extra_docs/Heroku.md +51 -0
  20. data/extra_docs/Index.md +8 -9
  21. data/extra_docs/MimeTypes.md +18 -17
  22. data/extra_docs/Models.md +251 -0
  23. data/extra_docs/Processing.md +94 -70
  24. data/extra_docs/Rack.md +53 -0
  25. data/extra_docs/Rails2.md +44 -0
  26. data/extra_docs/Rails3.md +51 -0
  27. data/extra_docs/Sinatra.md +21 -0
  28. data/extra_docs/URLs.md +114 -0
  29. data/features/images.feature +6 -7
  30. data/features/no_processing.feature +0 -6
  31. data/features/rails_2.3.5.feature +1 -1
  32. data/features/rails_3.0.0.rc.feature +8 -0
  33. data/features/steps/dragonfly_steps.rb +14 -12
  34. data/features/steps/rails_steps.rb +20 -9
  35. data/features/support/env.rb +10 -11
  36. data/fixtures/files/app/views/albums/new.html.erb +4 -4
  37. data/fixtures/files/app/views/albums/show.html.erb +1 -1
  38. data/fixtures/files/features/manage_album_images.feature +1 -1
  39. data/fixtures/files/features/step_definitions/{album_steps.rb → image_steps.rb} +4 -3
  40. data/fixtures/files/features/support/paths.rb +2 -0
  41. data/fixtures/files/features/text_images.feature +7 -0
  42. data/fixtures/rails_3.0.0.rc/template.rb +21 -0
  43. data/irbrc.rb +2 -1
  44. data/lib/dragonfly.rb +4 -16
  45. data/lib/dragonfly/{active_record_extensions.rb → active_model_extensions.rb} +1 -1
  46. data/lib/dragonfly/active_model_extensions/attachment.rb +146 -0
  47. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/class_methods.rb +5 -6
  48. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/instance_methods.rb +1 -1
  49. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/validations.rb +5 -9
  50. data/lib/dragonfly/analyser.rb +59 -0
  51. data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
  52. data/lib/dragonfly/analysis/r_magick_analyser.rb +46 -31
  53. data/lib/dragonfly/app.rb +138 -173
  54. data/lib/dragonfly/config/heroku.rb +19 -0
  55. data/lib/dragonfly/config/r_magick.rb +37 -0
  56. data/lib/dragonfly/config/{rails_defaults.rb → rails.rb} +6 -7
  57. data/lib/dragonfly/configurable.rb +30 -27
  58. data/lib/dragonfly/core_ext/object.rb +1 -1
  59. data/lib/dragonfly/data_storage/file_data_store.rb +59 -26
  60. data/lib/dragonfly/data_storage/mongo_data_store.rb +65 -0
  61. data/lib/dragonfly/data_storage/s3data_store.rb +31 -12
  62. data/lib/dragonfly/encoder.rb +13 -0
  63. data/lib/dragonfly/encoding/r_magick_encoder.rb +10 -19
  64. data/lib/dragonfly/endpoint.rb +43 -0
  65. data/lib/dragonfly/function_manager.rb +65 -0
  66. data/lib/dragonfly/{processing/r_magick_text_processor.rb → generation/r_magick_generator.rb} +25 -11
  67. data/lib/dragonfly/generator.rb +9 -0
  68. data/lib/dragonfly/job.rb +290 -0
  69. data/lib/dragonfly/job_builder.rb +39 -0
  70. data/lib/dragonfly/job_definitions.rb +26 -0
  71. data/lib/dragonfly/job_endpoint.rb +17 -0
  72. data/lib/dragonfly/loggable.rb +28 -0
  73. data/lib/dragonfly/middleware.rb +21 -14
  74. data/lib/dragonfly/processing/r_magick_processor.rb +71 -48
  75. data/lib/dragonfly/processor.rb +9 -0
  76. data/lib/dragonfly/r_magick_utils.rb +24 -0
  77. data/lib/dragonfly/rails/images.rb +10 -7
  78. data/lib/dragonfly/routed_endpoint.rb +42 -0
  79. data/lib/dragonfly/serializer.rb +32 -0
  80. data/lib/dragonfly/simple_cache.rb +23 -0
  81. data/lib/dragonfly/simple_endpoint.rb +64 -0
  82. data/lib/dragonfly/temp_object.rb +77 -45
  83. data/spec/argument_matchers.rb +7 -17
  84. data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
  85. data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
  86. data/spec/dragonfly/{active_record_extensions → active_model_extensions}/model_spec.rb +282 -244
  87. data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
  88. data/spec/dragonfly/analyser_spec.rb +123 -0
  89. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +2 -2
  90. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +10 -1
  91. data/spec/dragonfly/app_spec.rb +175 -69
  92. data/spec/dragonfly/configurable_spec.rb +14 -0
  93. data/spec/dragonfly/data_storage/data_store_spec.rb +36 -9
  94. data/spec/dragonfly/data_storage/file_data_store_spec.rb +61 -38
  95. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +18 -0
  96. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +34 -39
  97. data/spec/dragonfly/deprecation_spec.rb +20 -0
  98. data/spec/dragonfly/function_manager_spec.rb +154 -0
  99. data/spec/dragonfly/generation/r_magick_generator_spec.rb +119 -0
  100. data/spec/dragonfly/job_builder_spec.rb +37 -0
  101. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  102. data/spec/dragonfly/job_endpoint_spec.rb +66 -0
  103. data/spec/dragonfly/job_spec.rb +605 -0
  104. data/spec/dragonfly/loggable_spec.rb +80 -0
  105. data/spec/dragonfly/middleware_spec.rb +37 -17
  106. data/spec/dragonfly/processing/r_magick_processor_spec.rb +182 -166
  107. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  108. data/spec/dragonfly/serializer_spec.rb +61 -0
  109. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  110. data/spec/dragonfly/simple_endpoint_spec.rb +78 -0
  111. data/spec/dragonfly/temp_object_spec.rb +154 -119
  112. data/spec/simple_matchers.rb +22 -0
  113. data/spec/spec_helper.rb +28 -4
  114. data/yard/templates/default/layout/html/layout.erb +18 -11
  115. metadata +89 -190
  116. data/config.rb +0 -5
  117. data/extra_docs/ActiveRecord.md +0 -196
  118. data/extra_docs/ExampleUseCases.md +0 -189
  119. data/extra_docs/GettingStarted.md +0 -114
  120. data/extra_docs/Shortcuts.md +0 -118
  121. data/extra_docs/UsingWithRails.md +0 -81
  122. data/features/rails_3.0.0.beta3.feature +0 -7
  123. data/fixtures/rails_3.0.0.beta3/template.rb +0 -16
  124. data/lib/dragonfly/active_record_extensions/attachment.rb +0 -170
  125. data/lib/dragonfly/analyser_list.rb +0 -9
  126. data/lib/dragonfly/analysis/base.rb +0 -10
  127. data/lib/dragonfly/belongs_to_app.rb +0 -24
  128. data/lib/dragonfly/config/heroku_rails_images.rb +0 -23
  129. data/lib/dragonfly/config/r_magick_images.rb +0 -69
  130. data/lib/dragonfly/config/r_magick_text.rb +0 -25
  131. data/lib/dragonfly/config/rails_images.rb +0 -13
  132. data/lib/dragonfly/data_storage/base.rb +0 -21
  133. data/lib/dragonfly/data_storage/base64_data_store.rb +0 -23
  134. data/lib/dragonfly/data_storage/transparent_data_store.rb +0 -21
  135. data/lib/dragonfly/delegatable.rb +0 -14
  136. data/lib/dragonfly/delegator.rb +0 -62
  137. data/lib/dragonfly/encoder_list.rb +0 -9
  138. data/lib/dragonfly/encoding/base.rb +0 -14
  139. data/lib/dragonfly/encoding/transparent_encoder.rb +0 -14
  140. data/lib/dragonfly/extended_temp_object.rb +0 -120
  141. data/lib/dragonfly/parameters.rb +0 -163
  142. data/lib/dragonfly/processing/base.rb +0 -10
  143. data/lib/dragonfly/processor_list.rb +0 -9
  144. data/lib/dragonfly/url_handler.rb +0 -147
  145. data/spec/dragonfly/active_record_extensions/attachment_spec.rb +0 -8
  146. data/spec/dragonfly/active_record_extensions/migration.rb +0 -42
  147. data/spec/dragonfly/active_record_extensions/models.rb +0 -6
  148. data/spec/dragonfly/active_record_extensions/spec_helper.rb +0 -24
  149. data/spec/dragonfly/belongs_to_app_spec.rb +0 -55
  150. data/spec/dragonfly/delegatable_spec.rb +0 -32
  151. data/spec/dragonfly/delegator_spec.rb +0 -145
  152. data/spec/dragonfly/extended_temp_object_spec.rb +0 -71
  153. data/spec/dragonfly/parameters_spec.rb +0 -298
  154. data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +0 -84
  155. data/spec/dragonfly/url_handler_spec.rb +0 -247
  156. data/spec/dragonfly_spec.rb +0 -16
  157. data/spec/ginger_scenarios.rb +0 -13
@@ -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
@@ -44,8 +44,8 @@ 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
- processor = Dragonfly::Processing::RMagickProcessor.new
48
- temp_object = Dragonfly::TempObject.new(processor.generate(1000, 1000, format))
47
+ data = Dragonfly::Generation::RMagickGenerator.new.plasma(1000, 1000, format).first
48
+ temp_object = Dragonfly::TempObject.new(data)
49
49
  @analyser.mime_type(temp_object).should == mime_type
50
50
  end
51
51
  end
@@ -6,6 +6,7 @@ describe Dragonfly::Analysis::RMagickAnalyser do
6
6
  image_path = File.dirname(__FILE__) + '/../../../samples/beach.png'
7
7
  @beach = Dragonfly::TempObject.new(File.new(image_path))
8
8
  @analyser = Dragonfly::Analysis::RMagickAnalyser.new
9
+ @analyser.log = Logger.new(LOG_FILE)
9
10
  end
10
11
 
11
12
  it "should return the width" do
@@ -20,6 +21,14 @@ describe Dragonfly::Analysis::RMagickAnalyser do
20
21
  @analyser.aspect_ratio(@beach).should == (280.0/355.0)
21
22
  end
22
23
 
24
+ it "should say if it's portrait" do
25
+ @analyser.portrait?(@beach).should be_true
26
+ end
27
+
28
+ it "should say if it's landscape" do
29
+ @analyser.landscape?(@beach).should be_false
30
+ end
31
+
23
32
  it "should return the number of colours" do
24
33
  @analyser.number_of_colours(@beach).should == 34703
25
34
  end
@@ -32,7 +41,7 @@ describe Dragonfly::Analysis::RMagickAnalyser do
32
41
  @analyser.format(@beach).should == :png
33
42
  end
34
43
 
35
- %w(width height aspect_ratio number_of_colours depth format).each do |meth|
44
+ %w(width height aspect_ratio number_of_colours depth format portrait? landscape?).each do |meth|
36
45
  it "should throw unable_to_handle in #{meth.inspect} if it's not an image file" do
37
46
  temp_object = Dragonfly::TempObject.new('blah')
38
47
  lambda{
@@ -1,11 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'rack/mock'
3
3
 
4
- describe Dragonfly::App do
4
+ def request(app, path)
5
+ Rack::MockRequest.new(app).get(path)
6
+ end
5
7
 
6
- def make_request(app, url)
7
- Rack::MockRequest.new(app).get(url)
8
- end
8
+ describe Dragonfly::App do
9
9
 
10
10
  describe ".instance" do
11
11
 
@@ -20,7 +20,7 @@ describe Dragonfly::App do
20
20
  end
21
21
 
22
22
  it "should also work using square brackets" do
23
- Dragonfly::App[:images].should == Dragonfly::App.instance(:images)
23
+ Dragonfly[:images].should == Dragonfly::App.instance(:images)
24
24
  end
25
25
 
26
26
  end
@@ -32,45 +32,11 @@ describe Dragonfly::App do
32
32
  }.should raise_error(NoMethodError)
33
33
  end
34
34
  end
35
-
36
- describe "errors" do
37
-
38
- before(:each) do
39
- @app = Dragonfly::App[:images]
40
- end
41
-
42
- it "should return 400 if UrlHandler::IncorrectSHA is raised" do
43
- @app.url_handler.should_receive(:url_to_parameters).and_raise(Dragonfly::UrlHandler::IncorrectSHA)
44
- response = make_request(@app, '/some_uid.png?s=sadfas')
45
- response.status.should == 400
46
- end
47
-
48
- it "should return 400 if UrlHandler::SHANotGiven is raised" do
49
- @app.url_handler.should_receive(:url_to_parameters).and_raise(Dragonfly::UrlHandler::SHANotGiven)
50
- response = make_request(@app, '/some_uid.png?s=asdfghsg')
51
- response.status.should == 400
52
- end
53
-
54
- it "should return 404 if url handler raises an unknown url exception" do
55
- @app.url_handler.should_receive(:url_to_parameters).and_raise(Dragonfly::UrlHandler::UnknownUrl)
56
- response = make_request(@app, '/')
57
- response.status.should == 404
58
- end
59
-
60
- it "should return 404 if the datastore raises data not found" do
61
- @app.url_handler.protect_from_dos_attacks = false
62
- @app.should_receive(:fetch).and_raise(Dragonfly::DataStorage::DataNotFound)
63
- response = make_request(@app, '/hello.png')
64
- response.status.should == 404
65
- end
66
-
67
- end
68
35
 
69
36
  describe "mime types" do
70
37
  describe "#mime_type_for" do
71
38
  before(:each) do
72
- Dragonfly::App.send(:apps)[:images] = nil # A Hack to get rspec to reset stuff in between tests
73
- @app = Dragonfly::App[:images]
39
+ @app = test_app
74
40
  end
75
41
  it "should return the correct mime type for a symbol" do
76
42
  @app.mime_type_for(:png).should == 'image/png'
@@ -84,23 +50,19 @@ describe Dragonfly::App do
84
50
  it "should work with a dot" do
85
51
  @app.mime_type_for('.png').should == 'image/png'
86
52
  end
87
- it "should return the fallback mime_type if not known" do
88
- @app.mime_type_for(:mark).should == 'application/octet-stream'
89
- end
90
- it "should return the fallback mime_type if not known" do
91
- @app.configure{|c| c.fallback_mime_type = 'egg/nog'}
92
- @app.mime_type_for(:mark).should == 'egg/nog'
53
+ it "should return nil if not known" do
54
+ @app.mime_type_for(:mark).should be_nil
93
55
  end
94
56
  it "should allow for configuring extra mime types" do
95
- @app.configure{|c| c.register_mime_type 'mark', 'application/mark'}
57
+ @app.register_mime_type 'mark', 'application/mark'
96
58
  @app.mime_type_for(:mark).should == 'application/mark'
97
59
  end
98
60
  it "should override existing mime types when registered" do
99
- @app.configure{|c| c.register_mime_type :png, 'ping/pong'}
61
+ @app.register_mime_type :png, 'ping/pong'
100
62
  @app.mime_type_for(:png).should == 'ping/pong'
101
63
  end
102
64
  it "should have a per-app mime-type configuration" do
103
- other_app = Dragonfly::App[:other_app]
65
+ other_app = Dragonfly[:other_app]
104
66
  @app.register_mime_type(:mark, 'first/one')
105
67
  other_app.register_mime_type(:mark, 'second/one')
106
68
  @app.mime_type_for(:mark).should == 'first/one'
@@ -108,32 +70,176 @@ describe Dragonfly::App do
108
70
  end
109
71
  end
110
72
 
111
- describe "Content-Type header" do
73
+ describe "#resolve_mime_type" do
112
74
  before(:each) do
113
- Dragonfly::App.send(:apps)[:test] = nil # A Hack to get rspec to reset stuff in between tests
114
- @app = Dragonfly::App[:test]
115
- @app.url_handler.protect_from_dos_attacks = false
116
- @app.datastore = Dragonfly::DataStorage::TransparentDataStore.new
117
- @app.register_encoder(Dragonfly::Encoding::TransparentEncoder)
118
- @analyser = Class.new(Dragonfly::Analysis::Base){ def mime_type(*args); 'analyser/mime-type'; end }
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
119
85
  end
120
- it "should return the fallback mime_type if none registered and no mime_type analyser" do
121
- make_request(@app, '/some_uid.gog').headers['Content-Type'].should == 'application/octet-stream'
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'
122
90
  end
123
- it "should return the analysed mime-type if an analyser is registered" do
124
- @app.register_analyser(@analyser)
125
- make_request(@app, '/some_uid.gog').headers['Content-Type'].should == 'analyser/mime-type'
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'
126
95
  end
127
- it "should return the registered mime_type over the analysed one" do
128
- @app.register_analyser(@analyser)
129
- @app.register_mime_type(:gog, 'numb/nut')
130
- make_request(@app, '/some_uid.gog').headers['Content-Type'].should == 'numb/nut'
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
+
131
129
  end
132
- it "should use the fallback mime-type if the registered analyser doesn't respond to 'mime-type'" do
133
- @app.register_analyser(Class.new(Dragonfly::Analysis::Base))
134
- make_request(@app, '/some_uid.gog').headers['Content-Type'].should == 'application/octet-stream'
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 "Denial of Service protection" do
189
+ before(:each) do
190
+ @app = test_app
191
+ @app.protect_from_dos_attacks = true
192
+ @job = Dragonfly::Job.new(@app).fetch('some_uid')
193
+ end
194
+ it "should generate the correct url" do
195
+ @app.url_for(@job).should == "/#{@job.serialize}?s=#{@job.sha}"
196
+ end
197
+ end
198
+
199
+ describe "configuring with saved configurations" do
200
+ before(:each) do
201
+ @app = test_app
202
+ end
203
+
204
+ {
205
+ :rmagick => Dragonfly::Config::RMagick,
206
+ :r_magick => Dragonfly::Config::RMagick,
207
+ :rails => Dragonfly::Config::Rails,
208
+ :heroku => Dragonfly::Config::Heroku,
209
+ }.each do |key, klass|
210
+ it "should map #{key} to #{klass}" do
211
+ klass.should_receive(:apply_configuration).with(@app)
212
+ @app.configure_with(key)
135
213
  end
136
214
  end
215
+
216
+ it "should description" do
217
+ lambda {
218
+ @app.configure_with(:eggs)
219
+ }.should raise_error(ArgumentError)
220
+ end
221
+ end
222
+
223
+ describe "#store" do
224
+ before(:each) do
225
+ @app = test_app
226
+ end
227
+ it "should allow just storing content" do
228
+ @app.datastore.should_receive(:store).with(a_temp_object_with_data("HELLO"), {})
229
+ @app.store("HELLO")
230
+ end
231
+ it "should allow storing using a TempObject" do
232
+ temp_object = Dragonfly::TempObject.new("HELLO")
233
+ @app.datastore.should_receive(:store).with(temp_object, {})
234
+ @app.store(temp_object)
235
+ end
236
+ it "should allow storing with extra stuff" do
237
+ @app.datastore.should_receive(:store).with(
238
+ a_temp_object_with_data("HELLO", :meta => {:egg => :head}),
239
+ {:option => :blarney}
240
+ )
241
+ @app.store("HELLO", :meta => {:egg => :head}, :option => :blarney)
242
+ end
137
243
  end
138
244
 
139
- end
245
+ end