dragonfly 0.6.2 → 0.7.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 (157) hide show
  1. data/.gitignore +2 -0
  2. data/.specopts +2 -0
  3. data/.yardopts +11 -5
  4. data/Gemfile +22 -0
  5. data/Gemfile.rails.2.3.5 +13 -0
  6. data/History.md +49 -0
  7. data/README.md +18 -28
  8. data/Rakefile +24 -36
  9. data/VERSION +1 -1
  10. data/config.ru +4 -1
  11. data/dragonfly.gemspec +85 -99
  12. data/extra_docs/Analysers.md +66 -30
  13. data/extra_docs/Caching.md +22 -0
  14. data/extra_docs/Configuration.md +116 -0
  15. data/extra_docs/DataStorage.md +114 -14
  16. data/extra_docs/Encoding.md +62 -37
  17. data/extra_docs/GeneralUsage.md +118 -0
  18. data/extra_docs/Generators.md +92 -0
  19. data/extra_docs/Heroku.md +51 -0
  20. data/extra_docs/Index.md +8 -9
  21. data/extra_docs/MimeTypes.md +18 -17
  22. data/extra_docs/Models.md +251 -0
  23. data/extra_docs/Processing.md +94 -70
  24. data/extra_docs/Rack.md +53 -0
  25. data/extra_docs/Rails2.md +44 -0
  26. data/extra_docs/Rails3.md +51 -0
  27. data/extra_docs/Sinatra.md +21 -0
  28. data/extra_docs/URLs.md +114 -0
  29. data/features/images.feature +6 -7
  30. data/features/no_processing.feature +0 -6
  31. data/features/rails_2.3.5.feature +1 -1
  32. data/features/rails_3.0.0.rc.feature +8 -0
  33. data/features/steps/dragonfly_steps.rb +14 -12
  34. data/features/steps/rails_steps.rb +20 -9
  35. data/features/support/env.rb +10 -11
  36. data/fixtures/files/app/views/albums/new.html.erb +4 -4
  37. data/fixtures/files/app/views/albums/show.html.erb +1 -1
  38. data/fixtures/files/features/manage_album_images.feature +1 -1
  39. data/fixtures/files/features/step_definitions/{album_steps.rb → image_steps.rb} +4 -3
  40. data/fixtures/files/features/support/paths.rb +2 -0
  41. data/fixtures/files/features/text_images.feature +7 -0
  42. data/fixtures/rails_3.0.0.rc/template.rb +21 -0
  43. data/irbrc.rb +2 -1
  44. data/lib/dragonfly.rb +4 -16
  45. data/lib/dragonfly/{active_record_extensions.rb → active_model_extensions.rb} +1 -1
  46. data/lib/dragonfly/active_model_extensions/attachment.rb +146 -0
  47. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/class_methods.rb +5 -6
  48. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/instance_methods.rb +1 -1
  49. data/lib/dragonfly/{active_record_extensions → active_model_extensions}/validations.rb +5 -9
  50. data/lib/dragonfly/analyser.rb +59 -0
  51. data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
  52. data/lib/dragonfly/analysis/r_magick_analyser.rb +46 -31
  53. data/lib/dragonfly/app.rb +138 -173
  54. data/lib/dragonfly/config/heroku.rb +19 -0
  55. data/lib/dragonfly/config/r_magick.rb +37 -0
  56. data/lib/dragonfly/config/{rails_defaults.rb → rails.rb} +6 -7
  57. data/lib/dragonfly/configurable.rb +30 -27
  58. data/lib/dragonfly/core_ext/object.rb +1 -1
  59. data/lib/dragonfly/data_storage/file_data_store.rb +59 -26
  60. data/lib/dragonfly/data_storage/mongo_data_store.rb +65 -0
  61. data/lib/dragonfly/data_storage/s3data_store.rb +31 -12
  62. data/lib/dragonfly/encoder.rb +13 -0
  63. data/lib/dragonfly/encoding/r_magick_encoder.rb +10 -19
  64. data/lib/dragonfly/endpoint.rb +43 -0
  65. data/lib/dragonfly/function_manager.rb +65 -0
  66. data/lib/dragonfly/{processing/r_magick_text_processor.rb → generation/r_magick_generator.rb} +25 -11
  67. data/lib/dragonfly/generator.rb +9 -0
  68. data/lib/dragonfly/job.rb +290 -0
  69. data/lib/dragonfly/job_builder.rb +39 -0
  70. data/lib/dragonfly/job_definitions.rb +26 -0
  71. data/lib/dragonfly/job_endpoint.rb +17 -0
  72. data/lib/dragonfly/loggable.rb +28 -0
  73. data/lib/dragonfly/middleware.rb +21 -14
  74. data/lib/dragonfly/processing/r_magick_processor.rb +71 -48
  75. data/lib/dragonfly/processor.rb +9 -0
  76. data/lib/dragonfly/r_magick_utils.rb +24 -0
  77. data/lib/dragonfly/rails/images.rb +10 -7
  78. data/lib/dragonfly/routed_endpoint.rb +42 -0
  79. data/lib/dragonfly/serializer.rb +32 -0
  80. data/lib/dragonfly/simple_cache.rb +23 -0
  81. data/lib/dragonfly/simple_endpoint.rb +64 -0
  82. data/lib/dragonfly/temp_object.rb +77 -45
  83. data/spec/argument_matchers.rb +7 -17
  84. data/spec/dragonfly/active_model_extensions/active_model_setup.rb +97 -0
  85. data/spec/dragonfly/active_model_extensions/active_record_setup.rb +85 -0
  86. data/spec/dragonfly/{active_record_extensions → active_model_extensions}/model_spec.rb +282 -244
  87. data/spec/dragonfly/active_model_extensions/spec_helper.rb +11 -0
  88. data/spec/dragonfly/analyser_spec.rb +123 -0
  89. data/spec/dragonfly/analysis/file_command_analyser_spec.rb +2 -2
  90. data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +10 -1
  91. data/spec/dragonfly/app_spec.rb +175 -69
  92. data/spec/dragonfly/configurable_spec.rb +14 -0
  93. data/spec/dragonfly/data_storage/data_store_spec.rb +36 -9
  94. data/spec/dragonfly/data_storage/file_data_store_spec.rb +61 -38
  95. data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +18 -0
  96. data/spec/dragonfly/data_storage/s3_data_store_spec.rb +34 -39
  97. data/spec/dragonfly/deprecation_spec.rb +20 -0
  98. data/spec/dragonfly/function_manager_spec.rb +154 -0
  99. data/spec/dragonfly/generation/r_magick_generator_spec.rb +119 -0
  100. data/spec/dragonfly/job_builder_spec.rb +37 -0
  101. data/spec/dragonfly/job_definitions_spec.rb +35 -0
  102. data/spec/dragonfly/job_endpoint_spec.rb +66 -0
  103. data/spec/dragonfly/job_spec.rb +605 -0
  104. data/spec/dragonfly/loggable_spec.rb +80 -0
  105. data/spec/dragonfly/middleware_spec.rb +37 -17
  106. data/spec/dragonfly/processing/r_magick_processor_spec.rb +182 -166
  107. data/spec/dragonfly/routed_endpoint_spec.rb +48 -0
  108. data/spec/dragonfly/serializer_spec.rb +61 -0
  109. data/spec/dragonfly/simple_cache_spec.rb +27 -0
  110. data/spec/dragonfly/simple_endpoint_spec.rb +78 -0
  111. data/spec/dragonfly/temp_object_spec.rb +154 -119
  112. data/spec/simple_matchers.rb +22 -0
  113. data/spec/spec_helper.rb +28 -4
  114. data/yard/templates/default/layout/html/layout.erb +18 -11
  115. metadata +89 -190
  116. data/config.rb +0 -5
  117. data/extra_docs/ActiveRecord.md +0 -196
  118. data/extra_docs/ExampleUseCases.md +0 -189
  119. data/extra_docs/GettingStarted.md +0 -114
  120. data/extra_docs/Shortcuts.md +0 -118
  121. data/extra_docs/UsingWithRails.md +0 -81
  122. data/features/rails_3.0.0.beta3.feature +0 -7
  123. data/fixtures/rails_3.0.0.beta3/template.rb +0 -16
  124. data/lib/dragonfly/active_record_extensions/attachment.rb +0 -170
  125. data/lib/dragonfly/analyser_list.rb +0 -9
  126. data/lib/dragonfly/analysis/base.rb +0 -10
  127. data/lib/dragonfly/belongs_to_app.rb +0 -24
  128. data/lib/dragonfly/config/heroku_rails_images.rb +0 -23
  129. data/lib/dragonfly/config/r_magick_images.rb +0 -69
  130. data/lib/dragonfly/config/r_magick_text.rb +0 -25
  131. data/lib/dragonfly/config/rails_images.rb +0 -13
  132. data/lib/dragonfly/data_storage/base.rb +0 -21
  133. data/lib/dragonfly/data_storage/base64_data_store.rb +0 -23
  134. data/lib/dragonfly/data_storage/transparent_data_store.rb +0 -21
  135. data/lib/dragonfly/delegatable.rb +0 -14
  136. data/lib/dragonfly/delegator.rb +0 -62
  137. data/lib/dragonfly/encoder_list.rb +0 -9
  138. data/lib/dragonfly/encoding/base.rb +0 -14
  139. data/lib/dragonfly/encoding/transparent_encoder.rb +0 -14
  140. data/lib/dragonfly/extended_temp_object.rb +0 -120
  141. data/lib/dragonfly/parameters.rb +0 -163
  142. data/lib/dragonfly/processing/base.rb +0 -10
  143. data/lib/dragonfly/processor_list.rb +0 -9
  144. data/lib/dragonfly/url_handler.rb +0 -147
  145. data/spec/dragonfly/active_record_extensions/attachment_spec.rb +0 -8
  146. data/spec/dragonfly/active_record_extensions/migration.rb +0 -42
  147. data/spec/dragonfly/active_record_extensions/models.rb +0 -6
  148. data/spec/dragonfly/active_record_extensions/spec_helper.rb +0 -24
  149. data/spec/dragonfly/belongs_to_app_spec.rb +0 -55
  150. data/spec/dragonfly/delegatable_spec.rb +0 -32
  151. data/spec/dragonfly/delegator_spec.rb +0 -145
  152. data/spec/dragonfly/extended_temp_object_spec.rb +0 -71
  153. data/spec/dragonfly/parameters_spec.rb +0 -298
  154. data/spec/dragonfly/processing/r_magick_text_processor_spec.rb +0 -84
  155. data/spec/dragonfly/url_handler_spec.rb +0 -247
  156. data/spec/dragonfly_spec.rb +0 -16
  157. data/spec/ginger_scenarios.rb +0 -13
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ class Testoast
4
+ include Dragonfly::Loggable
5
+ end
6
+
7
+ describe Dragonfly::Loggable do
8
+
9
+ before(:each) do
10
+ @object = Testoast.new
11
+ end
12
+
13
+ describe "common", :shared => true do
14
+ it "should return a log" do
15
+ @object.log.should be_a(Logger)
16
+ end
17
+ it "should cache the log" do
18
+ @object.log.should == @object.log
19
+ end
20
+ end
21
+
22
+ describe "without being set" do
23
+ it "should return the log object as nil" do
24
+ @object.log_object.should be_nil
25
+ end
26
+ it_should_behave_like 'common'
27
+ end
28
+
29
+ describe "when set" do
30
+ before(:each) do
31
+ @log = Logger.new($stdout)
32
+ @object.log = @log
33
+ end
34
+ it "should return the new log" do
35
+ @object.log.should == @log
36
+ end
37
+ it "should return the log object" do
38
+ @object.log_object.should == @log
39
+ end
40
+ it_should_behave_like 'common'
41
+ end
42
+
43
+ describe "when set as a proc" do
44
+ before(:each) do
45
+ @log = Logger.new($stdout)
46
+ @object.log = proc{ @log }
47
+ end
48
+ it "should return the new log" do
49
+ @object.log.should == @log
50
+ end
51
+ it "should return the log object" do
52
+ @object.log_object.should be_a(Proc)
53
+ end
54
+ it "should allow for changing logs" do
55
+ logs = [@log]
56
+ @object.log = proc{ logs[0] }
57
+ @object.log.should == @log
58
+
59
+ new_log = Logger.new($stdout)
60
+ logs[0] = new_log
61
+
62
+ @object.log.should == new_log
63
+ end
64
+ it_should_behave_like 'common'
65
+ end
66
+
67
+ describe "sharing logs" do
68
+ before(:each) do
69
+ @log = Logger.new($stdout)
70
+ @obj1 = Testoast.new
71
+ @obj2 = Testoast.new
72
+ end
73
+ it "should enable sharing logs" do
74
+ @obj1.log = proc{ @log }
75
+ @obj2.use_same_log_as(@obj1)
76
+ @obj2.log.should == @log
77
+ end
78
+ end
79
+
80
+ end
@@ -13,35 +13,55 @@ describe Dragonfly::Middleware do
13
13
 
