Class: Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/have_attached_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(macro, name) ⇒ HaveAttachedMatcher

Returns a new instance of HaveAttachedMatcher.



58
59
60
61
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 58

def initialize(macro, name)
  @macro = macro
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



56
57
58
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 56

def name
  @name
end

Instance Method Details

#descriptionObject



63
64
65
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 63

def description
  "have a has_#{macro}_attached called #{name}"
end

#expectationObject



80
81
82
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 80

def expectation
  "#{model_class.name} to #{description}"
end

#failure_messageObject



67
68
69
70
71
72
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 67

def failure_message
  "Expected \#{expectation}, but this could not be proved.\n  \#{@failure}\n  MESSAGE\nend\n"

#failure_message_when_negatedObject



74
75
76
77
78
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 74

def failure_message_when_negated
  "Did not expect \#{expectation}, but it does.\n  MESSAGE\nend\n"

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 84

def matches?(subject)
  @subject = subject
  reader_attribute_exists? &&
    writer_attribute_exists? &&
    attachments_association_exists? &&
    blobs_association_exists? &&
    eager_loading_scope_exists?
end