Class: RmagickTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- RmagickTest
- Defined in:
- lib/test/processors/rmagick_test.rb
Instance Method Summary collapse
- #test_flunk ⇒ Object
- #test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachment) ⇒ Object
- #test_should_create_image_from_uploaded_file ⇒ Object
- #test_should_create_image_from_uploaded_file_with_custom_content_type ⇒ Object
- #test_should_create_thumbnail ⇒ Object
- #test_should_create_thumbnail_with_geometry_string ⇒ Object
- #test_should_delete_file_when_in_file_system_when_attachment_record_destroyed(klass = ImageWithThumbsFileAttachment) ⇒ Object
- #test_should_give_correct_thumbnail_filenames(klass = ImageWithThumbsFileAttachment) ⇒ Object
- #test_should_overwrite_old_thumbnail_records_when_renaming(klass = ImageWithThumbsAttachment) ⇒ Object
- #test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithThumbsAttachment) ⇒ Object
- #test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbsFileAttachment) ⇒ Object
- #test_should_resize_image(klass = ImageAttachment) ⇒ Object
- #test_should_resize_image_with_geometry(klass = ImageOrPdfAttachment) ⇒ Object
- #test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachment) ⇒ Object
Instance Method Details
#test_flunk ⇒ Object
237 238 239 |
# File 'lib/test/processors/rmagick_test.rb', line 237 def test_flunk puts "RMagick not installed, no tests running" end |
#test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachment) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/test/processors/rmagick_test.rb', line 116 def test_should_automatically_create_thumbnails(klass = ImageWithThumbsAttachment) klass assert_created 3 do = upload_file :filename => '/files/rails.png' assert_valid assert !.size.zero? #assert_equal 1784, attachment.size assert_equal 55, .width assert_equal 55, .height assert_equal 2, .thumbnails.length assert_equal 1.0, .aspect_ratio thumb = .thumbnails.detect { |t| t.filename =~ /_thumb/ } assert !thumb.new_record?, thumb.errors..join("\n") assert !thumb.size.zero? #assert_in_delta 4673, thumb.size, 2 assert_equal 50, thumb.width assert_equal 50, thumb.height assert_equal 1.0, thumb.aspect_ratio geo = .thumbnails.detect { |t| t.filename =~ /_geometry/ } assert !geo.new_record?, geo.errors..join("\n") assert !geo.size.zero? #assert_equal 3915, geo.size assert_equal 50, geo.width assert_equal 50, geo.height assert_equal 1.0, geo.aspect_ratio end end |
#test_should_create_image_from_uploaded_file ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/test/processors/rmagick_test.rb', line 7 def test_should_create_image_from_uploaded_file assert_created do = upload_file :filename => '/files/rails.png' assert_valid assert !.db_file.new_record? if .respond_to?(:db_file) assert .image? assert !.size.zero? #assert_equal 1784, attachment.size assert_equal 50, .width assert_equal 64, .height assert_equal '50x64', .image_size end end |
#test_should_create_image_from_uploaded_file_with_custom_content_type ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/test/processors/rmagick_test.rb', line 21 def test_should_create_image_from_uploaded_file_with_custom_content_type assert_created do = upload_file :content_type => 'foo/bar', :filename => '/files/rails.png' assert_valid assert !.image? assert !.db_file.new_record? if .respond_to?(:db_file) assert !.size.zero? #assert_equal 1784, attachment.size assert_nil .width assert_nil .height assert_equal [], .thumbnails end end |
#test_should_create_thumbnail ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/test/processors/rmagick_test.rb', line 35 def test_should_create_thumbnail = upload_file :filename => '/files/rails.png' assert_created do basename, ext = .filename.split '.' thumbnail = .create_or_update_thumbnail(.create_temp_file, 'thumb', 50, 50) assert_valid thumbnail assert !thumbnail.size.zero? #assert_in_delta 4673, thumbnail.size, 2 assert_equal 50, thumbnail.width assert_equal 50, thumbnail.height assert_equal [thumbnail.id], .thumbnails.collect(&:id) assert_equal .id, thumbnail.parent_id if thumbnail.respond_to?(:parent_id) assert_equal "#{basename}_thumb.#{ext}", thumbnail.filename end end |
#test_should_create_thumbnail_with_geometry_string ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/test/processors/rmagick_test.rb', line 52 def test_should_create_thumbnail_with_geometry_string = upload_file :filename => '/files/rails.png' assert_created do basename, ext = .filename.split '.' thumbnail = .create_or_update_thumbnail(.create_temp_file, 'thumb', 'x50') assert_valid thumbnail assert !thumbnail.size.zero? #assert_equal 3915, thumbnail.size assert_equal 39, thumbnail.width assert_equal 50, thumbnail.height assert_equal [thumbnail], .thumbnails assert_equal .id, thumbnail.parent_id if thumbnail.respond_to?(:parent_id) assert_equal "#{basename}_thumb.#{ext}", thumbnail.filename end end |
#test_should_delete_file_when_in_file_system_when_attachment_record_destroyed(klass = ImageWithThumbsFileAttachment) ⇒ Object
193 194 195 196 197 198 199 200 |
# File 'lib/test/processors/rmagick_test.rb', line 193 def (klass = ImageWithThumbsFileAttachment) klass = upload_file :filename => '/files/rails.png' filenames = [.full_filename] + .thumbnails.collect(&:full_filename) filenames.each { |f| assert File.exists?(f), "#{f} never existed to delete on destroy" } .destroy filenames.each { |f| assert !File.exists?(f), "#{f} still exists" } end |
#test_should_give_correct_thumbnail_filenames(klass = ImageWithThumbsFileAttachment) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/test/processors/rmagick_test.rb', line 99 def test_should_give_correct_thumbnail_filenames(klass = ImageWithThumbsFileAttachment) klass assert_created 3 do = upload_file :filename => '/files/rails.png' thumb = .thumbnails.detect { |t| t.filename =~ /_thumb/ } geo = .thumbnails.detect { |t| t.filename =~ /_geometry/ } [, thumb, geo].each { |record| assert_valid record } assert_match /rails\.png$/, .full_filename assert_match /rails_geometry\.png$/, .full_filename(:geometry) assert_match /rails_thumb\.png$/, .full_filename(:thumb) end end |
#test_should_overwrite_old_thumbnail_records_when_renaming(klass = ImageWithThumbsAttachment) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/test/processors/rmagick_test.rb', line 221 def test_should_overwrite_old_thumbnail_records_when_renaming(klass = ImageWithThumbsAttachment) klass = nil assert_created 3 do = upload_file :class => klass, :filename => '/files/rails.png' end assert_not_created do # no new db_file records .filename = 'rails2.png' .save assert !.reload.size.zero? assert_equal 'rails2.png', .filename end end |
#test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithThumbsAttachment) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/test/processors/rmagick_test.rb', line 204 def test_should_overwrite_old_thumbnail_records_when_updating(klass = ImageWithThumbsAttachment) klass = nil assert_created 3 do = upload_file :filename => '/files/rails.png' end assert_not_created do # no new db_file records use_temp_file "files/rails.png" do |file| .filename = 'rails2.png' .temp_path = File.join(fixture_path, file) .save! end end end |
#test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbsFileAttachment) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/test/processors/rmagick_test.rb', line 170 def test_should_remove_old_thumbnail_files_when_updating(klass = ImageWithThumbsFileAttachment) klass = nil assert_created 3 do = upload_file :filename => '/files/rails.png' end old_filenames = [.full_filename] + .thumbnails.collect(&:full_filename) assert_not_created do use_temp_file "files/rails.png" do |file| .filename = 'rails2.png' .temp_path = File.join(fixture_path, file) .save new_filenames = [.reload.full_filename] + .thumbnails.collect { |t| t.reload.full_filename } new_filenames.each { |f| assert File.exists?(f), "#{f} does not exist" } old_filenames.each { |f| assert !File.exists?(f), "#{f} still exists" } end end end |
#test_should_resize_image(klass = ImageAttachment) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/test/processors/rmagick_test.rb', line 69 def test_should_resize_image(klass = ImageAttachment) klass assert_equal [50, 50], .[:resize_to] = upload_file :filename => '/files/rails.png' assert_valid assert !.db_file.new_record? if .respond_to?(:db_file) assert .image? assert !.size.zero? #assert_in_delta 4673, attachment.size, 2 assert_equal 50, .width assert_equal 50, .height end |
#test_should_resize_image_with_geometry(klass = ImageOrPdfAttachment) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/test/processors/rmagick_test.rb', line 84 def test_should_resize_image_with_geometry(klass = ImageOrPdfAttachment) klass assert_equal 'x50', .[:resize_to] = upload_file :filename => '/files/rails.png' assert_valid assert !.db_file.new_record? if .respond_to?(:db_file) assert .image? assert !.size.zero? #assert_equal 3915, attachment.size assert_equal 39, .width assert_equal 50, .height end |
#test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachment) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/test/processors/rmagick_test.rb', line 152 def test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachment) klass = nil assert_difference ImageThumbnail, :count do = upload_file :filename => '/files/rails.png' assert_valid end assert_kind_of ImageThumbnail, .thumbnails.first assert_equal .id, .thumbnails.first.parent.id assert_kind_of FileAttachment, .thumbnails.first.parent assert_equal 'rails_thumb.png', .thumbnails.first.filename assert_equal .thumbnails.first.full_filename, .full_filename(.thumbnails.first.thumbnail), "#full_filename does not use thumbnail class' path." assert_equal .destroy end |