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.



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

def initialize attachment_name
  @attachment_name = 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

#descriptionObject



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_messageObject



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

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)


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_messageObject



44
45
46
47
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 44

def negative_failure_message
  "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