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
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'logger'
3
+ require 'stringio'
4
+
5
+ describe Dragonfly do
6
+ it "returns a default app" do
7
+ Dragonfly.app.should == Dragonfly::App.instance
8
+ end
9
+
10
+ it "returns a named app" do
11
+ Dragonfly.app(:mine).should == Dragonfly::App.instance(:mine)
12
+ end
13
+
14
+ describe "logging" do
15
+ before do
16
+ Dragonfly.logger = Logger.new(StringIO.new)
17
+ end
18
+
19
+ it "debugs" do
20
+ Dragonfly.logger.should_receive(:debug).with(/something/)
21
+ Dragonfly.debug("something")
22
+ end
23
+
24
+ it "warns" do
25
+ Dragonfly.logger.should_receive(:warn).with(/something/)
26
+ Dragonfly.warn("something")
27
+ end
28
+
29
+ it "shows info" do
30
+ Dragonfly.logger.should_receive(:info).with(/something/)
31
+ Dragonfly.info("something")
32
+ end
33
+ end
34
+
35
+ describe "deprecations" do
36
+ it "raises a message when using Dragonfly[:name]" do
37
+ expect {
38
+ Dragonfly[:images]
39
+ }.to raise_error(/deprecated/)
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1 @@
1
+ {: nameI"eggs.bonus:ET: someI" meta;T: numberi
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "configuration" do
4
+ let (:app) { test_app }
5
+
6
+ it "adds to fetch_file_whitelist" do
7
+ app.configure do
8
+ fetch_file_whitelist ['something']
9
+ end
10
+ app.fetch_file_whitelist.should include 'something'
11
+ end
12
+
13
+ it "adds to fetch_url_whitelist" do
14
+ app.configure do
15
+ fetch_url_whitelist ['http://something']
16
+ end
17
+ app.fetch_url_whitelist.should include 'http://something'
18
+ end
19
+ end
@@ -1,44 +1,46 @@
1
- require 'dragonfly/active_model_extensions/spec_helper'
1
+ require 'spec_helper'
2
2
  require 'tempfile'
3
3
 
4
4
  describe "model urls" do
5
-
5
+
6
6
  def new_tempfile(data='HELLO', filename='hello.txt')
7
7
  tempfile = Tempfile.new('test')
8
8
  tempfile.write(data)
9
9
  tempfile.rewind
10
- tempfile.stub!(:original_filename).and_return(filename)
10
+ tempfile.stub(:original_filename).and_return(filename)
11
11
  tempfile
12
12
  end
13
-
13
+
14
14
  before(:each) do
15
- @app = test_app.configure do |c|
16
- c.url_format = '/media/:job/:basename.:format'
17
- c.analyser.add :some_analyser_method do |t|
15
+ @app = test_app.configure do
16
+ plugin :imagemagick
17
+ url_format '/media/:job/:name'
18
+ analyser :some_analyser_method do |t|
18
19
  53
19
20
  end
20
- c.processor.add :upcase do |t|
21
- t.data.upcase
22
- end
23
21
  end
24
- @app.define_macro(MyModel, :image_accessor)
25
- Item.class_eval do
26
- image_accessor :preview_image # has name, some_analyser_method, etc.
27
- image_accessor :other_image # doesn't have magic stuff
22
+ @item_class = new_model_class('Item',
23
+ :preview_image_uid,
24
+ :preview_image_name,
25
+ :preview_image_some_analyser_method,
26
+ :other_image_uid
27
+ ) do
28
+ dragonfly_accessor :preview_image # has name, some_analyser_method, etc.
29
+ dragonfly_accessor :other_image # doesn't have magic stuff
28
30
  end
29
- @item = Item.new
31
+ @item = @item_class.new
30
32
  end
31
-
33
+
32
34
  it "should include the name in the url if it has the magic attribute" do
33
35
  @item.preview_image = new_tempfile
34
36
  @item.save!
35
37
  @item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt$}
36
38
  end
37
-
39
+
38
40
  it "should still include the name in the url if it has the magic attribute on reload" do
39
41
  @item.preview_image = new_tempfile
40
42
  @item.save!
41
- item = Item.find(@item.id)
43
+ item = @item_class.find(@item.id)
42
44
  item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt$}
43
45
  end
44
46
 
@@ -47,74 +49,74 @@ describe "model urls" do
47
49
  @item.preview_image = new_tempfile
48
50
  @item.save!
49
51
  @item.preview_image.url.should =~ %r{^/\w+/53$}
50
- Item.find(@item.id).preview_image.url.should =~ %r{^/\w+/53$}
52
+ @item_class.find(@item.id).preview_image.url.should =~ %r{^/\w+/53$}
51
53
  end
