Sha256: 69aab9d83c6ab71abe09a3e43a343a8ff9aaa9368c1c504e88ed94c39146b5cb

Contents?: true

Size: 1.3 KB

Versions: 13

Compression:

Stored size: 1.3 KB

Contents

require File.dirname(__FILE__) + '/../../test/test_helper'

class FleximageFileUploadToDbTest < Test::Unit::TestCase
  def test_should_be_valid_with_image
    p = PhotoDb.new(:image_file => files(:photo))
    assert p.save, 'Record expected to be allowed to save'
    
    p = PhotoDb.find(p.id)
    assert_kind_of Magick::Image, p.load_image
    assert p.image_file_data.size > 0
  end
  
  def test_should_require_an_image
    p = PhotoDb.new
    assert !p.save, 'Record expected to not be allowed to save'
    assert_equal 1, p.errors.size
    assert_equal 'is required', p.errors.on(:image_file)
  end
  
  def test_should_require_an_valid_image
    p = PhotoDb.new(:image_file => files(:not_a_photo))
    assert !p.save, 'Record expected to not be allowed to save'
    assert_equal 1, p.errors.size
    assert_equal 'was not a readable image', p.errors.on(:image_file)
  end
  
  def test_should_retrieve_a_stored_image
    id = PhotoDb.create(:image_file => files(:photo)).id
    p = PhotoDb.find(id)
    assert_kind_of Magick::Image, p.load_image
    assert_equal 768,  p.load_image.columns
    assert_equal 1024, p.load_image.rows
  end
  
  def test_should_delete_an_image
    id = PhotoDb.create(:image_file => files(:photo)).id
    photo = PhotoDb.find(id)
    photo.destroy
    assert_nil PhotoDb.find_by_id(id)
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
tvdeyen-fleximage-1.1.1 test/unit/file_upload_to_db_test.rb
tvdeyen-fleximage-1.0.9 test/unit/file_upload_to_db_test.rb
tvdeyen-fleximage-1.0.8 test/unit/file_upload_to_db_test.rb
tvdeyen-fleximage-1.0.7 test/unit/file_upload_to_db_test.rb
robinboening-fleximage-1.0.6 test/unit/file_upload_to_db_test.rb
robinboening-fleximage-1.0.4 test/unit/file_upload_to_db_test.rb
tvdeyen-fleximage-1.0.5 test/unit/file_upload_to_db_test.rb
fleximage-1.0.4 test/unit/file_upload_to_db_test.rb
dougmcbride-fleximage-1.0.3 test/unit/file_upload_to_db_test.rb
fleximage-1.0.3 test/unit/file_upload_to_db_test.rb
fleximage-1.0.2 test/unit/file_upload_to_db_test.rb
fleximage-1.0.1 test/unit/file_upload_to_db_test.rb
fleximage-1.0.0 test/unit/file_upload_to_db_test.rb