Class: WhyValidationsSuckIn96::ValidatesAssociated

Inherits:
WhyValidationsSuckIn96::Validation show all
Includes:
WhyValidationsSuckIn96::AttributeBasedValidation, WhyValidationsSuckIn96::SkippableValidation
Defined in:
lib/whyvalidationssuckin96/macros/validates_associated.rb

Overview

Checks the validity of any associated objects, such as an ActiveRecord association.

Examples:

Checking the validity of an associated collection of tracks

  setup_validations do
    validates_associated :tracks
  end

Checking the validity of an associated artist

  setup_validations do
    validates_associated :artist
  end

Constant Summary

DefaultOptions =
{:message => "is invalid"}

Constants inherited from WhyValidationsSuckIn96::Validation

DefaultOptions

Instance Method Summary

Methods included from WhyValidationsSuckIn96::AttributeBasedValidation

#attribute, #attribute_value, #initialize

Methods inherited from WhyValidationsSuckIn96::Validation

#failed?, #has_run?, #initialize, #message, new_subclass, #passed?, #validates?

Constructor Details

This class inherits a constructor from WhyValidationsSuckIn96::AttributeBasedValidation

Instance Method Details

- (Object) validate



23
24
25
26
27
28
# File 'lib/whyvalidationssuckin96/macros/validates_associated.rb', line 23

def validate
  super
  Array(attribute_value).collect do |assoc|
    assoc.valid?
  end.all? ? pass : fail
end