dougmcbride-fleximage 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.gitignore +27 -0
  2. data/CHANGELOG.rdoc +14 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +257 -0
  5. data/Rakefile +49 -0
  6. data/VERSION +1 -0
  7. data/autotest.rb +5 -0
  8. data/fleximage.gemspec +236 -0
  9. data/init.rb +1 -0
  10. data/lib/dsl_accessor.rb +52 -0
  11. data/lib/fleximage.rb +59 -0
  12. data/lib/fleximage/aviary_controller.rb +75 -0
  13. data/lib/fleximage/blank.rb +70 -0
  14. data/lib/fleximage/helper.rb +41 -0
  15. data/lib/fleximage/image_proxy.rb +69 -0
  16. data/lib/fleximage/legacy_view.rb +63 -0
  17. data/lib/fleximage/model.rb +726 -0
  18. data/lib/fleximage/operator/background.rb +62 -0
  19. data/lib/fleximage/operator/base.rb +189 -0
  20. data/lib/fleximage/operator/border.rb +50 -0
  21. data/lib/fleximage/operator/crop.rb +58 -0
  22. data/lib/fleximage/operator/image_overlay.rb +85 -0
  23. data/lib/fleximage/operator/resize.rb +92 -0
  24. data/lib/fleximage/operator/shadow.rb +87 -0
  25. data/lib/fleximage/operator/text.rb +104 -0
  26. data/lib/fleximage/operator/trim.rb +14 -0
  27. data/lib/fleximage/operator/unsharp_mask.rb +36 -0
  28. data/lib/fleximage/rmagick_image_patch.rb +5 -0
  29. data/lib/fleximage/string_patch.rb +5 -0
  30. data/lib/fleximage/view.rb +58 -0
  31. data/tasks/fleximage_tasks.rake +154 -0
  32. data/test/fixtures/100x1.jpg +0 -0
  33. data/test/fixtures/100x100.jpg +0 -0
  34. data/test/fixtures/1x1.jpg +0 -0
  35. data/test/fixtures/1x100.jpg +0 -0
  36. data/test/fixtures/cmyk.jpg +0 -0
  37. data/test/fixtures/not_a_photo.xml +1 -0
  38. data/test/fixtures/photo.jpg +0 -0
  39. data/test/mock_file.rb +21 -0
  40. data/test/rails_root/app/controllers/application.rb +10 -0
  41. data/test/rails_root/app/controllers/avatars_controller.rb +85 -0
  42. data/test/rails_root/app/controllers/photo_bares_controller.rb +85 -0
  43. data/test/rails_root/app/controllers/photo_dbs_controller.rb +85 -0
  44. data/test/rails_root/app/controllers/photo_files_controller.rb +85 -0
  45. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  46. data/test/rails_root/app/helpers/avatars_helper.rb +2 -0
  47. data/test/rails_root/app/helpers/photo_bares_helper.rb +2 -0
  48. data/test/rails_root/app/helpers/photo_dbs_helper.rb +2 -0
  49. data/test/rails_root/app/helpers/photo_files_helper.rb +2 -0
  50. data/test/rails_root/app/locales/de.yml +7 -0
  51. data/test/rails_root/app/locales/en.yml +8 -0
  52. data/test/rails_root/app/models/abstract.rb +8 -0
  53. data/test/rails_root/app/models/avatar.rb +4 -0
  54. data/test/rails_root/app/models/photo_bare.rb +7 -0
  55. data/test/rails_root/app/models/photo_custom_error.rb +10 -0
  56. data/test/rails_root/app/models/photo_db.rb +3 -0
  57. data/test/rails_root/app/models/photo_file.rb +3 -0
  58. data/test/rails_root/app/views/avatars/edit.html.erb +17 -0
  59. data/test/rails_root/app/views/avatars/index.html.erb +20 -0
  60. data/test/rails_root/app/views/avatars/new.html.erb +16 -0
  61. data/test/rails_root/app/views/avatars/show.html.erb +8 -0
  62. data/test/rails_root/app/views/layouts/avatars.html.erb +17 -0
  63. data/test/rails_root/app/views/layouts/photo_bares.html.erb +17 -0
  64. data/test/rails_root/app/views/layouts/photo_dbs.html.erb +17 -0
  65. data/test/rails_root/app/views/layouts/photo_files.html.erb +17 -0
  66. data/test/rails_root/app/views/photo_bares/edit.html.erb +12 -0
  67. data/test/rails_root/app/views/photo_bares/index.html.erb +18 -0
  68. data/test/rails_root/app/views/photo_bares/new.html.erb +11 -0
  69. data/test/rails_root/app/views/photo_bares/show.html.erb +3 -0
  70. data/test/rails_root/app/views/photo_dbs/edit.html.erb +32 -0
  71. data/test/rails_root/app/views/photo_dbs/index.html.erb +26 -0
  72. data/test/rails_root/app/views/photo_dbs/new.html.erb +31 -0
  73. data/test/rails_root/app/views/photo_dbs/show.html.erb +23 -0
  74. data/test/rails_root/app/views/photo_files/edit.html.erb +27 -0
  75. data/test/rails_root/app/views/photo_files/index.html.erb +24 -0
  76. data/test/rails_root/app/views/photo_files/new.html.erb +26 -0
  77. data/test/rails_root/app/views/photo_files/show.html.erb +18 -0
  78. data/test/rails_root/config/boot.rb +109 -0
  79. data/test/rails_root/config/database.yml +7 -0
  80. data/test/rails_root/config/environment.rb +66 -0
  81. data/test/rails_root/config/environments/development.rb +18 -0
  82. data/test/rails_root/config/environments/production.rb +19 -0
  83. data/test/rails_root/config/environments/sqlite3.rb +0 -0
  84. data/test/rails_root/config/environments/test.rb +22 -0
  85. data/test/rails_root/config/initializers/inflections.rb +10 -0
  86. data/test/rails_root/config/initializers/load_translations.rb +4 -0
  87. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  88. data/test/rails_root/config/routes.rb +43 -0
  89. data/test/rails_root/db/migrate/001_create_photo_files.rb +16 -0
  90. data/test/rails_root/db/migrate/002_create_photo_dbs.rb +16 -0
  91. data/test/rails_root/db/migrate/003_create_photo_bares.rb +12 -0
  92. data/test/rails_root/db/migrate/004_create_avatars.rb +13 -0
  93. data/test/rails_root/public/.htaccess +40 -0
  94. data/test/rails_root/public/404.html +30 -0
  95. data/test/rails_root/public/422.html +30 -0
  96. data/test/rails_root/public/500.html +30 -0
  97. data/test/rails_root/public/dispatch.cgi +10 -0
  98. data/test/rails_root/public/dispatch.fcgi +24 -0
  99. data/test/rails_root/public/dispatch.rb +10 -0
  100. data/test/rails_root/public/favicon.ico +0 -0
  101. data/test/rails_root/public/images/rails.png +0 -0
  102. data/test/rails_root/public/index.html +277 -0
  103. data/test/rails_root/public/javascripts/application.js +2 -0
  104. data/test/rails_root/public/javascripts/controls.js +963 -0
  105. data/test/rails_root/public/javascripts/dragdrop.js +972 -0
  106. data/test/rails_root/public/javascripts/effects.js +1120 -0
  107. data/test/rails_root/public/javascripts/prototype.js +4225 -0
  108. data/test/rails_root/public/robots.txt +5 -0
  109. data/test/rails_root/public/stylesheets/scaffold.css +74 -0
  110. data/test/rails_root/vendor/plugins/fleximage/init.rb +2 -0
  111. data/test/test_helper.rb +81 -0
  112. data/test/unit/abstract_test.rb +20 -0
  113. data/test/unit/basic_model_test.rb +36 -0
  114. data/test/unit/blank_test.rb +23 -0
  115. data/test/unit/default_image_path_option_test.rb +16 -0
  116. data/test/unit/dsl_accessor_test.rb +120 -0
  117. data/test/unit/file_upload_from_local_test.rb +31 -0
  118. data/test/unit/file_upload_from_strings_test.rb +23 -0
  119. data/test/unit/file_upload_from_url_test.rb +35 -0
  120. data/test/unit/file_upload_to_db_test.rb +41 -0
  121. data/test/unit/i18n_messages_test.rb +49 -0
  122. data/test/unit/image_directory_option_test.rb +20 -0
  123. data/test/unit/image_proxy_test.rb +17 -0
  124. data/test/unit/image_storage_format_option_test.rb +31 -0
  125. data/test/unit/magic_columns_test.rb +34 -0
  126. data/test/unit/minimum_image_size_test.rb +56 -0
  127. data/test/unit/operator_base_test.rb +124 -0
  128. data/test/unit/operator_resize_test.rb +18 -0
  129. data/test/unit/preprocess_image_option_test.rb +21 -0
  130. data/test/unit/require_image_option_test.rb +30 -0
  131. data/test/unit/temp_image_test.rb +23 -0
  132. data/test/unit/use_creation_date_based_directories_option_test.rb +16 -0
  133. metadata +284 -0
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageFileUploadToDbTest < Test::Unit::TestCase
4
+ def test_should_be_valid_with_image
5
+ p = PhotoDb.new(:image_file => files(:photo))
6
+ assert p.save, 'Record expected to be allowed to save'
7
+
8
+ p = PhotoDb.find(p.id)
9
+ assert_kind_of Magick::Image, p.load_image
10
+ assert p.image_file_data.size > 0
11
+ end
12
+
13
+ def test_should_require_an_image
14
+ p = PhotoDb.new
15
+ assert !p.save, 'Record expected to not be allowed to save'
16
+ assert_equal 1, p.errors.size
17
+ assert_equal 'is required', p.errors.on(:image_file)
18
+ end
19
+
20
+ def test_should_require_an_valid_image
21
+ p = PhotoDb.new(:image_file => files(:not_a_photo))
22
+ assert !p.save, 'Record expected to not be allowed to save'
23
+ assert_equal 1, p.errors.size
24
+ assert_equal 'was not a readable image', p.errors.on(:image_file)
25
+ end
26
+
27
+ def test_should_retrieve_a_stored_image
28
+ id = PhotoDb.create(:image_file => files(:photo)).id
29
+ p = PhotoDb.find(id)
30
+ assert_kind_of Magick::Image, p.load_image
31
+ assert_equal 768, p.load_image.columns
32
+ assert_equal 1024, p.load_image.rows
33
+ end
34
+
35
+ def test_should_delete_an_image
36
+ id = PhotoDb.create(:image_file => files(:photo)).id
37
+ photo = PhotoDb.find(id)
38
+ photo.destroy
39
+ assert_nil PhotoDb.find_by_id(id)
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+
4
+ class I18nMessagesTest < Test::Unit::TestCase
5
+ def test_should_have_default_message
6
+ p = PhotoBare.new
7
+ p.save
8
+ assert_equal "is required", p.errors["image_file"]
9
+
10
+ p = PhotoBare.new(:image_file => files(:not_a_photo))
11
+ p.save
12
+ assert_equal "was not a readable image", p.errors["image_file"]
13
+
14
+ p = PhotoBare.new(:image_file => files(:i1x1))
15
+ p.save
16
+ assert_equal "is too small (Minimum: 2x2)", p.errors["image_file"]
17
+ end
18
+
19
+ def test_should_have_german_message
20
+ I18n.locale = "de"
21
+ p = PhotoBare.new
22
+ p.save
23
+ assert_equal "ist erforderlich", p.errors["image_file"]
24
+
25
+ p = PhotoBare.new(:image_file => files(:not_a_photo))
26
+ p.save
27
+ assert_equal "war nicht lesbar", p.errors["image_file"]
28
+
29
+ p = PhotoBare.new(:image_file => files(:i1x1))
30
+ p.save
31
+ assert_equal "ist zu klein (Minimalgröße: 2x2)", p.errors["image_file"]
32
+ ensure
33
+ I18n.locale = "en"
34
+ end
35
+
36
+ def test_should_have_model_specific_message
37
+ p = PhotoCustomError.new
38
+ assert !p.save
39
+ assert_equal "needs to be attached", p.errors["image_file"]
40
+
41
+ p = PhotoCustomError.new(:image_file => files(:not_a_photo))
42
+ p.save
43
+ assert_equal "seems to be broken", p.errors["image_file"]
44
+
45
+ p = PhotoCustomError.new(:image_file => files(:i1x1))
46
+ assert !p.save
47
+ assert_equal "must be bigger (min. size: 2x2)", p.errors["image_file"]
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageImageDirectoryOptionTest < Test::Unit::TestCase
4
+ def test_should_store_in_default_image_directory
5
+ PhotoBare.use_creation_date_based_directories = true
6
+ p = PhotoBare.create(:image_file => files(:photo))
7
+ assert_match %r{public/uploads/\d+/\d+/\d+/\d+}, p.file_path
8
+ assert File.exists?(p.file_path)
9
+ end
10
+
11
+ def test_should_set_image_directory
12
+ PhotoBare.use_creation_date_based_directories = true
13
+ PhotoBare.image_directory = 'public/uploads/foo'
14
+ p = PhotoBare.create(:image_file => files(:photo))
15
+ assert_match %r{public/uploads/foo/\d+/\d+/\d+/\d+}, p.file_path
16
+ assert File.exists?(p.file_path)
17
+ ensure
18
+ PhotoBare.image_directory = 'public/uploads'
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageImageProxyTest < Test::Unit::TestCase
4
+ def test_should_have_a_width
5
+ p = PhotoBare.create(:image_file => files(:photo))
6
+ p.operate do |image|
7
+ assert_equal 768, image.width
8
+ end
9
+ end
10
+
11
+ def test_should_have_a_height
12
+ p = PhotoBare.create(:image_file => files(:photo))
13
+ p.operate do |image|
14
+ assert_equal 1024, image.height
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageImageStorageOptionTest < Test::Unit::TestCase
4
+ def test_should_have_default_storage_format_png
5
+ p = PhotoBare.create(:image_file => files(:photo))
6
+ assert_match %r{\d+\.png$}, p.file_path
7
+ assert_equal 'PNG', p.load_image.format
8
+ end
9
+
10
+ def test_should_set_image_storage_format_to_jpg
11
+ PhotoBare.image_storage_format = :jpg
12
+ p = PhotoBare.create(:image_file => files(:photo))
13
+ assert_match %r{\d+\.jpg$}, p.file_path
14
+ assert_equal 'JPG', p.load_image.format
15
+ ensure
16
+ PhotoBare.image_storage_format = :png
17
+ end
18
+
19
+ def test_should_have_default_storage_format_png_in_db
20
+ p = PhotoDb.create(:image_file => files(:photo))
21
+ assert_equal 'PNG', p.load_image.format
22
+ end
23
+
24
+ def test_should_set_image_storage_format_to_jpg_in_db
25
+ PhotoDb.image_storage_format = :jpg
26
+ p = PhotoDb.create(:image_file => files(:photo))
27
+ assert_equal 'JPG', p.load_image.format
28
+ ensure
29
+ PhotoDb.image_storage_format = :png
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageMagicColumnsTest < Test::Unit::TestCase
4
+ def test_should_save_data_in_magic_columns_from_local
5
+ p = PhotoFile.create(:image_file => files(:photo))
6
+ assert_equal 'photo.jpg', p.image_filename
7
+ assert_equal 1024, p.image_height
8
+ assert_equal 768, p.image_width
9
+ assert_equal 'JPEG', p.image_format
10
+ assert_equal 'jpg', p.extension
11
+ end
12
+
13
+ def test_should_save_data_in_magic_columns_from_url
14
+ p = PhotoFile.create(:image_file_url => files(:web_photo))
15
+ assert_equal files(:web_photo), p.image_filename
16
+ assert_equal 110, p.image_height
17
+ assert_equal 276, p.image_width
18
+ assert_equal 'GIF', p.image_format
19
+ assert_equal 'gif', p.extension
20
+ rescue SocketError
21
+ print '!'
22
+ end
23
+
24
+ def test_should_delete_magic_columns_when_image_is_deleted
25
+ p = PhotoFile.new(:image_file => files(:photo))
26
+ p.save
27
+
28
+ p = PhotoFile.find(p.id)
29
+ p.delete_image_file.save
30
+
31
+ assert_nil p.image_width
32
+ assert_nil p.image_height
33
+ end
34
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+
4
+ class BigPhoto < ActiveRecord::Base
5
+ set_table_name :photo_dbs
6
+ acts_as_fleximage do
7
+ validates_image_size '80x60'
8
+ end
9
+ end
10
+
11
+ class WidePhoto < ActiveRecord::Base
12
+ set_table_name :photo_dbs
13
+ acts_as_fleximage do
14
+ validates_image_size '80x0'
15
+ end
16
+ end
17
+
18
+ class HighPhoto < ActiveRecord::Base
19
+ set_table_name :photo_dbs
20
+ acts_as_fleximage do
21
+ validates_image_size '0x60'
22
+ end
23
+ end
24
+
25
+ class MinimumImageSizeTest < Test::Unit::TestCase
26
+ def test_should_not_save_small_image
27
+ p = BigPhoto.new(:image_file => files(:i1x1))
28
+ assert !p.save
29
+ assert p.errors["image_file"].match(/is too small/)
30
+ end
31
+
32
+ def test_should_save_big_image
33
+ p = BigPhoto.new(:image_file => files(:i100x100))
34
+ assert p.save
35
+ end
36
+
37
+ def test_should_only_save_wide
38
+ p = WidePhoto.new(:image_file => files(:i1x100))
39
+ assert !p.save
40
+ p = WidePhoto.new(:image_file => files(:i100x1))
41
+ assert p.save
42
+ end
43
+
44
+ def test_should_only_save_high
45
+ p = HighPhoto.new(:image_file => files(:i100x1))
46
+ assert !p.save
47
+ p = HighPhoto.new(:image_file => files(:i1x100))
48
+ assert p.save
49
+ end
50
+
51
+ def test_should_include_minimum_dimensions_in_message
52
+ p = BigPhoto.new(:image_file => files(:i1x1))
53
+ p.save
54
+ assert_equal "is too small (Minimum: 80x60)", p.errors["image_file"]
55
+ end
56
+ end
@@ -0,0 +1,124 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageOperatorBaseTest < Test::Unit::TestCase
4
+ def setup
5
+ @photo = PhotoBare.create(:image_file => files(:photo))
6
+ proxy = Fleximage::ImageProxy.new(@photo.load_image, @photo)
7
+ @op = Fleximage::Operator::Base.new(proxy, @photo.load_image, @photo)
8
+
9
+ @other_img = Magick::Image.read(@photo.file_path).first
10
+ end
11
+
12
+ def test_should_raise_operation_not_implemented_exception
13
+ assert_raise(Fleximage::Operator::OperationNotImplemented) do
14
+ @photo.operate { |p| p.base }
15
+ end
16
+ end
17
+
18
+
19
+ # size_to_xy
20
+
21
+ def test_should_parse_size_string_to_x_and_y
22
+ assert_equal [1,2], @op.size_to_xy('1x2')
23
+ assert_equal [640,480], @op.size_to_xy('640x480')
24
+ end
25
+
26
+ def test_should_parse_size_array_to_x_and_y
27
+ assert_equal [1,2], @op.size_to_xy([1,2])
28
+ assert_equal [640,480], @op.size_to_xy([640,480])
29
+ end
30
+
31
+ def test_should_parse_single_size_array_to_square_x_and_y
32
+ assert_equal [2,2], @op.size_to_xy(2)
33
+ assert_equal [2,2], @op.size_to_xy('2')
34
+ assert_equal [480,480], @op.size_to_xy(480)
35
+ assert_equal [480,480], @op.size_to_xy('480')
36
+ end
37
+
38
+
39
+ # scale
40
+
41
+ def test_should_scale_the_main_image_and_keep_its_aspect_ratio
42
+ img = @op.scale(400)
43
+ assert_equal 400, img.rows
44
+ assert_equal 300, img.columns
45
+ assert_equal 400, @photo.load_image.rows
46
+ assert_equal 300, @photo.load_image.columns
47
+ end
48
+
49
+ def test_should_scale_a_different_image_and_keep_its_aspect_ratio
50
+ @op.scale(400, @other_img)
51
+ assert_equal 400, @other_img.rows
52
+ assert_equal 300, @other_img.columns
53
+ assert_equal 1024, @photo.load_image.rows
54
+ assert_equal 768, @photo.load_image.columns
55
+ end
56
+
57
+
58
+ # scale and crop
59
+
60
+ def test_should_scale_and_crop_the_main_image
61
+ img = @op.scale_and_crop(400)
62
+ assert_equal 400, img.rows
63
+ assert_equal 400, img.columns
64
+ assert_equal 400, @photo.load_image.rows
65
+ assert_equal 400, @photo.load_image.columns
66
+ end
67
+
68
+ def test_should_scale_and_crop_a_different_image
69
+ @op.scale_and_crop(400, @other_img)
70
+ assert_equal 400, @other_img.rows
71
+ assert_equal 400, @other_img.columns
72
+ assert_equal 1024, @photo.load_image.rows
73
+ assert_equal 768, @photo.load_image.columns
74
+ end
75
+
76
+
77
+ # stretch
78
+
79
+ def test_should_stretch_the_main_image
80
+ img = @op.stretch(400)
81
+ assert_equal 400, img.rows
82
+ assert_equal 400, img.columns
83
+ assert_equal 400, @photo.load_image.rows
84
+ assert_equal 400, @photo.load_image.columns
85
+ end
86
+
87
+ def test_should_stretch_a_different_image
88
+ @op.stretch(400, @other_img)
89
+ assert_equal 400, @other_img.rows
90
+ assert_equal 400, @other_img.columns
91
+ assert_equal 1024, @photo.load_image.rows
92
+ assert_equal 768, @photo.load_image.columns
93
+ end
94
+
95
+
96
+ def test_should_convert_symbol_to_rmagick_blending_mode
97
+ assert_equal Magick::MultiplyCompositeOp, @op.symbol_to_blending_mode(:multiply)
98
+ assert_equal Magick::OverCompositeOp, @op.symbol_to_blending_mode(:over)
99
+ assert_equal Magick::ScreenCompositeOp, @op.symbol_to_blending_mode(:screen)
100
+ assert_equal Magick::CopyBlackCompositeOp, @op.symbol_to_blending_mode(:copy_black)
101
+ end
102
+
103
+ def test_should_raise_argument_error_when_no_blend_mode_found
104
+ assert_raise(ArgumentError) do
105
+ @op.symbol_to_blending_mode(:foobar)
106
+ end
107
+ end
108
+
109
+
110
+ # gravity lookup
111
+
112
+ def test_should_lookup_correct_gravity
113
+ assert_equal Magick::CenterGravity, @op.symbol_to_gravity(:center)
114
+ assert_equal Magick::NorthGravity, @op.symbol_to_gravity(:top)
115
+ assert_equal Magick::SouthWestGravity, @op.symbol_to_gravity(:bottom_left)
116
+ end
117
+
118
+ def test_should_raise_error_with_a_bad_gravity
119
+ assert_raise(ArgumentError) do
120
+ @op.symbol_to_gravity(:foo)
121
+ end
122
+ end
123
+
124
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageOperatorResizeTest < Test::Unit::TestCase
4
+ def setup
5
+ @photo = PhotoBare.create(:image_file => files(:photo))
6
+ proxy = Fleximage::ImageProxy.new(@photo.load_image, @photo)
7
+ @op = Fleximage::Operator::Base.new(proxy, @photo.load_image, @photo)
8
+
9
+ @other_img = Magick::Image.read(@photo.file_path).first
10
+ end
11
+
12
+ def test_should_resize
13
+ @photo.operate { |p| p.resize '300x400' }
14
+ assert_equal 400, @photo.load_image.rows
15
+ assert_equal 300, @photo.load_image.columns
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximagePreprocessImageOptionTest < Test::Unit::TestCase
4
+ def test_should_resize_image_on_upload
5
+ PhotoDb.preprocess_image do |image|
6
+ image.resize '50x50', :crop => true
7
+ end
8
+
9
+ p = PhotoDb.new(:image_file => files(:photo))
10
+ assert p.save, 'Record expected to be allowed to save'
11
+
12
+ assert_equal 50, p.load_image.columns
13
+ assert_equal 50, p.load_image.rows
14
+
15
+ assert_equal 50, p.image_height
16
+ assert_equal 50, p.image_width
17
+
18
+ ensure
19
+ PhotoDb.preprocess_image_operation = nil
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class ValidatedPhoto < ActiveRecord::Base
4
+ set_table_name :photo_dbs
5
+ acts_as_fleximage
6
+
7
+ def validate
8
+ # overiding the validate method
9
+ end
10
+ end
11
+
12
+ class FleximageRequireImageOptionTest < Test::Unit::TestCase
13
+ def test_should_require_image_by_default
14
+ p = PhotoBare.new
15
+ assert !p.save, 'Record expected to not be allowed to save'
16
+ end
17
+
18
+ def test_should_disable_image_requirement
19
+ PhotoBare.require_image = false
20
+ p = PhotoBare.new
21
+ assert p.save, 'Record expected to be allowed to save'
22
+ ensure
23
+ PhotoBare.require_image = true
24
+ end
25
+
26
+ def test_should_require_image_when_validate_is_overriden
27
+ p = ValidatedPhoto.new
28
+ assert !p.save, 'Record expected to not be allowed to save'
29
+ end
30
+ end