52
-
54
+
53
55
  it "should work without the name if the name magic attr doesn't exist" do
54
56
  @item.other_image = new_tempfile
55
57
  @item.save!
56
- item = Item.find(@item.id)
58
+ item = @item_class.find(@item.id)
57
59
  item.other_image.url.should =~ %r{^/media/\w+$}
58
60
  end
59
-
61
+
60
62
  it "should not add the name when there's no magic attr, even if the name is set (for consistency)" do
61
63
  @item.other_image = new_tempfile
62
64
  @item.save!
63
65
  @item.other_image.name = 'test.txt'
64
66
  @item.other_image.url.should =~ %r{^/media/\w+$}
65
67
  end
66
-
68
+
67
69
  it "should include the name in the url even if it has no ext" do
68
70
  @item.preview_image = new_tempfile("hello", 'hello')
69
71
  @item.save!
70
- item = Item.find(@item.id)
72
+ item = @item_class.find(@item.id)
71
73
  item.preview_image.url.should =~ %r{^/media/\w+/hello$}
72
74
  end
73
-
75
+
74
76
  it "should change the ext when there's an encoding step" do
75
77
  @item.preview_image = new_tempfile
76
78
  @item.save!
77
- item = Item.find(@item.id)
79
+ item = @item_class.find(@item.id)
78
80
  item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/hello\.bum$}
79
81
  end
80
-
82
+
81
83
  it "should not include the name if it has none" do
82
84
  @item.preview_image = "HELLO"
83
85
  @item.save!
84
- item = Item.find(@item.id)
86
+ item = @item_class.find(@item.id)
85
87
  item.preview_image.url.should =~ %r{^/media/\w+$}
86
88
  end
87
-
89
+
88
90
  it "should have an ext when there's an encoding step but no name" do
89
91
  @item.preview_image = "HELLO"
90
92
  @item.save!
91
- item = Item.find(@item.id)
92
- item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+\.bum$}
93
+ item = @item_class.find(@item.id)
94
+ item.preview_image.encode(:bum).url.should =~ %r{^/media/\w+/file\.bum$}
93
95
  end
94
-
96
+
95
97
  it "should work as normal with dos protection" do
96
98
  @app.server.protect_from_dos_attacks = true
97
99
  @item.preview_image = new_tempfile
98
100
  @item.save!
99
- item = Item.find(@item.id)
101
+ item = @item_class.find(@item.id)
100
102
  item.preview_image.url.should =~ %r{^/media/\w+/hello\.txt\?sha=\w+$}
101
103
  end
102
-
104
+
103
105
  it "should allow configuring the url" do
104
- @app.configure do |c|
105
- c.url_format = '/img/:job'
106
+ @app.configure do
107
+ url_format '/img/:job'
106
108
  end
107
109
  @item.preview_image = new_tempfile
108
110
  @item.save!
109
- item = Item.find(@item.id)
111
+ item = @item_class.find(@item.id)
110
112
  item.preview_image.url.should =~ %r{^/img/\w+$}
111
113
  end
112
114
 
113
115
  it "should still get params from magic attributes even when chained" do
114
116
  @item.preview_image = new_tempfile
115
117
  @item.save!
116
- item = Item.find(@item.id)
117
- item.preview_image.process(:upcase).url.should =~ %r{^/media/\w+/hello\.txt$}
118
+ item = @item_class.find(@item.id)
119
+ item.preview_image.thumb('30x30').url.should =~ %r{^/media/\w+/hello\.txt$}
118
120
  end
119
-
120
- end
121
+
122
+ end
@@ -1,42 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "remote on-the-fly urls" do
4
-
5
- THUMBS = {}
6
-
4
+
7
5
  before(:each) do
8
- @app = test_app.configure do |c|
9
- c.generator.add :test do
10
- "TEST"
6
+ @thumbs = thumbs = {}
7
+ @app = test_app.configure do
8
+ generator :test do |content|
9
+ content.update("TEST")
11
10
  end
12
- c.server.before_serve do |job, env|
11
+ before_serve do |job, env|
13
12
  uid = job.store(:path => 'yay.txt')
14
- THUMBS[job.serialize] = uid
13
+ thumbs[job.serialize] = uid
15
14
  end
16
- c.define_url do |app, job, opts|
17
- uid = THUMBS[job.serialize]
15
+ define_url do |app, job, opts|
16
+ uid = thumbs[job.serialize]
18
17
  if uid
19
18
  app.datastore.url_for(uid)
20
19
  else
21
20
  app.server.url_for(job)
22
21
  end
23
22
  end
