Sha256: e724359cf636a64b9ed5c6404082580018ece66f2e949e95d258566742975fb4

Contents?: true

Size: 1.41 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
paperclip-2.3.5 test/matchers/validate_attachment_content_type_matcher_test.rb
paperclip-2.3.4 test/matchers/validate_attachment_content_type_matcher_test.rb