Sha256: fc71a8ce8ff11f409c911fa73bfa28f944d600ca71cec2549a065d2ec1401043

Contents?: true

Size: 671 Bytes

Versions: 31

Compression:

Stored size: 671 Bytes

Contents

# frozen_string_literal: true
module ActiveMocker
  class SingleRelation
    attr_reader :item

    def initialize(item, child_self:, foreign_key:)
      @item = item
      assign_associations(child_self, item) if item.class <= Base
    end

    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
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
active_mocker-2.6.2 lib/active_mocker/mock/single_relation.rb
active_mocker-2.6.1.beta2 lib/active_mocker/mock/single_relation.rb
active_mocker-2.6.1.beta lib/active_mocker/mock/single_relation.rb
active_mocker-2.6.0 lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.4 lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.3 lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.2 lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.1 lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.1.pre lib/active_mocker/mock/single_relation.rb
active_mocker-2.5.0 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.4 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.3 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.2 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.1 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.0 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.0.pre5 lib/active_mocker/mock/single_relation.rb
active_mocker-2.3.4 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.0.pre4 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.0.pre3 lib/active_mocker/mock/single_relation.rb
active_mocker-2.4.0.pre2 lib/active_mocker/mock/single_relation.rb