Class: Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(attachment_name) ⇒ ValidateAttachmentPresenceMatcher

Returns a new instance of ValidateAttachmentPresenceMatcher.



17
18
19
# File 'lib/paperclip/matchers/validate_attachment_presence_matcher.rb', line 17

def initialize(attachment_name)
  @attachment_name = attachment_name
end

Instance Method Details

#descriptionObject



36
37
38
# File 'lib/paperclip/matchers/validate_attachment_presence_matcher.rb', line 36

def description
  "require presence of attachment #{@attachment_name}"
end

#failure_messageObject



27
28
29
# File 'lib/paperclip/matchers/validate_attachment_presence_matcher.rb', line 27

def failure_message
  "Attachment #{@attachment_name} should be required"
end

#failure_message_when_negatedObject Also known as: negative_failure_message



31
32
33
# File 'lib/paperclip/matchers/validate_attachment_presence_matcher.rb', line 31

def failure_message_when_negated
  "Attachment #{@attachment_name} should not be required"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/paperclip/matchers/validate_attachment_presence_matcher.rb', line 21

def matches?(subject)
  @subject = subject
  @subject = subject.new if subject.class == Class
  error_when_not_valid? && no_error_when_valid?
end