Sha256: bd503977026c55536110cc3419bfba1a80a3f491f9e1753e4ecffb4e3c9dddf7

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

module ActiveMocker
  module Mock

    class SingleRelation

      attr_reader :item

      def initialize(item, child_self:, foreign_key:, foreign_id:)
        @item = item
        assign_associations(child_self, item)
      end

      def assign_associations(child_self, item)
        has_many = child_self.class.send('mocked_class').tableize
        has_one = child_self.class.send('mocked_class').tableize.singularize
        item.send(has_many) << child_self if item.respond_to?("#{has_many}=") && !item.send(has_many).include?(child_self)
        item.send(:write_association, has_one, child_self) if item.respond_to?("#{has_one}=")
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_mocker-1.7.beta3 lib/active_mocker/mock/single_relation.rb
active_mocker-1.7.beta2 lib/active_mocker/mock/single_relation.rb