class Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection
@private
Attributes
Public Class Methods
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 9 def initialize(reflection) super(reflection) @reflection = reflection @subject = reflection.active_record end
Calls superclass method
Public Instance Methods
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 15 def associated_class reflection.klass end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 54 def association_foreign_key if has_and_belongs_to_many_reflection join_model = has_and_belongs_to_many_reflection.options[:class] join_model.right_reflection.foreign_key else reflection.association_foreign_key end end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 33 def association_relation(related_instance) relation = associated_class.all if reflection.scope # Source: AR::Associations::AssociationScope#eval_scope relation.instance_exec(related_instance, &reflection.scope) else relation end end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 44 def foreign_key if has_and_belongs_to_many_reflection has_and_belongs_to_many_reflection.foreign_key elsif reflection.respond_to?(:foreign_key) reflection.foreign_key else reflection.primary_key_name end end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 69 def has_and_belongs_to_many_name reflection.options[:through] end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 27 def join_table_name join_table_name = has_and_belongs_to_many_name_table_name || reflection.join_table join_table_name.to_s end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 19 def polymorphic? reflection.options[:polymorphic] end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 23 def through? reflection.options[:through] end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 63 def validate_inverse_of_through_association! if through? reflection.check_validity! end end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 79 def has_and_belongs_to_many_name_table_name has_and_belongs_to_many_reflection&.table_name end
Source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 83 def has_and_belongs_to_many_reflection @_has_and_belongs_to_many_reflection ||= if has_and_belongs_to_many_name @subject.reflect_on_association(has_and_belongs_to_many_name) end end