Sha256: 615700aff70691d7472b8b4169744c2a988032cade415f51714cfe34739429b4

Contents?: true

Size: 1.41 KB

Versions: 24

Compression:

Stored size: 1.41 KB

Contents

require './test/helper'

class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
  context "validate_attachment_content_type" do
    setup do
      reset_table("dummies") do |d|
        d.string :title
        d.string :avatar_file_name
        d.string :avatar_content_type
      end
      @dummy_class = reset_class "Dummy"
      @dummy_class.has_attached_file :avatar
      @matcher     = self.class.validate_attachment_content_type(:avatar).
                       allowing(%w(image/png image/jpeg)).
                       rejecting(%w(audio/mp3 application/octet-stream))
    end

    context "given a class with no validation" do
      should_reject_dummy_class
    end

    context "given a class with a validation that doesn't match" do
      setup do
        @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
      end

      should_reject_dummy_class
    end

    context "given a class with a matching validation" do
      setup do
        @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
      end

      should_accept_dummy_class
    end
    
    context "given a class with other validations but matching types" do
      setup do
        @dummy_class.validates_presence_of :title
        @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
      end
      
      should_accept_dummy_class
    end
  end
end

Version data entries

24 entries across 24 versions & 11 rubygems

Version Path
paperclip-2.3.7 test/matchers/validate_attachment_content_type_matcher_test.rb
twm_paperclip-2.3.6b test/matchers/validate_attachment_content_type_matcher_test.rb
twm_paperclip-2.3.6 test/matchers/validate_attachment_content_type_matcher_test.rb
paperclip-2.3.6 test/matchers/validate_attachment_content_type_matcher_test.rb