24
- c.datastore = Dragonfly::DataStorage::FileDataStore.new
25
- c.datastore.root_path = 'tmp/dragonfly_test_urls'
26
- c.datastore.server_root = 'tmp'
23
+ datastore :file,
24
+ :root_path => 'tmp/dragonfly_test_urls',
25
+ :server_root => 'tmp'
27
26
  end
28
27
  @job = @app.generate(:test)
29
28
  end
30
29
 
31
30
  after(:each) do
32
- THUMBS.delete_if{true}
33
31
  FileUtils.rm_f('tmp/dragonfly_test_urls/yay.txt')
34
32
  end
35
-
33
+
36
34
  it "should give the url for the server" do
37
35
  @job.url.should == "/#{@job.serialize}"
38
36
  end
39
-
37
+
40
38
  it "should store the content when first called" do
41
39
  File.exist?('tmp/dragonfly_test_urls/yay.txt').should be_false
42
40
  @app.server.call('PATH_INFO' => @job.url, 'REQUEST_METHOD' => 'GET')
@@ -1,23 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "a configured imagemagick app" do
4
-
5
- before(:each) do
6
- @app = test_app.configure_with(:imagemagick)
7
- end
8
-
3
+ describe "using the shell" do
4
+
5
+ let (:app) { test_app }
6
+
9
7
  describe "shell injection" do
10
-
11
8
  it "should not allow it!" do
9
+ app.configure_with(:imagemagick)
12
10
  begin
13
- suppressing_stderr do
14
- @app.generate(:plain, 10, 10, 'white').convert("-resize 5x5 ; touch tmp/stuff").apply
15
- end
16
- rescue Dragonfly::FunctionManager::UnableToHandle
11
+ app.generate(:plain, 10, 10, 'white').convert("-resize 5x5 ; touch tmp/stuff").apply
12
+ rescue Dragonfly::Shell::CommandFailed
17
13
  end
18
14
  File.exist?('tmp/stuff').should be_false
19
15
  end
20
-
21
16
  end
22
-
23
- end
17
+
18
+ describe "env variables with imagemagick" do
19
+ it "allows configuring the convert path" do
20
+ app.configure_with(:imagemagick, :convert_command => '/bin/convert')
21
+ app.shell.should_receive(:run).with(%r[/bin/convert], hash_including)
22
+ app.create("").thumb('30x30').apply
23
+ end
24
+
25
+ it "allows configuring the identify path" do
26
+ app.configure_with(:imagemagick, :identify_command => '/bin/identify')
27
+ app.shell.should_receive(:run).with(%r[/bin/identify], hash_including).and_return("JPG 1 1")
28
+ app.create("").width
29
+ end
30
+ end
31
+
32
+ end
33
+
@@ -1,31 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "getting rack response directly" do
4
-
4
+
5
5
  before(:each) do
6
- @app = test_app.configure do |c|
7
- c.generator.add :test do
8
- "bunheads"
6
+ @app = test_app.configure do
7
+ generator :test do |content|
8
+ content.update("bunheads")
9
9
  end
10
10
  end
11
11
  end
12
-
12
+
13
13
  it "should give a rack response" do
14
- response = @app.generate(:test, 1, 1).to_response
14
+ response = @app.generate(:test).to_response
15
15
  response.should be_a(Array)
16
16
  response.length.should == 3
17
17
  response[0].should == 200
18
18
  response[1]['Content-Type'].should == 'application/octet-stream'
19
19
  response[2].data.should == 'bunheads'
20
20
  end
21
-
21
+
22
22
  it "should allow passing in the env" do
23
- response = @app.generate(:test, 1, 1).to_response('REQUEST_METHOD' => 'POST')
23
+ response = @app.generate(:test).to_response('REQUEST_METHOD' => 'POST')
24
24
  response.should be_a(Array)
25
25
  response.length.should == 3
26
26
  response[0].should == 405
27
27
  response[1]['Content-Type'].should == 'text/plain'
28
- response[2].should == ["POST method not allowed"]
28
+ response[2].should == ["method not allowed"]
29
29
  end
30
-
30
+
31
31
  end
@@ -9,18 +9,20 @@ describe "urls" do
9
9
  def job_should_match(array)
10
10
  Dragonfly::Response.should_receive(:new).with do |job, env|
11
11
  job.to_a.should == array
12
- end.and_return(mock('response', :to_response => [200, {'Content-Type' => 'text/plain'}, ["OK"]]))
12
+ end.and_return(double('response', :to_response => [200, {'Content-Type' => 'text/plain'}, ["OK"]]))
13
13
  end
14
14
 