14
14
  before(:each) do
15
15
  @stack = Rack::Builder.new do
16
- use Dragonfly::Middleware, :images
16
+ use Dragonfly::Middleware, :images, '/media'
17
17
  run dummy_rack_app
18
18
  end
19
19
  end
20
20
 
21
- it "should continue the calling chain if the app returns a 404 for that url" do
22
- Dragonfly::App[:images].should_receive(:call).and_return(
23
- [404, {"Content-Type" => 'text/plain'}, ['Not found']]
24
- )
25
- response = make_request(@stack, 'hello.png?howare=you')
21
+ it "should pass through for urls with incorrect prefix" do
22
+ Dragonfly[:images].should_not_receive(:call)
23
+ response = make_request(@stack, '/hello.png?howare=you')
26
24
  response.status.should == 200
27
25
  response.body.should == 'dummy_rack_app body'
28
26
  end
29
27
 
30
- it "should return as per the dragonfly app if the app returns a 200" do
31
- Dragonfly::App[:images].should_receive(:call).and_return(
32
- [200, {"Content-Type" => 'text/plain'}, ['ABCD']]
28
+ it "should pass through if the app returns and X-Cascade: pass" do
29
+ Dragonfly[:images].should_receive(:call).and_return(
30
+ [404, {"Content-Type" => 'text/plain', 'X-Cascade' => 'pass'}, ['Not found']]
33
31
  )
34
- response = make_request(@stack, 'hello.png?howare=you')
35
- response.status.should == 200
36
- response.body.should == 'ABCD'
32
+ response = make_request(@stack, '/media/hello.png?howare=you')
33
+ response.body.should == 'dummy_rack_app body'
37
34
  end
38
35
 
39
- it "should return as per the dragonfly app if the app returns a 400" do
40
- Dragonfly::App[:images].should_receive(:call).and_return(
41
- [400, {"Content-Type" => 'text/plain'}, ['ABCD']]
36
+ it "should return a 404 if the app returns a 404 for that url but no X-Cascade: pass" do
37
+ Dragonfly[:images].should_receive(:call).and_return(
38
+ [404, {"Content-Type" => 'text/plain'}, ['Not found']]
42
39
  )
43
- response = make_request(@stack, 'hello.png?howare=you')
44
- response.status.should == 400
40
+ response = make_request(@stack, '/media/hello.png?howare=you')
41
+ response.status.should == 404
42
+ end
43
+
44
+ %w(0.1 0.9 0.10 1.0 1.0.0 1.0.1).each do |version|
45
+ it "should pass through if the rack version is #{version} (i.e. no X-Cascade: pass) and the app returns 404" do
46
+ Rack.should_receive(:version).and_return(version)
47
+ Dragonfly[:images].should_receive(:call).and_return(
48
+ [404, {"Content-Type" => 'text/plain'}, ['Not found']]
49
+ )
50
+ response = make_request(@stack, '/media/hello.png?howare=you')
51
+ response.status.should == 200
52
+ response.body.should == 'dummy_rack_app body'
53
+ end
54
+ end
55
+
56
+ %w(1.1 1.1.1 2.9).each do |version|
57
+ end
58
+
59
+ it "should return as per the dragonfly app if the app returns a 200" do
60
+ Dragonfly[:images].should_receive(:call).and_return(
61
+ [200, {"Content-Type" => 'text/plain'}, ['ABCD']]
62
+ )
63
+ response = make_request(@stack, '/media/hello.png?howare=you')
64
+ response.status.should == 200
45
65
  response.body.should == 'ABCD'
46
66
  end
47
67
 
@@ -1,201 +1,217 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe Dragonfly::Processing::RMagickProcessor 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::Processing::RMagickProcessor.new
9
+ end
10
+
11
+ describe "resize" do
4
12
 
5
- describe "generate" do
6
- before(:each) do
7
- @processor = Dragonfly::Processing::RMagickProcessor.new
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)
8
17
  end
9
-
10
- it "should generate an image with the given dimensions, defaulting to png format" do
11
- image = @processor.generate(23,12)
12
- image.should have_width(23)
13
- image.should have_height(12)
14
- image.should have_format('png')
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)
15
23
  end
