Sha256: 9514c7c5df4618e9095c91ce7c27e97e060b2d5d5ec1c3c989cf50022c97f1e1

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require './test/helper'

class ValidatorsTest < Test::Unit::TestCase
  def setup
    rebuild_model
  end

  context "using the helper" do
    setup do
      Dummy.validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/jpeg" }, :size => { :in => 0..10.kilobytes }
    end

    should "add the attachment_presence validator to the class" do
      assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
    end

    should "add the attachment_content_type validator to the class" do
      assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type }
    end

    should "add the attachment_size validator to the class" do
      assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
    end

    should 'prevent you from attaching a file that violates that validation' do
      Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
      dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
      assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
      assert_raise(RuntimeError){ dummy.valid? }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paperclip-3.5.2 test/validators_test.rb
paperclip-3.5.1 test/validators_test.rb
paperclip-3.5.0 test/validators_test.rb