15
- let (:app) { test_app }
15
+ let (:app) { test_app.configure{ processor(:thumb){} } }
16
16
 
17
17
  it "works with old marshalled urls (including with tildes in them)" do
18
+ app.allow_legacy_urls = true
18
19
  url = "/BAhbBlsHOgZmSSIIPD4~BjoGRVQ"
19
20
  job_should_match [["f", "<>?"]]
20
21
  response = request(app, url)
21
22
  end
22
23
 
23
24
  it "blows up if it detects bad objects" do
25
+ app.allow_legacy_urls = true
24
26
  url = "/BAhvOhpEcmFnb25mbHk6OlRlbXBPYmplY3QIOgpAZGF0YUkiCWJsYWgGOgZFVDoXQG9yaWdpbmFsX2ZpbGVuYW1lMDoKQG1ldGF7AA"
25
27
  Dragonfly::Job.should_not_receive(:from_a)
26
28
  response = request(app, url)
@@ -40,7 +42,7 @@ describe "urls" do
40
42
  end
41
43
 
42
44
  it "works with potentially tricky url characters for the url" do
43
- url = app.fetch('uid []=~/+').url(:basename => 'name []=~/+')
45
+ url = app.fetch('uid []=~/+').url(:name => 'name []=~/+')
44
46
  url.should =~ %r(^/[\w%]+/name%20%5B%5D%3D%7E%2F%2B$)
45
47
  job_should_match [["f", "uid []=~/+"]]
46
48
  response = request(app, url)
@@ -7,49 +7,44 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
7
  require 'rspec'
8
8
  require 'dragonfly'
9
9
  require 'fileutils'
10
-
10
+ require 'tempfile'
11
11
  require 'webmock/rspec'
12
+ require 'pry'
12
13
 
13
14
  # Requires supporting files with custom matchers and macros, etc,
14
15
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
16
 
16
- SAMPLES_DIR = Pathname.new(File.expand_path(File.dirname(__FILE__) + '/../samples')) unless defined?(SAMPLES_DIR)
17
+ SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
18
+
19
+ RSpec.configure do |c|
20
+ c.include ModelHelpers
21
+ end
17
22
 
18
23
  def todo
19
24
  raise "TODO"
20
25
  end
21
26
 
22
27
  require 'logger'
23
- LOG_FILE = 'tmp/test.log' unless defined?(LOG_FILE)
28
+ LOG_FILE = 'tmp/test.log'
24
29
  FileUtils.rm_rf(LOG_FILE)
25
- def mock_app(extra_stubs={})
26
- mock('app', {
27
- :datastore => mock('datastore', :store => 'some_uid', :retrieve => ["SOME_DATA", {}], :destroy => nil),
28
- :processor => mock('processor', :process => "SOME_PROCESSED_DATA"),
29
- :encoder => mock('encoder', :encode => "SOME_ENCODED_DATA"),
30
- :analyser => mock('analyser', :analyse => "some_result", :analysis_methods => Module.new),
31
- :generator => mock('generator', :generate => "SOME_GENERATED_DATA"),
32
- :log => Logger.new(LOG_FILE),
33
- :cache_duration => 10000,
34
- :job_definitions => Module.new
35
- }.merge(extra_stubs)
36
- )
30
+ Dragonfly.logger = Logger.new(LOG_FILE)
31
+
32
+ RSpec.configure do |c|
33
+ c.after(:each) do
34
+ Dragonfly::App.destroy_apps
35
+ end
37
36
  end
38
37
 
39
- def test_app
40
- time = Time.now
41
- app = Dragonfly::App.send(:new, "test_#{time.sec}_#{time.usec}".to_sym)
42
- app.log = Logger.new(LOG_FILE)
43
- app.datastore.root_path = 'tmp/file_data_store_test'
38
+ def test_app(name=nil)
39
+ app = Dragonfly::App.instance(name)
40
+ app.datastore = Dragonfly::MemoryDataStore.new
44
41
  app
45
42
  end
46
43
 
47
- def suppressing_stderr
48
- original_stderr = $stderr.dup
49
- tempfile = Tempfile.new('stderr')
50
- $stderr.reopen(tempfile) rescue
51
- yield
52
- ensure
53
- tempfile.close!
54
- $stderr.reopen(original_stderr)
44
+ def test_imagemagick_app
45
+ test_app.configure do
46
+ generator :convert, Dragonfly::ImageMagick::Generators::Convert.new
47
+ processor :convert, Dragonfly::ImageMagick::Processors::Convert.new
48
+ analyser :image_properties, Dragonfly::ImageMagick::Analysers::ImageProperties.new
49
+ end
55
50
  end