16
- it "should allow specifying the format" do
17
- image = @processor.generate(23, 12, :gif)
18
- image.should have_format('gif')
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)
19
29
  end
20
- end
21
-
22
- describe "processing methods" do
23
30
 
24
- before(:each) do
25
- sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
26
- @image = Dragonfly::TempObject.new(File.new(sample_file))
27
- @processor = Dragonfly::Processing::RMagickProcessor.new
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)
28
35
  end
29
36
 
30
- describe "resize" do
31
-
32
- it "should work correctly with xNN" do
33
- image = @processor.resize(@image, :geometry => 'x30')
34
- image.should have_width(24)
35
- image.should have_height(30)
36
- end
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
37
44
 
38
- it "should work correctly with NNx" do
39
- image = @processor.resize(@image, :geometry => '30x')
40
- image.should have_width(30)
41
- image.should have_height(38)
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)
42
49
  end
43
50
 
44
- it "should work correctly with NNxNN" do
45
- image = @processor.resize(@image, :geometry => '30x30')
51
+ it "should resize if the image is larger than specified" do
52
+ image = @processor.resize(@image, '30x30>')
46
53
  image.should have_width(24)
47
54
  image.should have_height(30)
48
55
  end
49
56
 
50
- it "should work correctly with NNxNN!" do
51
- image = @processor.resize(@image, :geometry => '30x30!')
52
- image.should have_width(30)
53
- image.should have_height(30)
54
- end
55
-
56
- it "should work correctly with NNxNN%" do
57
- image = @processor.resize(@image, :geometry => '25x50%')
58
- image.should have_width(70)
59
- image.should have_height(178)
60
- end
61
-
62
- describe "NNxNN>" do
63
-
64
- it "should not resize if the image is smaller than specified" do
65
- image = @processor.resize(@image, :geometry => '1000x1000>')
66
- image.should have_width(280)
67
- image.should have_height(355)
68
- end
69
-
70
- it "should resize if the image is larger than specified" do
71
- image = @processor.resize(@image, :geometry => '30x30>')
72
- image.should have_width(24)
73
- image.should have_height(30)
74
- end
75
-
76
- end
77
-
78
- describe "NNxNN<" do
79
-
80
- it "should not resize if the image is larger than specified" do
81
- image = @processor.resize(@image, :geometry => '10x10<')
82
- image.should have_width(280)
83
- image.should have_height(355)
84
- end
85
-
86
- it "should resize if the image is smaller than specified" do
87
- image = @processor.resize(@image, :geometry => '400x400<')
88
- image.should have_width(315)
89
- image.should have_height(400)
90
- end
91
-
92
- end
93
-
94
57
  end
