dragonfly 0.9.15 → 1.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 (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -8
  3. data/.travis.yml +11 -0
  4. data/Gemfile +1 -0
  5. data/History.md +52 -2
  6. data/LICENSE +1 -1
  7. data/README.md +38 -95
  8. data/dev/grid.jpg +0 -0
  9. data/dev/irbrc.rb +27 -0
  10. data/dev/rails_template.rb +38 -0
  11. data/dev/test.ru +56 -0
  12. data/dev/test_rails +19 -0
  13. data/dragonfly.gemspec +3 -21
  14. data/lib/dragonfly.rb +45 -44
  15. data/lib/dragonfly/app.rb +175 -96
  16. data/lib/dragonfly/configurable.rb +71 -170
  17. data/lib/dragonfly/content.rb +211 -0
  18. data/lib/dragonfly/core_ext/object.rb +1 -6
  19. data/lib/dragonfly/file_data_store.rb +197 -0
  20. data/lib/dragonfly/image_magick/analysers/image_properties.rb +23 -0
  21. data/lib/dragonfly/image_magick/generators/convert.rb +19 -0
  22. data/lib/dragonfly/image_magick/generators/plain.rb +26 -0
  23. data/lib/dragonfly/image_magick/generators/plasma.rb +25 -0
  24. data/lib/dragonfly/image_magick/generators/text.rb +127 -0
  25. data/lib/dragonfly/image_magick/plugin.rb +83 -0
  26. data/lib/dragonfly/image_magick/processors/convert.rb +29 -0
  27. data/lib/dragonfly/image_magick/processors/encode.rb +18 -0
  28. data/lib/dragonfly/image_magick/processors/thumb.rb +76 -0
  29. data/lib/dragonfly/job.rb +118 -134
  30. data/lib/dragonfly/job_endpoint.rb +2 -0
  31. data/lib/dragonfly/memory_data_store.rb +34 -0
  32. data/lib/dragonfly/middleware.rb +5 -3
  33. data/lib/dragonfly/{active_model_extensions.rb → model.rb} +5 -3
  34. data/lib/dragonfly/{active_model_extensions → model}/attachment.rb +40 -35
  35. data/lib/dragonfly/{active_model_extensions → model}/attachment_class_methods.rb +36 -40
  36. data/lib/dragonfly/model/class_methods.rb +109 -0
  37. data/lib/dragonfly/{active_model_extensions → model}/instance_methods.rb +2 -2
  38. data/lib/dragonfly/{active_model_extensions → model}/validations.rb +17 -12
  39. data/lib/dragonfly/railtie.rb +8 -6
  40. data/lib/dragonfly/register.rb +27 -0
  41. data/lib/dragonfly/response.rb +47 -52
  42. data/lib/dragonfly/routed_endpoint.rb +4 -0
  43. data/lib/dragonfly/serializer.rb +15 -5
  44. data/lib/dragonfly/server.rb +56 -29
  45. data/lib/dragonfly/shell.rb +12 -23
  46. data/lib/dragonfly/spec/data_store_examples.rb +64 -0
  47. data/lib/dragonfly/temp_object.rb +32 -47
  48. data/lib/dragonfly/url_attributes.rb +19 -22
  49. data/lib/dragonfly/url_mapper.rb +3 -0
  50. data/lib/dragonfly/utils.rb +12 -0
  51. data/lib/dragonfly/version.rb +1 -1
  52. data/lib/dragonfly/whitelist.rb +19 -0
  53. data/lib/rails/generators/dragonfly/USAGE +8 -0
  54. data/lib/rails/generators/dragonfly/dragonfly_generator.rb +24 -0
  55. data/lib/rails/generators/dragonfly/templates/initializer.rb.erb +27 -0
  56. data/samples/gif.gif +0 -0
  57. data/spec/dragonfly/app_spec.rb +270 -64
  58. data/spec/dragonfly/configurable_spec.rb +142 -418
  59. data/spec/dragonfly/content_spec.rb +353 -0
  60. data/spec/dragonfly/cookie_monster_spec.rb +2 -1
  61. data/spec/dragonfly/file_data_store_spec.rb +301 -0
  62. data/spec/dragonfly/image_magick/analysers/image_properties_spec.rb +20 -0
  63. data/spec/dragonfly/image_magick/generators/convert_spec.rb +19 -0
  64. data/spec/dragonfly/image_magick/generators/plain_spec.rb +50 -0
  65. data/spec/dragonfly/image_magick/generators/plasma_spec.rb +32 -0
  66. data/spec/dragonfly/image_magick/generators/text_spec.rb +77 -0
  67. data/spec/dragonfly/image_magick/plugin_spec.rb +131 -0
  68. data/spec/dragonfly/image_magick/processors/convert_spec.rb +56 -0
  69. data/spec/dragonfly/image_magick/processors/thumb_spec.rb +173 -0
  70. data/spec/dragonfly/job_endpoint_spec.rb +30 -73
  71. data/spec/dragonfly/job_spec.rb +280 -608
  72. data/spec/dragonfly/memory_data_store_spec.rb +20 -0
  73. data/spec/dragonfly/middleware_spec.rb +47 -27
  74. data/spec/dragonfly/{active_model_extensions → model}/model_spec.rb +331 -555
  75. data/spec/dragonfly/model/validations_spec.rb +196 -0
  76. data/spec/dragonfly/register_spec.rb +35 -0
  77. data/spec/dragonfly/routed_endpoint_spec.rb +6 -6
  78. data/spec/dragonfly/serializer_spec.rb +13 -15
  79. data/spec/dragonfly/server_spec.rb +122 -46
  80. data/spec/dragonfly/shell_spec.rb +43 -24
  81. data/spec/dragonfly/temp_object_spec.rb +69 -94
  82. data/spec/dragonfly/url_attributes_spec.rb +49 -0
  83. data/spec/dragonfly/utils_spec.rb +32 -0
  84. data/spec/dragonfly/whitelist_spec.rb +30 -0
  85. data/spec/dragonfly_spec.rb +43 -0
  86. data/spec/fixtures/deprecated_stored_content/eggs.bonus +1 -0
  87. data/spec/fixtures/deprecated_stored_content/eggs.bonus.meta +1 -0
  88. data/spec/functional/configuration_spec.rb +19 -0
  89. data/spec/functional/model_urls_spec.rb +43 -41
  90. data/spec/functional/remote_on_the_fly_spec.rb +14 -16
  91. data/spec/functional/shell_commands_spec.rb +24 -14
  92. data/spec/functional/to_response_spec.rb +10 -10
  93. data/spec/functional/urls_spec.rb +5 -3
  94. data/spec/spec_helper.rb +23 -28
  95. data/spec/support/argument_matchers.rb +7 -8
  96. data/spec/support/image_matchers.rb +14 -36
  97. data/spec/support/model_helpers.rb +97 -0
  98. data/spec/support/simple_matchers.rb +12 -0
  99. metadata +92 -393
  100. data/.yardopts +0 -29
  101. data/Rakefile +0 -36
  102. data/config.ru +0 -14
  103. data/docs.watchr +0 -1
  104. data/extra_docs/Analysers.md +0 -68
  105. data/extra_docs/Caching.md +0 -23
  106. data/extra_docs/Configuration.md +0 -149
  107. data/extra_docs/Couch.md +0 -49
  108. data/extra_docs/DataStorage.md +0 -226
  109. data/extra_docs/Encoding.md +0 -67
  110. data/extra_docs/ExampleUseCases.md +0 -116
  111. data/extra_docs/GeneralUsage.md +0 -105
  112. data/extra_docs/Generators.md +0 -68
  113. data/extra_docs/Heroku.md +0 -50
  114. data/extra_docs/ImageMagick.md +0 -136
  115. data/extra_docs/Index.md +0 -33
  116. data/extra_docs/MimeTypes.md +0 -40
  117. data/extra_docs/Models.md +0 -441
  118. data/extra_docs/Mongo.md +0 -42
  119. data/extra_docs/Processing.md +0 -77
  120. data/extra_docs/Rack.md +0 -52
  121. data/extra_docs/Rails2.md +0 -57
  122. data/extra_docs/Rails3.md +0 -56
  123. data/extra_docs/ServingRemotely.md +0 -104
  124. data/extra_docs/Sinatra.md +0 -25
  125. data/extra_docs/URLs.md +0 -203
  126. data/features/images.feature +0 -47
  127. data/features/no_processing.feature +0 -14
  128. data/features/rails.feature +0 -8
  129. data/features/steps/common_steps.rb +0 -8
  130. data/features/steps/dragonfly_steps.rb +0 -66
  131. data/features/steps/rails_steps.rb +0 -40
  132. data/features/support/env.rb +0 -13
  133. data/features/support/setup.rb +0 -41
  134. data/fixtures/rails/files/app/models/album.rb +0 -6
  135. data/fixtures/rails/files/app/views/albums/new.html.erb +0 -7
  136. data/fixtures/rails/files/app/views/albums/show.html.erb +0 -6
  137. data/fixtures/rails/files/config/initializers/dragonfly.rb +0 -4
  138. data/fixtures/rails/files/features/manage_album_images.feature +0 -38
  139. data/fixtures/rails/files/features/step_definitions/helper_steps.rb +0 -7
  140. data/fixtures/rails/files/features/step_definitions/image_steps.rb +0 -25
  141. data/fixtures/rails/files/features/step_definitions/web_steps.rb +0 -189
  142. data/fixtures/rails/files/features/support/paths.rb +0 -17
  143. data/fixtures/rails/files/features/text_images.feature +0 -7
  144. data/fixtures/rails/template.rb +0 -20
  145. data/irbrc.rb +0 -19
  146. data/lib/dragonfly/active_model_extensions/class_methods.rb +0 -98
  147. data/lib/dragonfly/analyser.rb +0 -58
  148. data/lib/dragonfly/analysis/file_command_analyser.rb +0 -33
  149. data/lib/dragonfly/analysis/image_magick_analyser.rb +0 -6
  150. data/lib/dragonfly/config/heroku.rb +0 -26
  151. data/lib/dragonfly/config/image_magick.rb +0 -6
  152. data/lib/dragonfly/config/rails.rb +0 -20
  153. data/lib/dragonfly/data_storage.rb +0 -11
  154. data/lib/dragonfly/data_storage/couch_data_store.rb +0 -83
  155. data/lib/dragonfly/data_storage/file_data_store.rb +0 -144
  156. data/lib/dragonfly/data_storage/mongo_data_store.rb +0 -96
  157. data/lib/dragonfly/data_storage/s3data_store.rb +0 -168
  158. data/lib/dragonfly/encoder.rb +0 -13
  159. data/lib/dragonfly/encoding/image_magick_encoder.rb +0 -6
  160. data/lib/dragonfly/function_manager.rb +0 -67
  161. data/lib/dragonfly/generation/image_magick_generator.rb +0 -6
  162. data/lib/dragonfly/generator.rb +0 -9
  163. data/lib/dragonfly/image_magick/analyser.rb +0 -53
  164. data/lib/dragonfly/image_magick/config.rb +0 -44
  165. data/lib/dragonfly/image_magick/encoder.rb +0 -57
  166. data/lib/dragonfly/image_magick/generator.rb +0 -147
  167. data/lib/dragonfly/image_magick/processor.rb +0 -114
  168. data/lib/dragonfly/image_magick/utils.rb +0 -46
  169. data/lib/dragonfly/image_magick_utils.rb +0 -4
  170. data/lib/dragonfly/job_builder.rb +0 -39
  171. data/lib/dragonfly/job_definitions.rb +0 -30
  172. data/lib/dragonfly/loggable.rb +0 -28
  173. data/lib/dragonfly/processing/image_magick_processor.rb +0 -6
  174. data/lib/dragonfly/processor.rb +0 -9
  175. data/lib/dragonfly/rails/images.rb +0 -32
  176. data/lib/dragonfly/simple_cache.rb +0 -23
  177. data/spec/dragonfly/active_model_extensions/spec_helper.rb +0 -95
  178. data/spec/dragonfly/analyser_spec.rb +0 -123
  179. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +0 -49
  180. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +0 -84
  181. data/spec/dragonfly/data_storage/file_data_store_spec.rb +0 -308
  182. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +0 -81
  183. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +0 -277
  184. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +0 -77
  185. data/spec/dragonfly/function_manager_spec.rb +0 -154
  186. data/spec/dragonfly/image_magick/analyser_spec.rb +0 -73
  187. data/spec/dragonfly/image_magick/encoder_spec.rb +0 -46
  188. data/spec/dragonfly/image_magick/generator_spec.rb +0 -178
  189. data/spec/dragonfly/image_magick/processor_spec.rb +0 -293
  190. data/spec/dragonfly/job_builder_spec.rb +0 -37
  191. data/spec/dragonfly/job_definitions_spec.rb +0 -57
  192. data/spec/dragonfly/loggable_spec.rb +0 -80
  193. data/spec/dragonfly/simple_cache_spec.rb +0 -27
  194. data/spec/dragonfly/url_attributes.rb +0 -47
  195. data/spec/functional/deprecations_spec.rb +0 -51
  196. data/spec/functional/image_magick_app_spec.rb +0 -27
  197. data/spec/test_imagemagick.ru +0 -49
  198. data/yard/handlers/configurable_attr_handler.rb +0 -38
  199. data/yard/setup.rb +0 -15
  200. data/yard/templates/default/fulldoc/html/css/common.css +0 -109
  201. data/yard/templates/default/layout/html/layout.erb +0 -93
  202. data/yard/templates/default/module/html/configuration_summary.erb +0 -31
  203. data/yard/templates/default/module/setup.rb +0 -17
@@ -1,6 +0,0 @@
1
- module Dragonfly
2
- module Processing
3
- puts "WARNING: Dragonfly::Processing::ImageMagickProcessor is DEPRECATED and will soon be removed. Please use Dragonfly::ImageMagick::Processor instead."
4
- ImageMagickProcessor = ImageMagick::Processor
5
- end
6
- end
@@ -1,9 +0,0 @@
1
- module Dragonfly
2
- class Processor < FunctionManager
3
-
4
- def process(temp_object, method, *args)
5
- call_last(method, temp_object, *args)
6
- end
7
-
8
- end
9
- end
@@ -1,32 +0,0 @@
1
- require 'uri'
2
- require 'dragonfly'
3
- begin
4
- require 'rack/cache'
5
- rescue LoadError => e
6
- puts "Couldn't find rack-cache - make sure you have it in your Gemfile:"
7
- puts " gem 'rack-cache', :require => 'rack/cache'"
8
- puts " or configure dragonfly manually instead of using 'dragonfly/rails/images'"
9
- raise e
10
- end
11
-
12
- ### The dragonfly app ###
13
- app = Dragonfly[:images]
14
- app.configure_with(:rails)
15
- app.configure_with(:imagemagick)
16
-
17
- ### Extend active record ###
18
- if defined?(ActiveRecord::Base)
19
- app.define_macro(ActiveRecord::Base, :image_accessor)
20
- app.define_macro(ActiveRecord::Base, :file_accessor)
21
- end
22
-
23
- ### Insert the middleware ###
24
- rack_cache_already_inserted = Rails.application.config.action_controller.perform_caching && Rails.application.config.action_dispatch.rack_cache
25
-
26
- Rails.application.middleware.insert 0, Rack::Cache, {
27
- :verbose => true,
28
- :metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
29
- :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
30
- } unless rack_cache_already_inserted
31
-
32
- Rails.application.middleware.insert_after Rack::Cache, Dragonfly::Middleware, :images
@@ -1,23 +0,0 @@
1
- module Dragonfly
2
- class SimpleCache < Hash
3
-
4
- def initialize(max_size)
5
- @max_size = max_size
6
- @keys = []
7
- end
8
-
9
- attr_reader :max_size
10
-
11
- def []=(key, value)
12
- if !has_key?(key)
13
- @keys << key
14
- if size == max_size
15
- key_to_purge = @keys.shift
16
- delete(key_to_purge)
17
- end
18
- end
19
- super
20
- end
21
-
22
- end
23
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
- require 'active_model'
3
-
4
- # --------------------------------------------------------------- #
5
- # MODELS
6
- # --------------------------------------------------------------- #
7
- class MyModel
8
-
9
- # Callbacks
10
- extend ActiveModel::Callbacks
11
- define_model_callbacks :save, :destroy
12
-
13
- include ActiveModel::Validations
14
- include ActiveModel::Dirty
15
-
16
- class << self
17
- def create!(attrs={})
18
- new(attrs).save!
19
- end
20
-
21
- def find(id)
22
- new(instances[id])
23
- end
24
-
25
- def instances
26
- @instances ||= {}
27
- end
28
- end
29
-
30
- def initialize(attrs={})
31
- attrs.each do |key, value|
32
- send("#{key}=", value)
33
- end
34
- end
35
-
36
- attr_accessor :id
37
-
38
- def to_hash
39
- self.class::ATTRIBUTES.inject({}) do |hash, attr|
40
- hash[attr] = send(attr)
41
- hash
42
- end
43
- end
44
-
45
- def save
46
- _run_save_callbacks {
47
- self.id ||= rand(1000)
48
- self.class.instances[id] = self.to_hash
49
- }
50
- end
51
- def save!
52
- save
53
- self
54
- end
55
-
56
- def destroy
57
- _run_destroy_callbacks {}
58
- end
59
- end
60
-
61
- class Item < MyModel
62
-
63
- ATTRIBUTES = [
64
- :title,
65
- :preview_image_uid,
66
- :preview_image_some_analyser_method,
67
- :preview_image_size,
68
- :preview_image_name,
69
- :preview_image_blah_blah,
70
- :other_image_uid,
71
- :yet_another_image_uid,
72
- :otra_imagen_uid,
73
- :trailer_video_uid,
74
- :created_at,
75
- :updated_at
76
- ]
77
- define_attribute_methods ATTRIBUTES
78
- attr_accessor *ATTRIBUTES
79
- end
80
-
81
- class Car < MyModel
82
- ATTRIBUTES = [
83
- :image_uid,
84
- :reliant_image_uid,
85
- :type
86
- ]
87
- define_attribute_methods ATTRIBUTES
88
- attr_accessor *ATTRIBUTES
89
- end
90
-
91
- class Photo < MyModel
92
- ATTRIBUTES = [:image_uid]
93
- define_attribute_methods ATTRIBUTES
94
- attr_accessor *ATTRIBUTES
95
- end
@@ -1,123 +0,0 @@
1
- require '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
@@ -1,49 +0,0 @@
1
- require '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
- pending "not applicable to windows" if Dragonfly.running_on_windows?
9
- @analyser = Dragonfly::Analysis::FileCommandAnalyser.new
10
- end
11
-
12
- describe "mime_type" do
13
-
14
- describe "when using the filesystem" do
15
- before(:each) do
16
- @analyser.use_filesystem = true
17
- @temp_object = Dragonfly::TempObject.new(File.new(png_path))
18
- end
19
- it "should give the mime-type" do
20
- @analyser.mime_type(@temp_object).should == 'image/png'
21
- end
22
- it "should not have initialized the data string" do
23
- @analyser.mime_type(@temp_object)
24
- @temp_object.instance_eval{@data}.should be_nil
25
- end
26
- end
27
-
28
- describe "when not using the filesystem" do
29
- before(:each) do
30
- @analyser.use_filesystem = false
31
- @temp_object = Dragonfly::TempObject.new(File.read(png_path))
32
- end
33
- it "should give the mime-type" do
34
- @analyser.mime_type(@temp_object).should == 'image/png'
35
- end
36
- it "should not have initialized the file" do
37
- @analyser.mime_type(@temp_object)
38
- @temp_object.instance_eval{@tempfile}.should be_nil
39
- end
40
- it "should work properly (without a broken pipe error) for big files of format jpg" do
41
- data = Dragonfly::ImageMagick::Generator.new.plasma(1000, 1000, :jpg).first
42
- temp_object = Dragonfly::TempObject.new(data)
43
- @analyser.mime_type(temp_object).should == "image/jpeg"
44
- end
45
- end
46
-
47
- end
48
-
49
- end
@@ -1,84 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require File.dirname(__FILE__) + '/shared_data_store_examples'
4
- require 'net/http'
5
- require 'uri'
6
-
7
- describe Dragonfly::DataStorage::CouchDataStore do
8
-
9
- before(:each) do
10
- WebMock.allow_net_connect!
11
- @data_store = Dragonfly::DataStorage::CouchDataStore.new(
12
- :database => "dragonfly_test"
13
- )
14
- begin
15
- @data_store.db.get('ping')
16
- rescue Errno::ECONNREFUSED => e
17
- pending "You need to start CouchDB on localhost:5984 to test the CouchDataStore"
18
- rescue RestClient::ResourceNotFound
19
- end
20
-
21
- end
22
-
23
- it_should_behave_like 'data_store'
24
-
25
- describe "destroy" do
26
- before(:each) do
27
- @temp_object = Dragonfly::TempObject.new('gollum')
28
- end
29
-
30
- it "should raise an error if the data doesn't exist on destroy" do
31
- uid = @data_store.store(@temp_object)
32
- @data_store.destroy(uid)
33
- lambda{
34
- @data_store.destroy(uid)
35
- }.should raise_error(Dragonfly::DataStorage::DataNotFound)
36
- end
37
- end
38
-
39
- describe "url_for" do
40
- it "should give the correct url" do
41
- @data_store.url_for('asd7fas9df/thing.txt').should == 'http://localhost:5984/dragonfly_test/asd7fas9df/thing.txt'
42
- end
43
-
44
- it "should assume the attachment is called 'file' if not given" do
45
- @data_store.url_for('asd7fas9df').should == 'http://localhost:5984/dragonfly_test/asd7fas9df/file'
46
- end
47
- end
48
-
49
- describe "serving from couchdb" do
50
-
51
- def get_content(url)
52
- uri = URI.parse(url)
53
- Net::HTTP.start(uri.host, uri.port) {|http|
54
- http.get(uri.path)
55
- }
56
- end
57
-
58
- before(:each) do
59
- @temp_object = Dragonfly::TempObject.new('testingyo')
60
- end
61
-
62
- it "should use the fallback by default" do
63
- uid = @data_store.store(@temp_object)
64
- response = get_content(@data_store.url_for(uid))
65
- response.body.should == 'testingyo'
66
- response['Content-Type'].should == 'application/octet-stream'
67
- end
68
-
69
- it "should allow setting on store with 'content_type'" do
70
- uid = @data_store.store(@temp_object, :content_type => 'text/plain')
71
- response = get_content(@data_store.url_for(uid))
72
- response.body.should == 'testingyo'
73
- response['Content-Type'].should == 'text/plain'
74
- end
75
-
76
- it "should allow setting on store with 'mime_type'" do
77
- uid = @data_store.store(@temp_object, :mime_type => 'text/plain-yo')
78
- response = get_content(@data_store.url_for(uid))
79
- response.body.should == 'testingyo'
80
- response['Content-Type'].should == 'text/plain-yo'
81
- end
82
- end
83
-
84
- end
@@ -1,308 +0,0 @@
1
- require 'spec_helper'
2
- require File.dirname(__FILE__) + '/shared_data_store_examples'
3
-
4
- describe Dragonfly::DataStorage::FileDataStore do
5
-
6
- def touch_file(filename)
7
- FileUtils.mkdir_p(File.dirname(filename))
8
- FileUtils.touch(filename)
9
- end
10
-
11
- def assert_exists(path)
12
- File.exists?(path).should be_true
13
- end
14
-
15
- before(:each) do
16
- @data_store = Dragonfly::DataStorage::FileDataStore.new
17
- @data_store.root_path = 'tmp/file_data_store_test'
18
- @temp_object = Dragonfly::TempObject.new('goobydoo')
19
- end
20
-
21
- after(:each) do
22
- # Clean up created files
23
- FileUtils.rm_rf("#{@data_store.root_path}")
24
- end
25
-
26
- it_should_behave_like 'data_store'
27
-
28
- describe "store" do
29
-
30
- before(:each) do
31
- # Set 'now' to a date in the past
32
- Time.stub!(:now).and_return Time.mktime(1984,"may",4,14,28,1)
33
- @file_pattern_prefix_without_root = '1984/05/04/14_28_01_0_'
34
- @file_pattern_prefix = "#{@data_store.root_path}/#{@file_pattern_prefix_without_root}"
35
- end
36
-
37
- it "should store the file in a folder based on date, with default filename" do
38
- @data_store.store(@temp_object)
39
- assert_exists "#{@file_pattern_prefix}file"
40
- end
41
-
42
- it "should use the temp_object name if it exists" do
43
- @temp_object.should_receive(:name).at_least(:once).and_return('hello.there')
44
- @data_store.store(@temp_object)
45
- assert_exists "#{@file_pattern_prefix}hello.there"
46
- end
47
-
48
- it "should get rid of funny characters in the temp_object name" do
49
- @temp_object.should_receive(:name).at_least(:once).and_return('A Picture with many spaces in its name (at 20:00 pm).png')
50
- @data_store.store(@temp_object)
51
- assert_exists "#{@file_pattern_prefix}A_Picture_with_many_spaces_in_its_name_at_20_00_pm_.png"
52
- end
53
-
54
- describe "when the filename already exists" do
55
-
56
- it "should use a different filename" do
57
- touch_file("#{@file_pattern_prefix}file")
58
- @data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file").and_return("#{@file_pattern_prefix}file_2")
59
- @data_store.store(@temp_object)
60
- assert_exists "#{@file_pattern_prefix}file_2"
61
- end
62
-
63
- it "should use a different filename taking into account the name and ext" do
64
- @temp_object.should_receive(:name).at_least(:once).and_return('hello.png')
65
- touch_file("#{@file_pattern_prefix}hello.png")
66
- @data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}hello.png").and_return("#{@file_pattern_prefix}blah.png")
67
- @data_store.store(@temp_object)
68
- end
69
-
70
- it "should keep trying until it finds a free filename" do
71
- touch_file("#{@file_pattern_prefix}file")
72
- touch_file("#{@file_pattern_prefix}file_2")
73
- @data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file").and_return("#{@file_pattern_prefix}file_2")
74
- @data_store.should_receive(:disambiguate).with("#{@file_pattern_prefix}file_2").and_return("#{@file_pattern_prefix}file_3")
75
- @data_store.store(@temp_object)
76
- assert_exists "#{@file_pattern_prefix}file_3"
77
- end
78
-
79
- describe "specifying the uid" do
80
- it "should allow for specifying the path to use" do
81
- @data_store.store(@temp_object, :path => 'hello/there/mate.png')
82
- assert_exists "#{@data_store.root_path}/hello/there/mate.png"
83
- end
84
- it "should correctly disambiguate if the file exists" do
85
- touch_file("#{@data_store.root_path}/hello/there/mate.png")
86
- @data_store.should_receive(:disambiguate).with("#{@data_store.root_path}/hello/there/mate.png").and_return("#{@data_store.root_path}/hello/there/mate_2.png")
87
- @data_store.store(@temp_object, :path => 'hello/there/mate.png')
88
- assert_exists "#{@data_store.root_path}/hello/there/mate_2.png"
89
- end
90
- end
91
-
92
- end
93
-
94
- describe "return value" do
95
-
96
- it "should return the filepath without the root of the stored file when a file name is not provided" do
97
- @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}file"
98
- end
99
-
100
- it "should return the filepath without the root of the stored file when a file name is provided" do
101
- @temp_object.should_receive(:name).at_least(:once).and_return('hello.you.png')
102
- @data_store.store(@temp_object).should == "#{@file_pattern_prefix_without_root}hello.you.png"
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- describe "disambiguate" do
110
- it "should add a suffix" do
111
- @data_store.disambiguate('/some/file').should =~ %r{^/some/file_\w+$}
112
- end
113
- it "should add a suffix to the basename" do
114
- @data_store.disambiguate('/some/file.png').should =~ %r{^/some/file_\w+\.png$}
115
- end
116
- it "should be random(-ish)" do
117
- @data_store.disambiguate('/some/file').should_not == @data_store.disambiguate('/some/file')
118
- end
119
- end
120
-
121
- describe "errors" do
122
-
123
- it "should raise an error if it can't create a directory" do
124
- FileUtils.should_receive(:mkdir_p).and_raise(Errno::EACCES)
125
- lambda{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::DataStorage::UnableToStore)
126
- end
127
-
128
- it "should raise an error if it can't create a file" do
129
- @temp_object.should_receive(:to_file).and_raise(Errno::EACCES)
130
- lambda{ @data_store.store(@temp_object) }.should raise_error(Dragonfly::DataStorage::UnableToStore)
131
- end
132
-
133
- end
134
-
135
- describe "retrieve" do
136
- it "should return a pathname" do
137
- uid = @data_store.store(@temp_object)
138
- pathname, meta = @data_store.retrieve(uid)
139
- pathname.should be_a(Pathname)
140
- end
141
-
142
- it "should be able to retrieve any file, stored or not (and without meta data)" do
143
- FileUtils.mkdir_p("#{@data_store.root_path}/jelly_beans/are")
144
- File.open("#{@data_store.root_path}/jelly_beans/are/good", 'w'){|f| f.write('hey dog') }
145
- pathname, meta = @data_store.retrieve("jelly_beans/are/good")
146
- pathname.read.should == 'hey dog'
147
- meta.should == {}
148
- end
149
-
150
- it "should work even if meta is stored in old .extra file" do
151
- @temp_object.meta = {:dog => 'foog'}
152
- uid = @data_store.store(@temp_object)
153
- FileUtils.mv("#{@data_store.root_path}/#{uid}.meta", "#{@data_store.root_path}/#{uid}.extra")
154
- pathname, meta = @data_store.retrieve(uid)
155
- meta.should == {:dog => 'foog'}
156
- end
157
-
158
- it "should raise a BadUID error if the file path has ../ in it" do
159
- expect{
160
- @data_store.retrieve('jelly_beans/../are/good')
161
- }.to raise_error(Dragonfly::DataStorage::BadUID)
162
- end
163
-
164
- it "should not raise a BadUID error if the file path has .. but not ../ in it" do
165
- expect{
166
- @data_store.retrieve('jelly_beans..good')
167
- }.to raise_error(Dragonfly::DataStorage::DataNotFound)
168
- end
169
- end
170
-
171
- describe "destroying" do
172
- it "should prune empty directories when destroying" do
173
- uid = @data_store.store(@temp_object)
174
- @data_store.destroy(uid)
175
- @data_store.root_path.should be_an_empty_directory
176
- end
177
-
178
- it "should not prune root_path directory when destroying file without directory prefix in path" do
179
- uid = @data_store.store(@temp_object, :path => 'mate.png')
180
- @data_store.destroy(uid)
181
- @data_store.root_path.should be_an_empty_directory
182
- end
183
-
184
- it "should raise an error if the data doesn't exist on destroy" do
185
- uid = @data_store.store(@temp_object)
186
- @data_store.destroy(uid)
187
- lambda{
188
- @data_store.destroy(uid)
189
- }.should raise_error(Dragonfly::DataStorage::DataNotFound)
190
- end
191
-
192
- it "should also destroy old .extra files" do
193
- uid = @data_store.store(@temp_object)
194
- FileUtils.cp("#{@data_store.root_path}/#{uid}.meta", "#{@data_store.root_path}/#{uid}.extra")
195
- @data_store.destroy(uid)
196
- File.exist?("#{@data_store.root_path}/#{uid}").should be_false
197
- File.exist?("#{@data_store.root_path}/#{uid}.meta").should be_false
198
- File.exist?("#{@data_store.root_path}/#{uid}.extra").should be_false
199
- end
200
-
201
- it "should raise an error if the file path has ../ in it" do
202
- expect{
203
- @data_store.destroy('jelly_beans/../are/good')
204
- }.to raise_error(Dragonfly::DataStorage::BadUID)
205
- end
206
- end
207
-
208
- describe "relative paths" do
209
- let(:store) { Dragonfly::DataStorage::FileDataStore.new }
210
- let(:relative_path) { "2011/02/11/picture.jpg" }
211
- let(:absolute_path) { "#{root_path}#{relative_path}" }
212
- let(:root_path) { "/path/to/file/" }
213
-
214
- before do
215
- store.root_path = root_path
216
- end
217
-
218
- subject { store.send :relative, absolute_path }
219
-
220
- it { should == relative_path }
221
-
222
- context "where root path contains spaces" do
223
- let(:root_path) { "/path/to/file name/" }
224
- it { should == relative_path }
225
- end
226
- context "where root path contains special chars" do
227
- let(:root_path) { "/path/to/file name (Special backup directory)/" }
228
- it { should == relative_path }
229
- end
230
- end
231
-
232
- describe "turning meta off" do
233
- before(:each) do
234
- @data_store.store_meta = false
235
- @temp_object.meta = {:bitrate => '35', :name => 'danny.boy'}
236
- end
237
-
238
- it "should not write a meta file" do
239
- uid = @data_store.store(@temp_object)
240
- path = File.join(@data_store.root_path, uid) + '.meta'
241
- File.exist?(path).should be_false
242
- end
243
-
244
- it "should return an empty hash on retrieve" do
245
- uid = @data_store.store(@temp_object)
246
- obj, meta = @data_store.retrieve(uid)
247
- meta.should == {}
248
- end
249
-
250
- it "should still destroy the meta file if it exists" do
251
- @data_store.store_meta = true
252
- uid = @data_store.store(@temp_object)
253
- @data_store.store_meta = false
254
- @data_store.destroy(uid)
255
- @data_store.root_path.should be_an_empty_directory
256
- end
257
-
258
- it "should still destroy properly if meta is on but the meta file doesn't exist" do
259
- uid = @data_store.store(@temp_object)
260
- @data_store.store_meta = true
261
- @data_store.destroy(uid)
262
- @data_store.root_path.should be_an_empty_directory
263
- end
264
- end
265
-
266
- describe "urls for serving directly" do
267
- before(:each) do
268
- @uid = 'some/path/to/file.png'
269
- @data_store.root_path = '/var/tmp/eggs'
270
- end
271
-
272
- it "should raise an error if called without configuring" do
273
- expect{
274
- @data_store.url_for(@uid)
275
- }.to raise_error(Dragonfly::Configurable::NotConfigured)
276
- end
277
-
278
- it "should work as expected when the the server root is above the root path" do
279
- @data_store.server_root = '/var/tmp'
280
- @data_store.url_for(@uid).should == '/eggs/some/path/to/file.png'
281
- end
282
-
283
- it "should work as expected when the the server root is the root path" do
284
- @data_store.server_root = '/var/tmp/eggs'
285
- @data_store.url_for(@uid).should == '/some/path/to/file.png'
286
- end
287
-
288
- it "should work as expected when the the server root is below the root path" do
289
- @data_store.server_root = '/var/tmp/eggs/some/path'
290
- @data_store.url_for(@uid).should == '/to/file.png'
291
- end
292
-
293
- it "should raise an error when the server root doesn't coincide with the root path" do
294
- @data_store.server_root = '/var/blimey/eggs'
295
- expect{
296
- @data_store.url_for(@uid)
297
- }.to raise_error(Dragonfly::DataStorage::FileDataStore::UnableToFormUrl)
298
- end
299
-
300
- it "should raise an error when the server root doesn't coincide with the uid" do
301
- @data_store.server_root = '/var/tmp/eggs/some/gooney'
302
- expect{
303
- @data_store.url_for(@uid)
304
- }.to raise_error(Dragonfly::DataStorage::FileDataStore::UnableToFormUrl)
305
- end
306
- end
307
-
308
- end