Class: Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher
- Inherits:
-
Object
- Object
- Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher
- Defined in:
- lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
Instance Method Summary collapse
- #allowing(*types) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attachment_name) ⇒ ValidateAttachmentContentTypeMatcher
constructor
A new instance of ValidateAttachmentContentTypeMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #rejecting(*types) ⇒ Object
Constructor Details
#initialize(attachment_name) ⇒ ValidateAttachmentContentTypeMatcher
Returns a new instance of ValidateAttachmentContentTypeMatcher.
18 19 20 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 18 def initialize @attachment_name = end |
Instance Method Details
#allowing(*types) ⇒ Object
22 23 24 25 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 22 def allowing *types @allowed_types = types.flatten self end |
#description ⇒ Object
49 50 51 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 49 def description "validate the content types allowed on attachment #{@attachment_name}" end |
#failure_message ⇒ Object
39 40 41 42 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 39 def "Content types #{@allowed_types.join(", ")} should be accepted" + " and #{@rejected_types.join(", ")} rejected by #{@attachment_name}" end |
#matches?(subject) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 32 def matches? subject @subject = subject @subject = @subject.class unless Class === @subject @allowed_types && @rejected_types && allowed_types_allowed? && rejected_types_rejected? end |
#negative_failure_message ⇒ Object
44 45 46 47 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 44 def "Content types #{@allowed_types.join(", ")} should be rejected" + " and #{@rejected_types.join(", ")} accepted by #{@attachment_name}" end |
#rejecting(*types) ⇒ Object
27 28 29 30 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 27 def rejecting *types @rejected_types = types.flatten self end |