Sha256: 698138927655295013b4bfb1252f36abe2e1b23308cfb00afe6b1978eb1fd741

Contents?: true

Size: 869 Bytes

Versions: 4

Compression:

Stored size: 869 Bytes

Contents

require 'spec_helper'
require 'btspm/eager_loadable'

RSpec.describe Btspm::EagerLoadable do

  module Btspm
    class Dummy
    end
  end

  let!(:loader) {Btspm::Dummy.new.extend(Btspm::EagerLoadable)}

  describe '#eager_load' do
    it 'should return collection with pre-loaded associations for active_record_relation' do
      user = User.create
      user.posts = [Post.create]

      #Activerecord relation
      record_relation = loader.eager_load(User.where(id: user.id), :posts)
      expect(record_relation.first.association(:posts).loaded?).to be true

      #Array
      array = loader.eager_load([user], :posts)
      expect(array.first.association(:posts).loaded?).to be true

      #Single record
      record = loader.eager_load(user, :posts)
      expect(record.association(:posts).loaded?).to be true
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
btspm-0.0.4 spec/lib/eager_loadable_spec.rb
btspm-0.0.3 spec/lib/eager_loadable_spec.rb
btspm-0.0.2 spec/lib/eager_loadable_spec.rb
btspm-0.0.1 spec/lib/eager_loadable_spec.rb