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
@@ -2,33 +2,52 @@ require 'spec_helper'
2
2
 
3
3
  describe Dragonfly::Shell do
4
4
 
5
- include Dragonfly::Shell
5
+ let(:shell){ Dragonfly::Shell.new }
6
6
 
7
- it "should raise an error if the identify command isn't found" do
8
- suppressing_stderr do
9
- lambda{
10
- run "non-existent-command"
11
- }.should raise_error(Dragonfly::Shell::CommandFailed)
12
- end
7
+ it "returns the result of the command" do
8
+ shell.run("echo 10").strip.should == '10'
9
+ end
10
+
11
+ it "should raise an error if the command isn't found" do
12
+ lambda{
13
+ shell.run "non-existent-command"
14
+ }.should raise_error(Dragonfly::Shell::CommandFailed, /not found/)
13
15
  end
14
-
15
- describe "escaping args" do
16
- {
17
- %q(hello) => %q('hello'),
18
- %q("hello") => %q('hello'),
19
- %q('hello') => %q('hello'),
20
- %q(he\'llo) => %q('he'\''llo'),
21
- %q('he'\''llo') => %q('he'\''llo'),
22
- %q("he'llo") => %q('he'\''llo'),
23
- %q(hel$(lo)) => %q('hel$(lo)'),
24
- %q(hel\$(lo)) => %q('hel$(lo)'),
25
- %q('hel\$(lo)') => %q('hel\$(lo)')
26
- }.each do |args, escaped_args|
27
- it "should escape #{args.inspect} -> #{escaped_args.inspect}" do
28
- pending "not applicable to windows" if Dragonfly.running_on_windows?
29
- escape_args(args).should == escaped_args
16
+
17
+ it "should raise an error if the command fails" do
18
+ lambda{
19
+ shell.run "ls -j"
20
+ }.should raise_error(Dragonfly::Shell::CommandFailed, /option/)
21
+ end
22
+
23
+ unless Dragonfly.running_on_windows?
24
+
25
+ describe "escaping args" do
26
+ {
27
+ %q(hello) => %q('hello'),
28
+ %q("hello") => %q('hello'),
29
+ %q('hello') => %q('hello'),
30
+ %q(he\'llo) => %q('he'\''llo'),
31
+ %q('he'\''llo') => %q('he'\''llo'),
32
+ %q("he'llo") => %q('he'\''llo'),
33
+ %q(hel$(lo)) => %q('hel$(lo)'),
34
+ %q(hel\$(lo)) => %q('hel$(lo)'),
35
+ %q('hel\$(lo)') => %q('hel\$(lo)')
36
+ }.each do |args, escaped_args|
37
+ it "should escape #{args.inspect} -> #{escaped_args.inspect}" do
38
+ shell.escape_args(args).should == escaped_args
39
+ end
30
40
  end
31
41
  end
42
+
43
+ it "escapes commands by default" do
44
+ shell.run("echo `echo 1`").strip.should == "`echo 1`"
45
+ end
46
+
47
+ it "allows running non-escaped commands" do
48
+ shell.run("echo `echo 1`", :escape => false).strip.should == "1"
49
+ end
50
+
32
51
  end
33
-
52
+
34
53
  end
@@ -92,16 +92,6 @@ describe Dragonfly::TempObject do
92
92
  end
93
93
  end
94
94
 
95
- describe "tempfile" do
96
- it "should create a closed tempfile" do
97
- @temp_object.tempfile.should be_a(Tempfile)
98
- @temp_object.tempfile.should be_closed
99
- end
100
- it "should contain the correct data" do
101
- @temp_object.tempfile.open.read.should == 'HELLO'
102
- end
103
- end
104
-
105
95
  describe "path" do
106
96
  it "should return an absolute file path" do
107
97
  if Dragonfly.running_on_windows?
@@ -159,6 +149,15 @@ describe Dragonfly::TempObject do
159
149
  end
160
150
  end
161
151
 
152
+ describe "to_tempfile" do
153
+ it "returns a new open tempfile" do
154
+ tempfile = @temp_object.to_tempfile
155
+ tempfile.should be_a(Tempfile)
156
+ tempfile.path.should_not == @temp_object.path
157
+ tempfile.read.should == @temp_object.data
158
+ tempfile.should_not be_closed
159
+ end
160
+ end
162
161
  end
163
162
 
164
163
  describe "each" do
@@ -171,19 +170,12 @@ describe Dragonfly::TempObject do
171
170
  parts.last.bytesize.should <= 8192
172
171
  end
173
172
  end
174
-
173
+
175
174
  describe "closing" do
176
175
  before(:each) do
177
176
  @temp_object = new_temp_object("wassup")
178
177
  end
179
- it "should delete its tempfile" do
180
- tempfile = @temp_object.tempfile
181
- path = tempfile.path
182
- path.should_not be_empty
183
- @temp_object.close
184
- File.exist?(path).should be_false
185
- end
186
- %w(tempfile file data).each do |method|
178
+ %w(file data).each do |method|
187
179
  it "should raise error when calling #{method}" do
188
180
  @temp_object.close
189
181
  expect{
@@ -215,17 +207,21 @@ describe Dragonfly::TempObject do
215
207
  temp_object.should_not_receive(:tempfile)
216
208
  temp_object.each{}
217
209
  end
218
-
219
- it "should use set the file extension in path from the name" do
220
- temp_object = Dragonfly::TempObject.new("hi", :name => 'dark.cloud')
221
- temp_object.path.should =~ /\.cloud$/
210
+
211
+ it "should delete its internal tempfile on close" do
212
+ temp_object = new_temp_object("HELLO")
213
+ path = temp_object.path
214
+ File.exist?(path).should be_true
215
+ temp_object.close
216
+ File.exist?(path).should be_false
222
217
  end
223
- end
218
+
219
+ end
224
220
 
225
221
  describe "initializing from a tempfile" do
226
222
 
227
223
  def initialization_object(data)
228
- new_tempfile(data)
224
+ @tempfile = new_tempfile(data)
229
225
  end
230
226
 
231
227
  it_should_behave_like "common behaviour"
@@ -238,7 +234,15 @@ describe Dragonfly::TempObject do
238
234
 
239
235
  it "should return the tempfile's path" do
240
236
  temp_object = new_temp_object('HELLO')
241
- temp_object.path.should == temp_object.tempfile.path
237
+ temp_object.path.should == @tempfile.path
238
+ end
239
+
240
+ it "should delete its internal tempfile on close" do
241
+ temp_object = new_temp_object("HELLO")
242
+ path = temp_object.path
243
+ File.exist?(path).should be_true
244
+ temp_object.close
245
+ File.exist?(path).should be_false
242
246
  end
243
247
  end
244
248
 
@@ -261,7 +265,7 @@ describe Dragonfly::TempObject do
261
265
  temp_object = Dragonfly::TempObject.new(file)
262
266
  temp_object.path.should == File.expand_path(file.path)
263
267
  end
264
-
268
+
265
269
  it "should return an absolute path even if the file wasn't instantiated like that" do
266
270
  file = new_file('HELLO', 'tmp/bongo')
267
271
  temp_object = Dragonfly::TempObject.new(file)
@@ -273,6 +277,12 @@ describe Dragonfly::TempObject do
273
277
  file.close
274
278
  FileUtils.rm(file.path)
275
279
  end
280
+
281
+ it "doesn't remove the file on close" do
282
+ temp_object = new_temp_object("HELLO")
283
+ temp_object.close
284
+ File.exist?(temp_object.path).should be_true
285
+ end
276
286
  end
277
287
 
278
288
  describe "initializing from a pathname" do
@@ -294,7 +304,7 @@ describe Dragonfly::TempObject do
294
304
  temp_object = Dragonfly::TempObject.new(pathname)
295
305
  temp_object.path.should == File.expand_path(pathname.to_s)
296
306
  end
297
-
307
+
298
308
  it "should return an absolute path even if the pathname is relative" do
299
309
  pathname = new_pathname('HELLO', 'tmp/bingo')
300
310
  temp_object = Dragonfly::TempObject.new(pathname)
@@ -305,21 +315,28 @@ describe Dragonfly::TempObject do
305
315
  end
306
316
  pathname.delete
307
317
  end
318
+
319
+ it "doesn't remove the file on close" do
320
+ temp_object = new_temp_object("HELLO")
321
+ temp_object.close
322
+ File.exist?(temp_object.path).should be_true
323
+ end
324
+
308
325
  end
309
326
 
310
327
  describe "initializing from another temp object" do
311
-
328
+
312
329
  def initialization_object(data)
313
330
  Dragonfly::TempObject.new(data)
314
331
  end
315
-
332
+
316
333
  before(:each) do
317
334
  @temp_object1 = Dragonfly::TempObject.new(new_tempfile('hello'))
318
335
  @temp_object2 = Dragonfly::TempObject.new(@temp_object1)
319
336
  end
320
-
337
+
321
338
  it_should_behave_like "common behaviour"
322
-
339
+
323
340
  it "should not be the same object" do
324
341
  @temp_object1.should_not == @temp_object2
325
342
  end
@@ -338,9 +355,9 @@ describe Dragonfly::TempObject do
338
355
  #
339
356
  # We can't just check if it is_a?(Rack::Test::UploadedFile) because that
340
357
  # class may not always be present.
341
- uploaded_file = mock("mock_uploadedfile")
342
- uploaded_file.stub!(:path).and_return File.expand_path('tmp/test_file')
343
- uploaded_file.stub!(:original_filename).and_return('foo.jpg')
358
+ uploaded_file = double("mock_uploadedfile")
359
+ uploaded_file.stub(:path).and_return File.expand_path('tmp/test_file')
360
+ uploaded_file.stub(:original_filename).and_return('foo.jpg')
344
361
 
345
362
  # Create a real file with the contents required at the correct path
346
363
  new_file(data, 'tmp/test_file')
@@ -352,91 +369,49 @@ describe Dragonfly::TempObject do
352
369
  end
353
370
 
354
371
  describe "original_filename" do
372
+
355
373
  before(:each) do
356
374
  @obj = new_tempfile
357
375
  end
376
+
358
377
  it "should set the original_filename if the initial object responds to 'original filename'" do
359
378
  def @obj.original_filename
360
379
  'jimmy.page'
361
380
  end
362
381
  Dragonfly::TempObject.new(@obj).original_filename.should == 'jimmy.page'
363
382
  end
383
+
364
384
  it "should not set the name if the initial object doesn't respond to 'original filename'" do
365
385
  Dragonfly::TempObject.new(@obj).original_filename.should be_nil
366
386
  end
387
+
367
388
  it "should set the name if the initial object is a file object" do
368
389
  file = File.new(SAMPLES_DIR.join('round.gif'))
369
390
  temp_object = Dragonfly::TempObject.new(file)
370
391
  temp_object.original_filename.should == 'round.gif'
371
392
  end
393
+
372
394
  it "should set the name if the initial object is a pathname" do
373
395
  pathname = Pathname.new(SAMPLES_DIR + '/round.gif')
374
396
  temp_object = Dragonfly::TempObject.new(pathname)
375
397
  temp_object.original_filename.should == 'round.gif'
376
398
  end
377
- end
378
-
379
- describe "meta" do
380
- it "should default to an empty hash" do
381
- Dragonfly::TempObject.new('sdf').meta.should == {}
382
- end
383
- it "should allow setting on initialize" do
384
- Dragonfly::TempObject.new('sdf', :dub => 'wub').meta.should == {:dub => 'wub'}
385
- end
386
- it "should allow setting" do
387
- temp_object = Dragonfly::TempObject.new('boo')
388
- temp_object.meta = {:far => 'gone'}
389
- temp_object.meta.should == {:far => 'gone'}
390
- end
391
- end
392
399
 
393
- describe "name" do
394
- it "should default to nil" do
395
- Dragonfly::TempObject.new("HELLO").name.should be_nil
396
- end
397
- it "should allow setting the name via the meta" do
398
- Dragonfly::TempObject.new("HELLO", :name => 'gosh.pig').name.should == "gosh.pig"
399
- end
400
- it "should fallback to the original filename if not set" do
401
- content = "HELLO"
402
- content.should_receive(:original_filename).and_return("some.egg")
403
- temp_object = Dragonfly::TempObject.new(content)
404
- temp_object.name.should == "some.egg"
405
- end
406
- it "should prefer the specified name to the original filename" do
407
- content = "HELLO"
408
- content.stub!(:original_filename).and_return("brase.nose")
409
- temp_object = Dragonfly::TempObject.new("HELLO", :name => 'some.gug')
410
- temp_object.name.should == "some.gug"
411
- end
412
- it "should allow setting with a setter" do
413
- temp_object = Dragonfly::TempObject.new("HELLO")
414
- temp_object.name = 'bugs'
415
- temp_object.name.should == "bugs"
416
- end
417
- end
418
-
419
- describe "sanity check for using HasFilename" do
420
- it "should act like Dragonfly::HasFilename" do
421
- temp_object = Dragonfly::TempObject.new('h', :name => 'one.big.park')
422
- temp_object.ext = 'smeagol'
423
- temp_object.name.should == 'one.big.smeagol'
424
- end
425
400
  end
426
-
427
- describe "unique_id" do
428
- before(:each) do
429
- @temp_object = Dragonfly::TempObject.new('hello')
430
- end
431
- it "should return a unique id" do
432
- @temp_object.unique_id.should =~ /^\d+$/
433
- end
434
- it "should be unique" do
435
- @temp_object.unique_id.should_not == Dragonfly::TempObject.new('hello').unique_id
401
+
402
+ describe "ext" do
403
+
404
+ let(:temp_object) { Dragonfly::TempObject.new("stuff") }
405
+
406
+ it "defaults to nil" do
407
+ temp_object.ext.should be_nil
436
408
  end
437
- it "should not change" do
438
- @temp_object.unique_id.should == @temp_object.unique_id
409
+
410
+ it "uses original_filename if present" do
411
+ temp_object.should_receive(:original_filename).and_return('some.thing.yo')
412
+ temp_object.ext.should == 'yo'
439
413
  end
414
+
440
415
  end
441
416
 
442
417
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::UrlAttributes do
4
+
5
+ let(:url_attributes) { Dragonfly::UrlAttributes.new }
6
+
7
+ describe "empty" do
8
+ it "returns true when empty" do
9
+ url_attributes.empty?.should be_true
10
+ end
11
+
12
+ it "returns false when not empty" do
13
+ url_attributes.some = 'thing'
14
+ url_attributes.empty?.should be_false
15
+ end
16
+
17
+ it "returns true if all values are nil" do
18
+ url_attributes.some = nil
19
+ url_attributes.empty?.should be_true
20
+ end
21
+ end
22
+
23
+ describe "format" do
24
+ # because 'format' is already private on kernel, using 'send' calls it so we need a workaround
25
+ it "acts like other openstruct attributes when using 'send'" do
26
+ url_attributes.send(:format).should be_nil
27
+ url_attributes.format = "clive"
28
+ url_attributes.send(:format).should == "clive"
29
+ url_attributes.should_not be_empty
30
+ end
31
+ end
32
+
33
+ describe "extract" do
34
+ it "returns a hash for the given keys" do
35
+ url_attributes.egg = 'boiled'
36
+ url_attributes.veg = 'beef'
37
+ url_attributes.lard = 'lean'
38
+ url_attributes.extract(['egg', 'veg']).should == {'egg' => 'boiled', 'veg' => 'beef'}
39
+ end
40
+
41
+ it "excludes blank values" do
42
+ url_attributes.egg = ''
43
+ url_attributes.veg = nil
44
+ url_attributes.extract(['egg', 'veg']).should == {}
45
+ end
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::Utils do
4
+
5
+ describe "blank?" do
6
+ [
7
+ nil,
8
+ false,
9
+ "",
10
+ [],
11
+ {}
12
+ ].each do |obj|
13
+ it "returns true for #{obj.inspect}" do
14
+ obj.blank?.should be_true
15
+ end
16
+ end
17
+
18
+ [
19
+ "a",
20
+ [1],
21
+ {1 => 2},
22
+ Object.new,
23
+ true,
24
+ 7.3
25
+ ].each do |obj|
26
+ it "returns false for #{obj.inspect}" do
27
+ obj.blank?.should be_false
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::Whitelist do
4
+ it "matches regexps" do
5
+ whitelist = Dragonfly::Whitelist.new([/platipus/])
6
+ whitelist.include?("platipus").should be_true
7
+ whitelist.include?("small platipus in the bath").should be_true
8
+ whitelist.include?("baloney").should be_false
9
+ end
10
+
11
+ it "matches strings" do
12
+ whitelist = Dragonfly::Whitelist.new(["platipus"])
13
+ whitelist.include?("platipus").should be_true
14
+ whitelist.include?("small platipus in the bath").should be_false
15
+ whitelist.include?("baloney").should be_false
16
+ end
17
+
18
+ it "only needs one match" do
19
+ Dragonfly::Whitelist.new(%w(a b)).include?("c").should be_false
20
+ Dragonfly::Whitelist.new(%w(a b c)).include?("c").should be_true
21
+ end
22
+
23
+ it "allows pushing" do
24
+ whitelist = Dragonfly::Whitelist.new(["platipus"])
25
+ whitelist.push("duck")
26
+ whitelist.should include "platipus"
27
+ whitelist.should include "duck"
28
+ end
29
+ end
30
+