summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/graphql/loaders/batch_model_loader_spec.rb
blob: cf1f00bc176cbfceeba5106dbcd03f6c2db8b54b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Graphql::Loaders::BatchModelLoader do
  describe '#find' do
    let(:issue) { create(:issue) }
    let(:user) { create(:user) }

    it 'finds a model by id' do
      issue_result = described_class.new(Issue, issue.id).find
      user_result = described_class.new(User, user.id).find

      expect(issue_result.sync).to eq(issue)
      expect(user_result.sync).to eq(user)
    end

    it 'only queries once per model' do
      other_user = create(:user)
      user
      issue

      expect do
        [described_class.new(User, other_user.id).find,
         described_class.new(User, user.id).find,
         described_class.new(Issue, issue.id).find].map(&:sync)
      end.not_to exceed_query_limit(2)
    end
  end
end