Class: Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/matchers/validate_attachment_content_type_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attachment_name) ⇒ ValidateAttachmentContentTypeMatcher

Returns a new instance of ValidateAttachmentContentTypeMatcher.



9
10
11
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 9

def initialize attachment_name
  @attachment_name = attachment_name
end

Instance Method Details

#allowing(*types) ⇒ Object



13
14
15
16
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 13

def allowing *types
  @allowed_types = types.flatten
  self
end

#descriptionObject



39
40
41
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 39

def description
  "validate the content types allowed on attachment #{@attachment_name}"
end

#failure_messageObject



29
30
31
32
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 29

def failure_message
  "Content types #{@allowed_types.join(", ")} should be accepted" +
  " and #{@rejected_types.join(", ")} rejected by #{@attachment_name}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 23

def matches? subject
  @subject = subject
  @allowed_types && @rejected_types &&
  allowed_types_allowed? && rejected_types_rejected?
end

#negative_failure_messageObject



34
35
36
37
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 34

def negative_failure_message
  "Content types #{@allowed_types.join(", ")} should be rejected" + 
  " and #{@rejected_types.join(", ")} accepted by #{@attachment_name}"
end

#rejecting(*types) ⇒ Object



18
19
20
21
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 18

def rejecting *types
  @rejected_types = types.flatten
  self
end