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

Methods

Public Class methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 18
18:         def initialize attachment_name
19:           @attachment_name = attachment_name
20:         end

Public Instance methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 22
22:         def allowing *types
23:           @allowed_types = types.flatten
24:           self
25:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 49
49:         def description
50:           "validate the content types allowed on attachment #{@attachment_name}"
51:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 39
39:         def failure_message
40:           "Content types #{@allowed_types.join(", ")} should be accepted" +
41:           " and #{@rejected_types.join(", ")} rejected by #{@attachment_name}"
42:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 32
32:         def matches? subject
33:           @subject = subject
34:           @subject = @subject.class unless Class === @subject
35:           @allowed_types && @rejected_types &&
36:           allowed_types_allowed? && rejected_types_rejected?
37:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 44
44:         def negative_failure_message
45:           "Content types #{@allowed_types.join(", ")} should be rejected" +
46:           " and #{@rejected_types.join(", ")} accepted by #{@attachment_name}"
47:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 27
27:         def rejecting *types
28:           @rejected_types = types.flatten
29:           self
30:         end

Protected Instance methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 55
55:         def allow_types?(types)
56:           types.all? do |type|
57:             file = StringIO.new(".")
58:             file.content_type = type
59:             (subject = @subject.new).attachment_for(@attachment_name).assign(file)
60:             subject.valid?
61:             subject.errors["#{@attachment_name}_content_type""#{@attachment_name}_content_type"].blank?
62:           end
63:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 65
65:         def allowed_types_allowed?
66:           allow_types?(@allowed_types)
67:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_content_type_matcher.rb, line 69
69:         def rejected_types_rejected?
70:           not allow_types?(@rejected_types)
71:         end

[Validate]