blob: 7ae333463889729716f4d1d44be999083ba6cb12 (
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
31
32
33
34
35
36
37
38
39
40
41
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Graphql::Loaders::BatchModelLoader do
describe '#find' do
let_it_be(:issue) { create(:issue) }
let_it_be(:other_user) { create(:user) }
let_it_be(: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
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
it 'does not force values unnecessarily' do
expect do
a = described_class.new(User, user.id).find
b = described_class.new(Issue, issue.id).find
b.sync
c = described_class.new(User, other_user.id).find
a.sync
c.sync
end.not_to exceed_query_limit(2)
end
end
end
|