debian-mirror-gitlab/spec/graphql/resolvers/branch_commit_resolver_spec.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::BranchCommitResolver do
2020-05-24 23:13:21 +05:30
include GraphqlHelpers
subject(:commit) { resolve(described_class, obj: branch) }
let_it_be(:repository) { create(:project, :repository).repository }
2021-06-08 01:23:25 +05:30
2020-05-24 23:13:21 +05:30
let(:branch) { repository.find_branch('master') }
describe '#resolve' do
it 'resolves commit' do
2021-04-17 20:07:23 +05:30
expect(sync(commit)).to eq(repository.commits('master', limit: 1).last)
end
it 'sets project container' do
expect(sync(commit).container).to eq(repository.project)
2020-05-24 23:13:21 +05:30
end
context 'when branch does not exist' do
let(:branch) { nil }
it 'returns nil' do
is_expected.to be_nil
end
end
2021-04-17 20:07:23 +05:30
it 'is N+1 safe' do
commit_a = repository.commits('master', limit: 1).last
commit_b = repository.commits('spooky-stuff', limit: 1).last
commits = batch_sync(max_queries: 1) do
[
resolve(described_class, obj: branch),
resolve(described_class, obj: repository.find_branch('spooky-stuff'))
]
end
expect(commits).to contain_exactly(commit_a, commit_b)
end
2020-05-24 23:13:21 +05:30
end
end