Class | Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher
In: | vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
Parent: | Object

### Methods

allow_types? allowed_types_allowed? allowing description failure_message matches? negative_failure_message new rejected_types_rejected? rejecting

### Public Class methods

new(attachment_name)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 9
     9:         def initialize attachment_name
    10:           @attachment_name = attachment_name
    11:         end

### Public Instance methods

allowing(*types)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 13
    13:         def allowing *types
    14:           @allowed_types = types.flatten
    15:           self
    16:         end

description()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 39
    39:         def description
    40:           "validate the content types allowed on attachment #{@attachment_name}"
    41:         end

failure_message()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 29
    29:         def failure_message
    30:           "Content types #{@allowed_types.join(", ")} should be accepted" +
    31:           " and #{@rejected_types.join(", ")} rejected by #{@attachment_name}"
    32:         end

matches?(subject)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 23
    23:         def matches? subject
    24:           @subject = subject
    25:           @allowed_types && @rejected_types &&
    26:           allowed_types_allowed? && rejected_types_rejected?
    27:         end

negative_failure_message()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 34
    34:         def negative_failure_message
    35:           "Content types #{@allowed_types.join(", ")} should be rejected" +
    36:           " and #{@rejected_types.join(", ")} accepted by #{@attachment_name}"
    37:         end

rejecting(*types)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 18
    18:         def rejecting *types
    19:           @rejected_types = types.flatten
    20:           self
    21:         end

### Protected Instance methods

allow_types?(types)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 45
    45:         def allow_types?(types)
    46:           types.all? do |type|
    47:             file = StringIO.new(".")
    48:             file.content_type = type
    49:             attachment = @subject.new.attachment_for(@attachment_name)
    50:             attachment.assign(file)
    51:             attachment.errors[:content_type].nil?
    52:           end
    53:         end

allowed_types_allowed?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 55
    55:         def allowed_types_allowed?
    56:           allow_types?(@allowed_types)
    57:         end

rejected_types_rejected?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 59
    59:         def rejected_types_rejected?
    60:           not allow_types?(@rejected_types)
    61:         end

[Validate]