# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 15 def initialize attachment_name @attachment_name = attachment_name end
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 33 def description "require presence of attachment #{@attachment_name}" end
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 25 def failure_message "Attachment #{@attachment_name} should be required" end
# 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
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 29 def negative_failure_message "Attachment #{@attachment_name} should not be required" end
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 39 def error_when_not_valid? @subject.send(@attachment_name).assign(nil) @subject.valid? @subject.errors[:"#{@attachment_name}"].present? end
# File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 45 def no_error_when_valid? @file = StringIO.new(".") @subject.send(@attachment_name).assign(@file) @subject.valid? @subject.errors[:"#{@attachment_name}"].blank? end