class MiniPaperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher

Public Class Methods

new(attachment_name) click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb, line 17
def initialize(attachment_name)
  @attachment_name = attachment_name.to_sym
end

Public Instance Methods

description() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb, line 46
def description
  "require presence of attachment :#{@attachment_name}"
end
failure_message() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb, line 37
def failure_message
  "Attachment :#{@attachment_name} should be required"
end
failure_message_when_negated() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb, line 41
def failure_message_when_negated
  "Attachment :#{@attachment_name} should not be required"
end
Also aliased as: negative_failure_message
matches?(subject) click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb, line 21
def matches?(subject)
  @subject = subject.class == Class ? subject.new : subject

  begin
    @subject.write_attribute("#{@attachment_name}_file_name", 'hello.png')
    @subject.write_attribute("#{@attachment_name}_updated_at", Time.now)
    @subject.valid?
    @subject.errors[@attachment_name].empty?
  end && begin
    @subject.write_attribute("#{@attachment_name}_file_name", nil)
    @subject.write_attribute("#{@attachment_name}_updated_at", Time.now)
    @subject.valid?
    @subject.errors[@attachment_name].present?
  end
end
negative_failure_message()