Sha256: bcd69b13cd69d2569a0ef9ce283f85c5ae81c7d928ee545b9c572459933fb3fd
Contents?: true
Size: 654 Bytes
Versions: 1
Compression:
Stored size: 654 Bytes
Contents
module ActiveMocker module Mock class BelongsTo attr_reader :item def initialize(item, child_self:, foreign_key:, foreign_id:) @item = item child_self.send(:write_attribute, foreign_key, foreign_id) if item.try(:persisted?) 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/belongs_to.rb |