class Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher
Public Class Methods
new(attachment_name)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 15 def initialize(attachment_name) @attachment_name = attachment_name end
Public Instance Methods
description()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 34 def description "require presence of attachment #{@attachment_name}" end
failure_message()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 25 def failure_message "Attachment #{@attachment_name} should be required" end
failure_message_when_negated()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 29 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/paperclip/matchers/validate_attachment_presence_matcher.rb, line 19 def matches?(subject) @subject = subject @subject = subject.new if subject.class == Class error_when_not_valid? && no_error_when_valid? end
Protected Instance Methods
error_when_not_valid?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 40 def error_when_not_valid? @subject.send(@attachment_name).assign(nil) @subject.valid? @subject.errors[:"#{@attachment_name}"].present? end
no_error_when_valid?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 46 def no_error_when_valid? @file = StringIO.new(".") @subject.send(@attachment_name).assign(@file) @subject.valid? expected_message = [ @attachment_name.to_s.titleize, I18n.t(:blank, scope: [:errors, :messages]) ].join(" ") @subject.errors.full_messages.exclude?(expected_message) end