95
58
 
96
- describe "crop" do # Difficult to test here other than dimensions
59
+ describe "NNxNN<" do
97
60
 
98
- it "should not crop if no args given" do
99
- image = @processor.crop(@image)
61
+ it "should not resize if the image is larger than specified" do
62
+ image = @processor.resize(@image, '10x10<')
100
63
  image.should have_width(280)
101
64
  image.should have_height(355)
102
65
  end
103
66
 
104
- it "should crop using the offset given" do
105
- image = @processor.crop(@image, :x => '7', :y => '12')
106
- image.should have_width(273)
107
- image.should have_height(343)
108
- end
109
-
110
- it "should crop using the dimensions given" do
111
- image = @processor.crop(@image, :width => '10', :height => '20')
112
- image.should have_width(10)
113
- image.should have_height(20)
114
- end
115
-
116
- it "should crop in one dimension if given" do
117
- image = @processor.crop(@image, :width => '10')
118
- image.should have_width(10)
119
- image.should have_height(355)
120
- end
121
-
122
- it "should take into account the gravity given" do
123
- image1 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'nw')
124
- image2 = @processor.crop(@image, :width => '10', :height => '10', :gravity => 'se')
125
- image1.should_not == image2
126
- end
127
-
128
- it "should clip bits of the image outside of the requested crop area when not nw gravity" do
129
- # Rmagick was previously throwing an error when the cropping area was outside the image size, when
130
- # using a gravity other than nw
131
- image = @processor.crop(@image, :width => '500', :height => '1000', :x => '100', :y => '200', :gravity => 'se')
132
- image.should have_width(180)
133
- image.should have_height(155)
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)
134
71
  end
