Class Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher
In: lib/paperclip/matchers/validate_attachment_presence_matcher.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 15
15:         def initialize attachment_name
16:           @attachment_name = attachment_name
17:         end

Public Instance methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 33
33:         def description
34:           "require presence of attachment #{@attachment_name}"
35:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 25
25:         def failure_message
26:           "Attachment #{@attachment_name} should be required"
27:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 19
19:         def matches? subject
20:           @subject = subject
21:           @subject = @subject.class unless Class === @subject
22:           error_when_not_valid? && no_error_when_valid?
23:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 29
29:         def negative_failure_message
30:           "Attachment #{@attachment_name} should not be required"
31:         end

Protected Instance methods

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 39
39:         def error_when_not_valid?
40:           (subject = @subject.new).send(@attachment_name).assign(nil)
41:           subject.valid?
42:           not subject.errors["#{@attachment_name}_file_name""#{@attachment_name}_file_name"].blank?
43:         end

[Source]

    # File lib/paperclip/matchers/validate_attachment_presence_matcher.rb, line 45
45:         def no_error_when_valid?
46:           @file = StringIO.new(".")
47:           (subject = @subject.new).send(@attachment_name).assign(@file)
48:           subject.valid?
49:           subject.errors["#{@attachment_name}_file_name""#{@attachment_name}_file_name"].blank?
50:         end

[Validate]