Class: Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::HaveAttachedMatcher
- Defined in:
- lib/shoulda/matchers/active_record/have_attached_matcher.rb
Constant Summary collapse
- OPTION_METHODS =
{ service: -> (value) { value }, strict_loading: -> (value = true) { value }, dependent: -> (value) { value }, }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #description ⇒ Object
- #expectation ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #failure_reason ⇒ Object
-
#initialize(macro, name) ⇒ HaveAttachedMatcher
constructor
A new instance of HaveAttachedMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(macro, name) ⇒ HaveAttachedMatcher
Returns a new instance of HaveAttachedMatcher.
147 148 149 150 151 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 147 def initialize(macro, name) @macro = macro @name = name @options = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
145 146 147 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 145 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
145 146 147 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 145 def @options end |
Instance Method Details
#description ⇒ Object
153 154 155 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 153 def description "have a has_#{macro}_attached called #{name}" end |
#expectation ⇒ Object
174 175 176 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 174 def expectation "#{model_class.name} to #{description}" + build_expectation_suffix end |
#failure_message ⇒ Object
157 158 159 160 161 162 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 157 def <<-MESSAGE Expected #{expectation}, but this could not be proved. #{@failure} MESSAGE end |
#failure_message_when_negated ⇒ Object
168 169 170 171 172 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 168 def <<-MESSAGE Did not expect #{expectation}, but it does. MESSAGE end |
#failure_reason ⇒ Object
164 165 166 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 164 def failure_reason @failure end |
#matches?(subject) ⇒ Boolean
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/shoulda/matchers/active_record/have_attached_matcher.rb', line 178 def matches?(subject) @subject = subject reader_attribute_exists? && writer_attribute_exists? && && blobs_association_exists? && eager_loading_scope_exists? && service_correct? && dependent_option_correct? end |