oahu-dragonfly 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/.rspec +1 -0
  2. data/.yardopts +24 -0
  3. data/Gemfile +30 -0
  4. data/History.md +323 -0
  5. data/LICENSE +20 -0
  6. data/README.md +88 -0
  7. data/Rakefile +50 -0
  8. data/VERSION +1 -0
  9. data/config.ru +14 -0
  10. data/docs.watchr +1 -0
  11. data/dragonfly.gemspec +297 -0
  12. data/extra_docs/Analysers.md +66 -0
  13. data/extra_docs/Caching.md +23 -0
  14. data/extra_docs/Configuration.md +124 -0
  15. data/extra_docs/Couch.md +49 -0
  16. data/extra_docs/DataStorage.md +153 -0
  17. data/extra_docs/Encoding.md +67 -0
  18. data/extra_docs/GeneralUsage.md +121 -0
  19. data/extra_docs/Generators.md +60 -0
  20. data/extra_docs/Heroku.md +50 -0
  21. data/extra_docs/ImageMagick.md +125 -0
  22. data/extra_docs/Index.md +33 -0
  23. data/extra_docs/MimeTypes.md +40 -0
  24. data/extra_docs/Models.md +272 -0
  25. data/extra_docs/Mongo.md +45 -0
  26. data/extra_docs/Processing.md +77 -0
  27. data/extra_docs/Rack.md +52 -0
  28. data/extra_docs/Rails2.md +57 -0
  29. data/extra_docs/Rails3.md +62 -0
  30. data/extra_docs/Sinatra.md +25 -0
  31. data/extra_docs/URLs.md +169 -0
  32. data/features/images.feature +47 -0
  33. data/features/no_processing.feature +14 -0
  34. data/features/rails_3.0.5.feature +8 -0
  35. data/features/steps/common_steps.rb +8 -0
  36. data/features/steps/dragonfly_steps.rb +66 -0
  37. data/features/steps/rails_steps.rb +28 -0
  38. data/features/support/env.rb +13 -0
  39. data/features/support/setup.rb +32 -0
  40. data/fixtures/rails_3.0.5/files/app/models/album.rb +7 -0
  41. data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
  42. data/fixtures/rails_3.0.5/files/app/views/albums/show.html.erb +6 -0
  43. data/fixtures/rails_3.0.5/files/config/initializers/dragonfly.rb +4 -0
  44. data/fixtures/rails_3.0.5/files/features/manage_album_images.feature +38 -0
  45. data/fixtures/rails_3.0.5/files/features/step_definitions/helper_steps.rb +7 -0
  46. data/fixtures/rails_3.0.5/files/features/step_definitions/image_steps.rb +25 -0
  47. data/fixtures/rails_3.0.5/files/features/support/paths.rb +17 -0
  48. data/fixtures/rails_3.0.5/files/features/text_images.feature +7 -0
  49. data/fixtures/rails_3.0.5/template.rb +20 -0
  50. data/irbrc.rb +18 -0
  51. data/lib/dragonfly.rb +55 -0
  52. data/lib/dragonfly/active_model_extensions.rb +13 -0
  53. data/lib/dragonfly/active_model_extensions/attachment.rb +250 -0
  54. data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +148 -0
  55. data/lib/dragonfly/active_model_extensions/class_methods.rb +95 -0
  56. data/lib/dragonfly/active_model_extensions/instance_methods.rb +28 -0
  57. data/lib/dragonfly/active_model_extensions/validations.rb +41 -0
  58. data/lib/dragonfly/analyser.rb +58 -0
  59. data/lib/dragonfly/analysis/file_command_analyser.rb +32 -0
  60. data/lib/dragonfly/analysis/image_magick_analyser.rb +6 -0
  61. data/lib/dragonfly/app.rb +172 -0
  62. data/lib/dragonfly/config/heroku.rb +19 -0
  63. data/lib/dragonfly/config/image_magick.rb +6 -0
  64. data/lib/dragonfly/config/rails.rb +20 -0
  65. data/lib/dragonfly/configurable.rb +207 -0
  66. data/lib/dragonfly/core_ext/array.rb +7 -0
  67. data/lib/dragonfly/core_ext/hash.rb +7 -0
  68. data/lib/dragonfly/core_ext/object.rb +12 -0
  69. data/lib/dragonfly/core_ext/string.rb +9 -0
  70. data/lib/dragonfly/core_ext/symbol.rb +9 -0
  71. data/lib/dragonfly/data_storage.rb +9 -0
  72. data/lib/dragonfly/data_storage/couch_data_store.rb +64 -0
  73. data/lib/dragonfly/data_storage/file_data_store.rb +141 -0
  74. data/lib/dragonfly/data_storage/mongo_data_store.rb +86 -0
  75. data/lib/dragonfly/data_storage/s3data_store.rb +145 -0
  76. data/lib/dragonfly/encoder.rb +13 -0
  77. data/lib/dragonfly/encoding/image_magick_encoder.rb +6 -0
  78. data/lib/dragonfly/function_manager.rb +71 -0
  79. data/lib/dragonfly/generation/image_magick_generator.rb +6 -0
  80. data/lib/dragonfly/generator.rb +9 -0
  81. data/lib/dragonfly/hash_with_css_style_keys.rb +21 -0
  82. data/lib/dragonfly/image_magick/analyser.rb +51 -0
  83. data/lib/dragonfly/image_magick/config.rb +41 -0
  84. data/lib/dragonfly/image_magick/encoder.rb +57 -0
  85. data/lib/dragonfly/image_magick/generator.rb +145 -0
  86. data/lib/dragonfly/image_magick/processor.rb +99 -0
  87. data/lib/dragonfly/image_magick/utils.rb +72 -0
  88. data/lib/dragonfly/image_magick_utils.rb +4 -0
  89. data/lib/dragonfly/job.rb +451 -0
  90. data/lib/dragonfly/job_builder.rb +39 -0
  91. data/lib/dragonfly/job_definitions.rb +26 -0
  92. data/lib/dragonfly/job_endpoint.rb +15 -0
  93. data/lib/dragonfly/loggable.rb +28 -0
  94. data/lib/dragonfly/middleware.rb +20 -0
  95. data/lib/dragonfly/processing/image_magick_processor.rb +6 -0
  96. data/lib/dragonfly/processor.rb +9 -0
  97. data/lib/dragonfly/rails/images.rb +27 -0
  98. data/lib/dragonfly/response.rb +97 -0
  99. data/lib/dragonfly/routed_endpoint.rb +40 -0
  100. data/lib/dragonfly/serializer.rb +32 -0
  101. data/lib/dragonfly/server.rb +113 -0
  102. data/lib/dragonfly/simple_cache.rb +23 -0
  103. data/lib/dragonfly/temp_object.rb +175 -0
  104. data/lib/dragonfly/url_mapper.rb +78 -0
  105. data/samples/beach.png +0 -0
  106. data/samples/egg.png +0 -0
  107. data/samples/round.gif +0 -0
  108. data/samples/sample.docx +0 -0
  109. data/samples/taj.jpg +0 -0
  110. data/spec/dragonfly/active_model_extensions/model_spec.rb +1426 -0
  111. data/spec/dragonfly/active_model_extensions/spec_helper.rb +91 -0
  112. data/spec/dragonfly/analyser_spec.rb +123 -0
  113. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +48 -0
  114. data/spec/dragonfly/app_spec.rb +135 -0
  115. data/spec/dragonfly/configurable_spec.rb +461 -0
  116. data/spec/dragonfly/core_ext/array_spec.rb +19 -0
  117. data/spec/dragonfly/core_ext/hash_spec.rb +19 -0
  118. data/spec/dragonfly/core_ext/string_spec.rb +17 -0
  119. data/spec/dragonfly/core_ext/symbol_spec.rb +17 -0
  120. data/spec/dragonfly/data_storage/couch_data_store_spec.rb +76 -0
  121. data/spec/dragonfly/data_storage/file_data_store_spec.rb +296 -0
  122. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +57 -0
  123. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +258 -0
  124. data/spec/dragonfly/data_storage/shared_data_store_examples.rb +77 -0
  125. data/spec/dragonfly/function_manager_spec.rb +154 -0
  126. data/spec/dragonfly/hash_with_css_style_keys_spec.rb +24 -0
  127. data/spec/dragonfly/image_magick/analyser_spec.rb +64 -0
  128. data/spec/dragonfly/image_magick/encoder_spec.rb +41 -0
  129. data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
  130. data/spec/dragonfly/image_magick/processor_spec.rb +233 -0
  131. data/spec/dragonfly/image_magick/utils_spec.rb +18 -0
  132. data/spec/dragonfly/job_builder_spec.rb +37 -0
  133. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  134. data/spec/dragonfly/job_endpoint_spec.rb +173 -0
  135. data/spec/dragonfly/job_spec.rb +1046 -0
  136. data/spec/dragonfly/loggable_spec.rb +80 -0
  137. data/spec/dragonfly/middleware_spec.rb +47 -0
  138. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  139. data/spec/dragonfly/serializer_spec.rb +61 -0
  140. data/spec/dragonfly/server_spec.rb +278 -0
  141. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  142. data/spec/dragonfly/temp_object_spec.rb +306 -0
  143. data/spec/dragonfly/url_mapper_spec.rb +126 -0
  144. data/spec/functional/deprecations_spec.rb +51 -0
  145. data/spec/functional/image_magick_app_spec.rb +27 -0
  146. data/spec/functional/model_urls_spec.rb +85 -0
  147. data/spec/functional/remote_on_the_fly_spec.rb +51 -0
  148. data/spec/functional/to_response_spec.rb +31 -0
  149. data/spec/spec_helper.rb +51 -0
  150. data/spec/support/argument_matchers.rb +19 -0
  151. data/spec/support/image_matchers.rb +47 -0
  152. data/spec/support/simple_matchers.rb +53 -0
  153. data/yard/handlers/configurable_attr_handler.rb +38 -0
  154. data/yard/setup.rb +15 -0
  155. data/yard/templates/default/fulldoc/html/css/common.css +107 -0
  156. data/yard/templates/default/layout/html/layout.erb +89 -0
  157. data/yard/templates/default/module/html/configuration_summary.erb +31 -0
  158. data/yard/templates/default/module/setup.rb +17 -0
  159. metadata +544 -0
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::HashWithCssStyleKeys do
4
+
5
+ before(:each) do
6
+ @hash = Dragonfly::HashWithCssStyleKeys[
7
+ :font_style => 'normal',
8
+ :'font-weight' => 'bold',
9
+ 'font_colour' => 'white',
10
+ 'font-size' => 23,
11
+ :hello => 'there'
12
+ ]
13
+ end
14
+
15
+ describe "accessing using underscore symbol style" do
16
+ it{ @hash[:font_style].should == 'normal' }
17
+ it{ @hash[:font_weight].should == 'bold' }
18
+ it{ @hash[:font_colour].should == 'white' }
19
+ it{ @hash[:font_size].should == 23 }
20
+ it{ @hash[:hello].should == 'there' }
21
+ it{ @hash[:non_existent_key].should be_nil }
22
+ end
23
+
24
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Analyser do
4
+
5
+ before(:each) do
6
+ image_path = File.dirname(__FILE__) + '/../../../samples/beach.png'
7
+ @image = Dragonfly::TempObject.new(File.new(image_path))
8
+ @analyser = Dragonfly::ImageMagick::Analyser.new
9
+ end
10
+
11
+ it "should return the width" do
12
+ @analyser.width(@image).should == 280
13
+ end
14
+
15
+ it "should return the height" do
16
+ @analyser.height(@image).should == 355
17
+ end
18
+
19
+ it "should return the aspect ratio" do
20
+ @analyser.aspect_ratio(@image).should == (280.0/355.0)
21
+ end
22
+
23
+ it "should say if it's portrait" do
24
+ @analyser.portrait?(@image).should be_true
25
+ end
26
+
27
+ it "should say if it's landscape" do
28
+ @analyser.landscape?(@image).should be_false
29
+ end
30
+
31
+ it "should return the number of colours" do
32
+ @analyser.number_of_colours(@image).should == 34703
33
+ end
34
+
35
+ it "should return the depth" do
36
+ @analyser.depth(@image).should == 8
37
+ end
38
+
39
+ it "should return the format" do
40
+ @analyser.format(@image).should == :png
41
+ end
42
+
43
+ %w(width height aspect_ratio number_of_colours depth format portrait? landscape?).each do |meth|
44
+ it "should throw unable_to_handle in #{meth.inspect} if it's not an image file" do
45
+ suppressing_stderr do
46
+ temp_object = Dragonfly::TempObject.new('blah')
47
+ lambda{
48
+ @analyser.send(meth, temp_object)
49
+ }.should throw_symbol(:unable_to_handle)
50
+ end
51
+ end
52
+ end
53
+
54
+ it "should say if it's an image" do
55
+ @analyser.image?(@image).should == true
56
+ end
57
+
58
+ it "should say if it's not an image" do
59
+ suppressing_stderr do
60
+ @analyser.image?(Dragonfly::TempObject.new('blah')).should == false
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Encoder do
4
+
5
+ before(:all) do
6
+ sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355, 135KB
7
+ @image = Dragonfly::TempObject.new(File.new(sample_file))
8
+ @encoder = Dragonfly::ImageMagick::Encoder.new
9
+ end
10
+
11
+ describe "#encode" do
12
+
13
+ it "should encode the image to the correct format" do
14
+ image = @encoder.encode(@image, :gif)
15
+ image.should have_format('gif')
16
+ end
17
+
18
+ it "should throw :unable_to_handle if the format is not handleable" do
19
+ lambda{
20
+ @encoder.encode(@image, :goofy)
21
+ }.should throw_symbol(:unable_to_handle)
22
+ end
23
+
24
+ it "should do nothing if the image is already in the correct format" do
25
+ image = @encoder.encode(@image, :png)
26
+ image.should == @image
27
+ end
28
+
29
+ it "should allow for extra args" do
30
+ image = @encoder.encode(@image, :jpg, '-quality 1')
31
+ image.should have_format('jpeg')
32
+ image.should have_size('1.45KB')
33
+ end
34
+
35
+ it "should still work even if the image is already in the correct format and args are given" do
36
+ image = @encoder.encode(@image, :png, '-quality 1')
37
+ image.should_not == @image
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Generator do
4
+
5
+ before(:each) do
6
+ @generator = Dragonfly::ImageMagick::Generator.new
7
+ end
8
+
9
+ describe "plain" do
10
+ describe "of given dimensions and colour" do
11
+ before(:each) do
12
+ @image, @meta = @generator.plain(23,12,'white')
13
+ end
14
+ it {@image.should have_width(23)}
15
+ it {@image.should have_height(12)}
16
+ it {@image.should have_format('png')}
17
+ it {@meta.should == {:format => :png, :name => 'plain.png'}}
18
+ end
19
+
20
+ it "should cope with colour name format" do
21
+ image, meta = @generator.plain(1, 1, 'red')
22
+ image.should have_width(1)
23
+ end
24
+
25
+ it "should cope with rgb format" do
26
+ image, meta = @generator.plain(1, 1, 'rgb(244,255,1)')
27
+ image.should have_width(1)
28
+ end
29
+
30
+ it "should cope with rgb format with whitespace" do
31
+ image, meta = @generator.plain(1, 1, ' rgb ( 244 , 255 , 1 ) ')
32
+ image.should have_width(1)
33
+ end
34
+
35
+ it "should cope with rgb percent format" do
36
+ image, meta = @generator.plain(1, 1, 'rgb(100%,50%,20%)')
37
+ image.should have_width(1)
38
+ end
39
+
40
+ it "should cope with hex format" do
41
+ image, meta = @generator.plain(1, 1, '#fdafda')
42
+ image.should have_width(1)
43
+ end
44
+
45
+ it "should cope with uppercase hex format" do
46
+ image, meta = @generator.plain(1, 1, '#FDAFDA')
47
+ image.should have_width(1)
48
+ end
49
+
50
+ it "should cope with shortened hex format" do
51
+ image, meta = @generator.plain(1, 1, '#fda')
52
+ image.should have_width(1)
53
+ end
54
+
55
+ it "should cope with 'transparent'" do
56
+ image, meta = @generator.plain(1, 1, 'transparent')
57
+ image.should have_width(1)
58
+ end
59
+
60
+ it "should cope with rgba format" do
61
+ image, meta = @generator.plain(1, 1, 'rgba(25,100,255,0.5)')
62
+ image.should have_width(1)
63
+ end
64
+
65
+ it "should cope with hsl format" do
66
+ image, meta = @generator.plain(1, 1, 'hsl(25,100,255)')
67
+ image.should have_width(1)
68
+ end
69
+
70
+ it "should blow up with an invalid colour" do
71
+ lambda{
72
+ @generator.plain(1,1,'rgb(doogie)')
73
+ }.should_not raise_error()
74
+ end
75
+
76
+ describe "specifying the format" do
77
+ before(:each) do
78
+ @image, @meta = @generator.plain(23, 12, 'white', :format => :gif)
79
+ end
80
+ it {@image.should have_format('gif')}
81
+ it {@meta.should == {:format => :gif, :name => 'plain.gif'}}
82
+ end
83
+ end
84
+
85
+ describe "plasma" do
86
+ describe "of given dimensions" do
87
+ before(:each) do
88
+ @image, @meta = @generator.plasma(23,12)
89
+ end
90
+ it {@image.should have_width(23)}
91
+ it {@image.should have_height(12)}
92
+ it {@image.should have_format('png')}
93
+ it {@meta.should == {:format => :png, :name => 'plasma.png'}}
94
+ end
95
+
96
+ describe "specifying the format" do
97
+ before(:each) do
98
+ @image, @meta = @generator.plasma(23, 12, :gif)
99
+ end
100
+ it {@image.should have_format('gif')}
101
+ it {@meta.should == {:format => :gif, :name => 'plasma.gif'}}
102
+ end
103
+ end
104
+
105
+ describe "text" do
106
+ before(:each) do
107
+ @text = "mmm"
108
+ end
109
+
110
+ describe "creating a text image" do
111
+ before(:each) do
112
+ @image, @meta = @generator.text(@text, :font_size => 12)
113
+ end
114
+ it {@image.should have_width(20..40)} # approximate
115
+ it {@image.should have_height(10..20)}
116
+ it {@image.should have_format('png')}
117
+ it {@meta.should == {:format => :png, :name => 'text.png'}}
118
+ end
119
+
120
+ describe "specifying the format" do
121
+ before(:each) do
122
+ @image, @meta = @generator.text(@text, :format => :gif)
123
+ end
124
+ it {@image.should have_format('gif')}
125
+ it {@meta.should == {:format => :gif, :name => 'text.gif'}}
126
+ end
127
+
128
+ describe "padding" do
129
+ before(:each) do
130
+ no_padding_text, meta = @generator.text(@text, :font_size => 12)
131
+ @width = image_properties(no_padding_text)[:width].to_i
132
+ @height = image_properties(no_padding_text)[:height].to_i
133
+ end
134
+ it "1 number shortcut" do
135
+ image, meta = @generator.text(@text, :padding => '10')
136
+ image.should have_width(@width + 20)
137
+ image.should have_height(@height + 20)
138
+ end
139
+ it "2 numbers shortcut" do
140
+ image, meta = @generator.text(@text, :padding => '10 5')
141
+ image.should have_width(@width + 10)
142
+ image.should have_height(@height + 20)
143
+ end
144
+ it "3 numbers shortcut" do
145
+ image, meta = @generator.text(@text, :padding => '10 5 8')
146
+ image.should have_width(@width + 10)
147
+ image.should have_height(@height + 18)
148
+ end
149
+ it "4 numbers shortcut" do
150
+ image, meta = @generator.text(@text, :padding => '1 2 3 4')
151
+ image.should have_width(@width + 6)
152
+ image.should have_height(@height + 4)
153
+ end
154
+ it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
155
+ image, meta = @generator.text(@text, :padding => '10', 'padding-left' => 9)
156
+ image.should have_width(@width + 19)
157
+ image.should have_height(@height + 20)
158
+ end
159
+ it "should ignore 'px' suffixes" do
160
+ image, meta = @generator.text(@text, :padding => '1px 2px 3px 4px')
161
+ image.should have_width(@width + 6)
162
+ image.should have_height(@height + 4)
163
+ end
164
+ it "bad padding string" do
165
+ lambda{
166
+ @generator.text(@text, :padding => '1 2 3 4 5')
167
+ }.should raise_error(ArgumentError)
168
+ end
169
+ end
170
+ end
171
+
172
+ end
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dragonfly::ImageMagick::Processor do
4
+
5
+ before(:each) do
6
+ sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
7
+ @image = Dragonfly::TempObject.new(File.new(sample_file))
8
+ @processor = Dragonfly::ImageMagick::Processor.new
9
+ end
10
+
11
+ describe "resize" do
12
+
13
+ it "should work correctly with xNN" do
14
+ image = @processor.resize(@image, 'x30')
15
+ image.should have_width(24)
16
+ image.should have_height(30)
17
+ end
18
+
19
+ it "should work correctly with NNx" do
20
+ image = @processor.resize(@image, '30x')
21
+ image.should have_width(30)
22
+ image.should have_height(38)
23
+ end
24
+
25
+ it "should work correctly with NNxNN" do
26
+ image = @processor.resize(@image, '30x30')
27
+ image.should have_width(24)
28
+ image.should have_height(30)
29
+ end
30
+
31
+ it "should work correctly with NNxNN!" do
32
+ image = @processor.resize(@image, '30x30!')
33
+ image.should have_width(30)
34
+ image.should have_height(30)
35
+ end
36
+
37
+ it "should work correctly with NNxNN%" do
38
+ image = @processor.resize(@image, '25x50%')
39
+ image.should have_width(70)
40
+ image.should have_height(178)
41
+ end
42
+
43
+ describe "NNxNN>" do
44
+
45
+ it "should not resize if the image is smaller than specified" do
46
+ image = @processor.resize(@image, '1000x1000>')
47
+ image.should have_width(280)
48
+ image.should have_height(355)
49
+ end
50
+
51
+ it "should resize if the image is larger than specified" do
52
+ image = @processor.resize(@image, '30x30>')
53
+ image.should have_width(24)
54
+ image.should have_height(30)
55
+ end
56
+
57
+ end
58
+
59
+ describe "NNxNN<" do
60
+
61
+ it "should not resize if the image is larger than specified" do
62
+ image = @processor.resize(@image, '10x10<')
63
+ image.should have_width(280)
64
+ image.should have_height(355)
65
+ end
66
+
67
+ it "should resize if the image is smaller than specified" do
68
+ image = @processor.resize(@image, '400x400<')
69
+ image.should have_width(315)
70
+ image.should have_height(400)
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ describe "crop" do # Difficult to test here other than dimensions
78
+
79
+ it "should not crop if no args given" do
80
+ image = @processor.crop(@image)
81
+ image.should have_width(280)
82
+ image.should have_height(355)
83
+ end
84
+
85
+ it "should crop using the offset given" do
86
+ image = @processor.crop(@image, :x => '7', :y => '12')
87
+ image.should have_width(273)
88
+ image.should have_height(343)
89
+ end
90
+
91
+ it "should crop using the dimensions given" do
92
+ image = @processor.crop(@image, :width => '10', :height => '20')
93
+ image.should have_width(10)
94
+ image.should have_height(20)
95
+ end
96
+
97
+ it "should crop in one dimension if given" do
98
+ image = @processor.crop(@image, :width => '10')
99
+ image.should have_width(10)
100
+ image.should have_height(355)
101
+ end
102
+
103
+ it "should take into account the gravity given" do
104
+ image1 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'nw')
105
+ image2 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'se')
106
+ image1.should_not == image2
107
+ end
108
+
109
+ it "should clip bits of the image outside of the requested crop area when not nw gravity" do
110
+ # Rmagick was previously throwing an error when the cropping area was outside the image size, when
111
+ # using a gravity other than nw
112
+ image = @processor.crop(@image, :width => '500', :height => '1000', :x => '100', :y => '200', :gravity => 'se')
113
+ image.should have_width(180)
114
+ image.should have_height(155)
115
+ end
116
+
117
+ end
118
+
119
+ describe "greyscale" do
120
+ it "should not raise an error" do
121
+ # Bit tricky to test
122
+ @processor.greyscale(@image)
123
+ end
124
+ end
125
+
126
+ describe "resize_and_crop" do
127
+
128
+ it "should do nothing if no args given" do
129
+ image = @processor.resize_and_crop(@image)
130
+ image.should have_width(280)
131
+ image.should have_height(355)
132
+ end
133
+
134
+ it "should crop to the correct dimensions" do
135
+ image = @processor.resize_and_crop(@image, :width => '100', :height => '100')
136
+ image.should have_width(100)
137
+ image.should have_height(100)
138
+ end
139
+
140
+ it "should allow cropping in one dimension" do
141
+ image = @processor.resize_and_crop(@image, :width => '100')
142
+ image.should have_width(100)
143
+ image.should have_height(355)
144
+ end
145
+
146
+ it "should take into account the gravity given" do
147
+ image1 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'nw')
148
+ image2 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'se')
149
+ image1.should_not == image2
150
+ end
151
+
152
+ end
153
+
154
+ describe "rotate" do
155
+
156
+ it "should rotate by 90 degrees" do
157
+ image = @processor.rotate(@image, 90)
158
+ image.should have_width(355)
159
+ image.should have_height(280)
160
+ end
161
+
162
+ it "should not rotate given a larger height and the '>' qualifier" do
163
+ image = @processor.rotate(@image, 90, :qualifier => '>')
164
+ image.should have_width(280)
165
+ image.should have_height(355)
166
+ end
167
+
168
+ it "should rotate given a larger height and the '<' qualifier" do
169
+ image = @processor.rotate(@image, 90, :qualifier => '<')
170
+ image.should have_width(355)
171
+ image.should have_height(280)
172
+ end
173
+
174
+ end
175
+
176
+ describe "thumb" do
177
+ it "should call resize if the correct string given" do
178
+ @processor.should_receive(:resize).with(@image, '30x40').and_return(image = mock)
179
+ @processor.thumb(@image, '30x40').should == image
180
+ end
181
+ it "should call resize_and_crop if the correct string given" do
182
+ @processor.should_receive(:resize_and_crop).with(@image, :width => '30', :height => '40', :gravity => 'se').and_return(image = mock)
183
+ @processor.thumb(@image, '30x40#se').should == image
184
+ end
185
+ it "should call crop if x and y given" do
186
+ @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => '+10', :y => '+20', :gravity => nil).and_return(image = mock)
187
+ @processor.thumb(@image, '30x40+10+20').should == image
188
+ end
189
+ it "should call crop if just gravity given" do
190
+ @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => nil, :y => nil, :gravity => 'sw').and_return(image = mock)
191
+ @processor.thumb(@image, '30x40sw').should == image
192
+ end
193
+ it "should call crop if x, y and gravity given" do
194
+ @processor.should_receive(:crop).with(@image, :width => '30', :height => '40', :x => '-10', :y => '-20', :gravity => 'se').and_return(image = mock)
195
+ @processor.thumb(@image, '30x40-10-20se').should == image
196
+ end
197
+ it "should raise an argument error if an unrecognized string is given" do
198
+ lambda{ @processor.thumb(@image, '30x40#ne!') }.should raise_error(ArgumentError)
199
+ end
200
+ end
201
+
202
+ describe "flip" do
203
+ it "should flip the image, leaving the same dimensions" do
204
+ image = @processor.flip(@image)
205
+ image.should have_width(280)
206
+ image.should have_height(355)
207
+ end
208
+ end
209
+
210
+ describe "flop" do
211
+ it "should flop the image, leaving the same dimensions" do
212
+ image = @processor.flop(@image)
213
+ image.should have_width(280)
214
+ image.should have_height(355)
215
+ end
216
+ end
217
+
218
+ describe "convert" do
219
+ it "should allow for general convert commands" do
220
+ image = @processor.convert(@image, '-scale 56x71')
221
+ image.should have_width(56)
222
+ image.should have_height(71)
223
+ end
224
+ it "should allow for general convert commands with added format" do
225
+ image, extra = @processor.convert(@image, '-scale 56x71', :gif)
226
+ image.should have_width(56)
227
+ image.should have_height(71)
228
+ image.should have_format('gif')
229
+ extra[:format].should == :gif
230
+ end
231
+ end
232
+
233
+ end