class ActiveMocker::SingleRelation

Attributes

item[R]

Public Class Methods

new(item, child_self:, foreign_key:) click to toggle source
# File lib/active_mocker/mock/single_relation.rb, line 6
def initialize(item, child_self:, foreign_key:)
  @item = item
  assign_associations(child_self, item) if item.class <= Base
end

Public Instance Methods

assign_associations(child_self, item) click to toggle source
# File lib/active_mocker/mock/single_relation.rb, line 11
def assign_associations(child_self, item)
  [*item.class._find_associations_by_class(child_self.class.send("mocked_class"))].each do |_type, relations|
    relations.each do |relation|
      if item.send(relation).class <= Collection
        item.send(relation) << child_self
      else
        item.send(:write_association, relation, child_self)
      end
    end
  end
end