135
72
 
136
73
  end
74
+
75
+ end
137
76
 
138
- describe "greyscale" do
139
- it "should not raise an error" do
140
- # Bit tricky to test
141
- @processor.greyscale(@image)
142
- end
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)
143
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
144
118
 
145
- describe "resize_and_crop" do
146
-
147
- it "should do nothing if no args given" do
148
- image = @processor.resize_and_crop(@image)
149
- image.should have_width(280)
150
- image.should have_height(355)
151
- end
152
-
153
- it "should crop to the correct dimensions" do
154
- image = @processor.resize_and_crop(@image, :width => '100', :height => '100')
155
- image.should have_width(100)
156
- image.should have_height(100)
157
- end
158
-
159
- it "should allow cropping in one dimension" do
160
- image = @processor.resize_and_crop(@image, :width => '100')
161
- image.should have_width(100)
162
- image.should have_height(355)
163
- end
164
-
165
- it "should take into account the gravity given" do
166
- image1 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'nw')
167
- image2 = @processor.resize_and_crop(@image, :width => '10', :height => '10', :gravity => 'se')
168
- image1.should_not == image2
169
- end
170
-
119
+ describe "greyscale" do
120
+ it "should not raise an error" do
121
+ # Bit tricky to test
122
+ @processor.greyscale(@image)
171
123
  end
124
+ end
125
+
126
+ describe "resize_and_crop" do
172
127
 
173
- describe "rotate" do
174
-
175
- it "should rotate by 90 degrees" do
176
- image = @processor.rotate(@image, :amount => '90')
177
- image.should have_width(355)
178
- image.should have_height(280)
179
- end
180
-
181
- it "should not rotate given a larger height and the '>' qualifier" do
182
- image = @processor.rotate(@image, :amount => 90, :qualifier => '>')
183
- image.should have_width(280)
184
- image.should have_height(355)
185
- end
186
-
187
- it "should rotate given a larger height and the '<' qualifier" do
188
- image = @processor.rotate(@image, :amount => 90, :qualifier => '<')
189
- image.should have_width(355)
190
- image.should have_height(280)
191
- end
192
-
193
- it "should do nothing if no amount given" do
194
- image = @processor.rotate(@image)
195
- image.should have_width(280)
196
- image.should have_height(355)
197
- end
198
-
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)
199
215
  end
200
216
  end
201
217