Sha256: 2a56bcce60a6a9983e928561a1e042015b2b39c5405f78377f3d867c71cd7ac1

Contents?: true

Size: 1.82 KB

Versions: 10

Compression:

Stored size: 1.82 KB

Contents

require 'test_helper'

class ImageTest < ActiveSupport::TestCase

  setup do
    @valid = File.open("#{Rails.root}/test/fixtures/images/image.png")
    @small = File.open("#{Rails.root}/test/fixtures/images/small.png")
    @large = File.open("#{Rails.root}/test/fixtures/images/large.png")
    @invalid = File.open("#{Rails.root}/test/fixtures/images/invalid.png")
    @undefined = File.open("#{Rails.root}/test/fixtures/images/undefined.zip")
  end

  teardown do
    @valid.close
    @small.close
    @large.close
    @invalid.close
    @undefined.close
  end

  test "valid file assignment" do
    @image = Image.create(:file => @valid)
    assert @image.valid?, "valid file assignment failed"
    assert @image.file?, "should have a file"
  end

  test "inavlid file assignment" do
    @image = Image.create(:file => @invalid)
    assert !@image.valid?, "invalid file assignment succeeded"
    assert @image.errors[:file].include? "must be an image file"
  end

  test "undefined file assignment" do
    @image = Image.create(:file => @undefined)
    assert !@image.valid?, "undefined file assignment succeeded"
    assert @image.errors[:file].include? "extension is invalid"
  end

  test "too large file assignment" do
    @image = Image.create(:file => @large)
    assert !@image.valid?, "invalid file assignment succeeded"
    assert @image.errors[:file].include? "size must be between 2 kilobytes and 2 megabytes"
  end

  test "too small file assignment" do
    @image = Image.create(:file => @small)
    assert !@image.valid?, "invalid file assignment succeeded"
    assert @image.errors[:file].include? "size must be between 2 kilobytes and 2 megabytes"
  end

  test "no file assignment" do
    @image = Image.create()
    assert !@image.valid?, "invalid file assignment succeeded"
    assert @image.errors[:file].include? "must be attached"
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
attached-1.0.4 test/dummy/test/models/image_test.rb
attached-1.0.3 test/dummy/test/models/image_test.rb
attached-1.0.2 test/dummy/test/models/image_test.rb
attached-1.0.1 test/dummy/test/models/image_test.rb
attached-1.0.0 test/dummy/test/unit/image_test.rb
attached-0.6.0 test/dummy/test/unit/image_test.rb
attached-0.5.9 test/dummy/test/unit/image_test.rb
attached-0.5.8 test/dummy/test/unit/image_test.rb
attached-0.5.7 test/dummy/test/unit/image_test.rb
attached-0.5.6 test/dummy/test/unit/image_test.rb