Exception: MR::Factory::NoRecordClassError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/mr/factory.rb

Overview

used by factories and stacks to say they can’t determine a record class for an association (usually a polymorphic association doesn’t have its foreign type attribute set)

Class Method Summary collapse

Class Method Details

.for_association(ar_association) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mr/factory.rb', line 60

def self.for_association(ar_association)
  owner_record_class = ar_association.owner.class
  association_name   = ar_association.reflection.name
  message = "can't build '#{association_name}' association on " \
            "#{owner_record_class}"
  if ar_association.reflection.options[:polymorphic]
    foreign_type_attribute = ar_association.reflection.foreign_type
    message += " -- try manually setting it, building it via a stack " \
               "if you've configured default associations, or setting " \
               "its '#{foreign_type_attribute}' attribute"
  else
    message += " -- try manually setting it or building it via a stack " \
               "if you've configured default associations"
  end
  self.new(message)
end