Sha256: 34e7d13b924b014051fd4f4d2c26e04f0906e5ed7d49909f39a18f3b0b73f1c3

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

module ActiveMocker
  module Mock

    class HasOne

      attr_reader :item

      def initialize(item, child_self:, foreign_key:, foreign_id:)
        @item = item
        item.send(:write_attribute, foreign_key, foreign_id) if item.respond_to?("#{foreign_key}=") && !foreign_id.nil?
        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

1 entries across 1 versions & 1 rubygems

Version Path
active_mocker-1.7.beta1 lib/active_mocker/mock/has_one.rb