Class: MiniPaperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher
- Inherits:
-
Object
- Object
- MiniPaperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher
- Defined in:
- lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object (also: #negative_failure_message)
-
#initialize(attachment_name) ⇒ ValidateAttachmentPresenceMatcher
constructor
A new instance of ValidateAttachmentPresenceMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attachment_name) ⇒ ValidateAttachmentPresenceMatcher
Returns a new instance of ValidateAttachmentPresenceMatcher.
17 18 19 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb', line 17 def initialize() @attachment_name = .to_sym end |
Instance Method Details
#description ⇒ Object
46 47 48 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb', line 46 def description "require presence of attachment :#{@attachment_name}" end |
#failure_message ⇒ Object
37 38 39 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb', line 37 def "Attachment :#{@attachment_name} should be required" end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
41 42 43 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb', line 41 def "Attachment :#{@attachment_name} should not be required" end |
#matches?(subject) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |