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,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Analysers::ImageProperties do
4
+
5
+ let(:app) { test_imagemagick_app }
6
+ let(:analyser) { Dragonfly::ImageMagick::Analysers::ImageProperties.new }
7
+ let(:content) { Dragonfly::Content.new(app, SAMPLES_DIR.join('beach.png')) } # 280x355
8
+
9
+ describe "call" do
10
+ it "returns a hash of properties" do
11
+ analyser.call(content).should == {
12
+ 'width' => 280,
13
+ 'height' => 355,
14
+ 'format' => 'png'
15
+ }
16
+ end
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Generators::Convert do
4
+ let (:generator) { Dragonfly::ImageMagick::Generators::Convert.new }
5
+ let (:app) { test_app }
6
+ let (:image) { Dragonfly::Content.new(app) }
7
+
8
+ describe "calling convert" do
9
+ before(:each) do
10
+ generator.call(image, "-size 1x1 xc:white", 'png')
11
+ end
12
+ it {image.should have_width(1)}
13
+ it {image.should have_height(1)}
14
+ it {image.should have_format('png')}
15
+ it {image.meta.should == {'format' => 'png'}}
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Generators::Plain do
4
+ let (:generator) { Dragonfly::ImageMagick::Generators::Plain.new }
5
+ let (:app) { test_imagemagick_app }
6
+ let (:image) { Dragonfly::Content.new(app) }
7
+
8
+ describe "of given dimensions" do
9
+ before(:each) do
10
+ generator.call(image, 3, 2)
11
+ end
12
+ it {image.should have_width(3)}
13
+ it {image.should have_height(2)}
14
+ it {image.should have_format('png')}
15
+ it {image.meta.should == {'format' => 'png', 'name' => 'plain.png'}}
16
+ end
17
+
18
+ describe "specifying the format" do
19
+ before(:each) do
20
+ generator.call(image, 1, 1, 'format'=> 'gif')
21
+ end
22
+ it {image.should have_format('gif')}
23
+ it {image.meta.should == {'format' => 'gif', 'name' => 'plain.gif'}}
24
+ end
25
+
26
+ describe "specifying the colour" do
27
+ it "works with English spelling" do
28
+ generator.call(image, 1, 1, 'colour' => 'red')
29
+ end
30
+
31
+ it "works with American spelling" do
32
+ generator.call(image, 1, 1, 'color' => 'red')
33
+ end
34
+
35
+ it "blows up with a bad colour" do
36
+ expect {
37
+ generator.call(image, 1, 1, 'colour' => 'lardoin')
38
+ }.to raise_error(Dragonfly::Shell::CommandFailed)
39
+ end
40
+ end
41
+
42
+ describe "urls" do
43
+ it "updates the url" do
44
+ url_attributes = Dragonfly::UrlAttributes.new
45
+ generator.update_url(url_attributes, 1, 1, 'format' => 'gif')
46
+ url_attributes.name.should == 'plain.gif'
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Generators::Plasma do
4
+ let (:generator) { Dragonfly::ImageMagick::Generators::Plasma.new }
5
+ let (:app) { test_imagemagick_app }
6
+ let (:image) { Dragonfly::Content.new(app) }
7
+
8
+ describe "call" do
9
+ it "generates a png image" do
10
+ generator.call(image, 5, 3)
11
+ image.should have_width(5)
12
+ image.should have_height(3)
13
+ image.should have_format('png')
14
+ image.meta.should == {'format' => 'png', 'name' => 'plasma.png'}
15
+ end
16
+
17
+ it "allows changing the format" do
18
+ generator.call(image, 1, 1, 'format' => 'jpg')
19
+ image.should have_format('jpeg')
20
+ image.meta.should == {'format' => 'jpg', 'name' => 'plasma.jpg'}
21
+ end
22
+ end
23
+
24
+ describe "urls" do
25
+ it "updates the url" do
26
+ url_attributes = Dragonfly::UrlAttributes.new
27
+ generator.update_url(url_attributes, 1, 1, 'format' => 'jpg')
28
+ url_attributes.name.should == 'plasma.jpg'
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Generators::Text do
4
+ let (:generator) { Dragonfly::ImageMagick::Generators::Text.new }
5
+ let (:app) { test_imagemagick_app }
6
+ let (:image) { Dragonfly::Content.new(app) }
7
+
8
+ describe "creating a text image" do
9
+ before(:each) do
10
+ generator.call(image, "mmm", 'font_size' => 12)
11
+ end
12
+ it {image.should have_width(20..40)} # approximate
13
+ it {image.should have_height(10..20)}
14
+ it {image.should have_format('png')}
15
+ it {image.meta.should == {'format' => 'png', 'name' => 'text.png'}}
16
+ end
17
+
18
+ describe "specifying the format" do
19
+ before(:each) do
20
+ generator.call(image, "mmm", 'format' => 'gif')
21
+ end
22
+ it {image.should have_format('gif')}
23
+ it {image.meta.should == {'format' => 'gif', 'name' => 'text.gif'}}
24
+ end
25
+
26
+ describe "padding" do
27
+ before(:each) do
28
+ image_without_padding = image.clone
29
+ generator.call(image_without_padding, "mmm", 'font_size' => 12)
30
+ @width = image_properties(image_without_padding)[:width].to_i
31
+ @height = image_properties(image_without_padding)[:height].to_i
32
+ end
33
+ it "1 number shortcut" do
34
+ generator.call(image, "mmm", 'padding' => '10')
35
+ image.should have_width(@width + 20)
36
+ image.should have_height(@height + 20)
37
+ end
38
+ it "2 numbers shortcut" do
39
+ generator.call(image, "mmm", 'padding' => '10 5')
40
+ image.should have_width(@width + 10)
41
+ image.should have_height(@height + 20)
42
+ end
43
+ it "3 numbers shortcut" do
44
+ generator.call(image, "mmm", 'padding' => '10 5 8')
45
+ image.should have_width(@width + 10)
46
+ image.should have_height(@height + 18)
47
+ end
48
+ it "4 numbers shortcut" do
49
+ generator.call(image, "mmm", 'padding' => '1 2 3 4')
50
+ image.should have_width(@width + 6)
51
+ image.should have_height(@height + 4)
52
+ end
53
+ it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
54
+ generator.call(image, "mmm", 'padding' => '10', 'padding-left' => 9)
55
+ image.should have_width(@width + 19)
56
+ image.should have_height(@height + 20)
57
+ end
58
+ it "should ignore 'px' suffixes" do
59
+ generator.call(image, "mmm", 'padding' => '1px 2px 3px 4px')
60
+ image.should have_width(@width + 6)
61
+ image.should have_height(@height + 4)
62
+ end
63
+ it "bad padding string" do
64
+ lambda{
65
+ generator.call(image, "mmm", 'padding' => '1 2 3 4 5')
66
+ }.should raise_error(ArgumentError)
67
+ end
68
+ end
69
+
70
+ describe "urls" do
71
+ it "updates the url" do
72
+ url_attributes = Dragonfly::UrlAttributes.new
73
+ generator.update_url(url_attributes, "mmm", 'format' => 'gif')
74
+ url_attributes.name.should == 'text.gif'
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe "a configured imagemagick app" do
4
+
5
+ let(:app){ test_app.configure_with(:imagemagick) }
6
+ let(:image){ app.fetch_file(SAMPLES_DIR.join('beach.png')) }
7
+
8
+ describe "env variables" do
9
+ let(:app){ test_app }
10
+
11
+ it "allows setting the convert command" do
12
+ app.configure do
13
+ plugin :imagemagick, :convert_command => '/bin/convert'
14
+ end
15
+ app.env[:convert_command].should == '/bin/convert'
16
+ end
17
+
18
+ it "allows setting the identify command" do
19
+ app.configure do
20
+ plugin :imagemagick, :identify_command => '/bin/identify'
21
+ end
22
+ app.env[:identify_command].should == '/bin/identify'
23
+ end
24
+ end
25
+
26
+ describe "analysers" do
27
+ it "should return the width" do
28
+ image.width.should == 280
29
+ end
30
+
31
+ it "should return the height" do
32
+ image.height.should == 355
33
+ end
34
+
35
+ it "should return the aspect ratio" do
36
+ image.aspect_ratio.should == (280.0/355.0)
37
+ end
38
+
39
+ it "should say if it's portrait" do
40
+ image.portrait?.should be_true
41
+ image.portrait.should be_true # for using with magic attributes
42
+ end
43
+
44
+ it "should say if it's landscape" do
45
+ image.landscape?.should be_false
46
+ image.landscape.should be_false # for using with magic attributes
47
+ end
48
+
49
+ it "should return the format" do
50
+ image.format.should == "png"
51
+ end
52
+
53
+ it "should say if it's an image" do
54
+ image.image?.should be_true
55
+ image.image.should be_true # for using with magic attributes
56
+ end
57
+
58
+ it "should say if it's not an image" do
59
+ app.create("blah").image?.should be_false
60
+ end
61
+
62
+ it "should return false for pdfs" do
63
+ image.encode('pdf').image?.should be_false
64
+ end
65
+ end
66
+
67
+ describe "processors that change the url" do
68
+ before do
69
+ app.configure{ url_format '/:name' }
70
+ end
71
+
72
+ describe "convert" do
73
+ it "sanity check with format" do
74
+ thumb = image.convert('-resize 1x1!', 'format' => 'jpg')
75
+ thumb.url.should =~ /^\/beach\.jpg\?job=\w+/
76
+ thumb.width.should == 1
77
+ thumb.format.should == 'jpeg'
78
+ thumb.meta['format'].should == 'jpg'
79
+ end
80
+
81
+ it "sanity check without format" do
82
+ thumb = image.convert('-resize 1x1!')
83
+ thumb.url.should =~ /^\/beach\.png\?job=\w+/
84
+ thumb.width.should == 1
85
+ thumb.format.should == 'png'
86
+ thumb.meta['format'].should be_nil
87
+ end
88
+ end
89
+
90
+ describe "encode" do
91
+ it "sanity check" do
92
+ thumb = image.encode('jpg')
93
+ thumb.url.should =~ /^\/beach\.jpg\?job=\w+/
94
+ thumb.format.should == 'jpeg'
95
+ thumb.meta['format'].should == 'jpg'
96
+ end
97
+ end
98
+ end
99
+
100
+ describe "other processors" do
101
+ describe "encode" do
102
+ it "should encode the image to the correct format" do
103
+ image.encode!('gif')
104
+ image.format.should == 'gif'
105
+ end
106
+
107
+ it "should allow for extra args" do
108
+ image.encode!('jpg', '-quality 1')
109
+ image.format.should == 'jpeg'
110
+ image.size.should < 2000
111
+ end
112
+ end
113
+
114
+ describe "rotate" do
115
+ it "should rotate by 90 degrees" do
116
+ image.rotate!(90)
117
+ image.width.should == 355
118
+ image.height.should == 280
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ describe "identify" do
125
+ it "gives the output of the command line" do
126
+ image.identify.should =~ /280/
127
+ image.identify("-format %h").should == "355\n"
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Processors::Convert do
4
+
5
+ def sample_content(name)
6
+ Dragonfly::Content.new(app, SAMPLES_DIR.join(name))
7
+ end
8
+
9
+ let(:app){ test_app }
10
+ let(:image){ sample_content('beach.png') } # 280x355
11
+ let(:processor){ Dragonfly::ImageMagick::Processors::Convert.new }
12
+
13
+ it "should allow for general convert commands" do
14
+ processor.call(image, '-scale 56x71')
15
+ image.should have_width(56)
16
+ image.should have_height(71)
17
+ end
18
+
19
+ it "should allow for general convert commands with added format" do
20
+ processor.call(image, '-scale 56x71', 'format' => 'gif')
21
+ image.should have_width(56)
22
+ image.should have_height(71)
23
+ image.should have_format('gif')
24
+ image.meta['format'].should == 'gif'
25
+ end
26
+
27
+ it "should work for commands with parenthesis" do
28
+ processor.call(image, "\\( +clone -sparse-color Barycentric '0,0 black 0,%[fx:h-1] white' -function polynomial 2,-2,0.5 \\) -compose Blur -set option:compose:args 15 -composite")
29
+ image.should have_width(280)
30
+ end
31
+
32
+ it "should work for files with spaces in the name" do
33
+ image = Dragonfly::Content.new(app, SAMPLES_DIR.join('white pixel.png'))
34
+ processor.call(image, "-resize 2x2!")
35
+ image.should have_width(2)
36
+ end
37
+
38
+ it "updates the url with format if given" do
39
+ url_attributes = Dragonfly::UrlAttributes.new
40
+ processor.update_url(url_attributes, '-scale 56x71', 'format' => 'gif')
41
+ url_attributes.ext.should == 'gif'
42
+ end
43
+
44
+ it "allows converting specific frames" do
45
+ gif = sample_content('gif.gif')
46
+ processor.call(gif, '-resize 50x50')
47
+ all_frames_size = gif.size
48
+
49
+ gif = sample_content('gif.gif')
50
+ processor.call(gif, '-resize 50x50', 'frame' => 0)
51
+ one_frame_size = gif.size
52
+
53
+ one_frame_size.should < all_frames_size
54
+ end
55
+
56
+ end
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe Dragonfly::ImageMagick::Processors::Thumb do
5
+
6
+ let (:app) { test_imagemagick_app }
7
+ let (:image) { Dragonfly::Content.new(app, SAMPLES_DIR.join('beach.png')) } # 280x355
8
+ let (:processor) { Dragonfly::ImageMagick::Processors::Thumb.new }
9
+
10
+ it "raises an error if an unrecognized string is given" do
11
+ expect{
12
+ processor.call(image, '30x40#ne!')
13
+ }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ describe "resizing" do
17
+
18
+ it "works with xNN" do
19
+ processor.call(image, 'x30')
20
+ image.should have_width(24)
21
+ image.should have_height(30)
22
+ end
23
+
24
+ it "works with NNx" do
25
+ processor.call(image, '30x')
26
+ image.should have_width(30)
27
+ image.should have_height(38)
28
+ end
29
+
30
+ it "works with NNxNN" do
31
+ processor.call(image, '30x30')
32
+ image.should have_width(24)
33
+ image.should have_height(30)
34
+ end
35
+
36
+ it "works with NNxNN!" do
37
+ processor.call(image, '30x30!')
38
+ image.should have_width(30)
39
+ image.should have_height(30)
40
+ end
41
+
42
+ it "works with NNxNN%" do
43
+ processor.call(image, '25x50%')
44
+ image.should have_width(70)
45
+ image.should have_height(178)
46
+ end
47
+
48
+ describe "NNxNN>" do
49
+
50
+ it "doesn't resize if the image is smaller than specified" do
51
+ processor.call(image, '1000x1000>')
52
+ image.should have_width(280)
53
+ image.should have_height(355)
54
+ end
55
+
56
+ it "resizes if the image is larger than specified" do
57
+ processor.call(image, '30x30>')
58
+ image.should have_width(24)
59
+ image.should have_height(30)
60
+ end
61
+
62
+ end
63
+
64
+ describe "NNxNN<" do
65
+
66
+ it "doesn't resize if the image is larger than specified" do
67
+ processor.call(image, '10x10<')
68
+ image.should have_width(280)
69
+ image.should have_height(355)
70
+ end
71
+
72
+ it "resizes if the image is smaller than specified" do
73
+ processor.call(image, '400x400<')
74
+ image.should have_width(315)
75
+ image.should have_height(400)
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ describe "cropping" do # Difficult to test here other than dimensions
83
+
84
+ it "crops" do
85
+ processor.call(image, '10x20+30+30')
86
+ image.should have_width(10)
87
+ image.should have_height(20)
88
+ end
89
+
90
+ it "crops with gravity" do
91
+ image2 = image.clone
92
+
93
+ processor.call(image, '10x8nw')
94
+ image.should have_width(10)
95
+ image.should have_height(8)
96
+
97
+ processor.call(image2, '10x8se')
98
+ image2.should have_width(10)
99
+ image2.should have_height(8)
100
+
101
+ image2.should_not equal_image(image)
102
+ end
103
+
104
+ it "raises if given both gravity and offset" do
105
+ expect {
106
+ processor.call(image, '100x100+10+10se')
107
+ }.to raise_error(ArgumentError)
108
+ end
109
+
110
+ it "works when the crop area is outside the image" do
111
+ processor.call(image, '100x100+250+300')
112
+ image.should have_width(30)
113
+ image.should have_height(55)
114
+ end
115
+
116
+ it "crops twice in a row correctly" do
117
+ processor.call(image, '100x100+10+10')
118
+ processor.call(image, '50x50+0+0')
119
+ image.should have_width(50)
120
+ image.should have_height(50)
121
+ end
122
+
123
+ end
124
+
125
+ describe "resize_and_crop" do
126
+
127
+ it "crops to the correct dimensions" do
128
+ processor.call(image, '100x100#')
129
+ image.should have_width(100)
130
+ image.should have_height(100)
131
+ end
132
+
133
+ it "resizes before cropping" do
134
+ image2 = image.clone
135
+ processor.call(image, '100x100#')
136
+ processor.call(image2, '100x100c')
137
+ image2.should_not equal_image(image)
138
+ end
139
+
140
+ it "works with gravity" do
141
+ image2 = image.clone
142
+ processor.call(image, '10x10#nw')
143
+ processor.call(image, '10x10#se')
144
+ image2.should_not equal_image(image)
145
+ end
146
+
147
+ end
148
+
149
+ describe "format" do
150
+ let (:url_attributes) { OpenStruct.new }
151
+
152
+ it "changes the format if passed in" do
153
+ processor.call(image, '2x2', 'format' => 'jpeg')
154
+ image.should have_format('jpeg')
155
+ end
156
+
157
+ it "doesn't change the format if not passed in" do
158
+ processor.call(image, '2x2')
159
+ image.should have_format('png')
160
+ end
161
+
162
+ it "updates the url ext if passed in" do
163
+ processor.update_url(url_attributes, '2x2', 'format' => 'png')
164
+ url_attributes.ext.should == 'png'
165
+ end
166
+
167
+ it "doesn't update the url ext if not passed in" do
168
+ processor.update_url(url_attributes, '2x2')
169
+ url_attributes.ext.should be_nil
170
+ end
171
+ end
172
+
173
+ end