2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe Gitlab::LegacyGithubImport::BranchFormatter do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:commit) { create(:commit, project: project) }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:repo) { double }
|
|
|
|
let(:raw) do
|
|
|
|
{
|
2017-08-17 22:00:37 +05:30
|
|
|
ref: 'branch-merged',
|
2016-06-02 11:05:42 +05:30
|
|
|
repo: repo,
|
2016-08-24 12:49:21 +05:30
|
|
|
sha: commit.id
|
2016-06-02 11:05:42 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#exists?' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns true when branch exists and commit is part of the branch' do
|
2016-06-02 11:05:42 +05:30
|
|
|
branch = described_class.new(project, double(raw))
|
|
|
|
|
|
|
|
expect(branch.exists?).to eq true
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns false when branch exists and commit is not part of the branch' do
|
|
|
|
branch = described_class.new(project, double(raw.merge(ref: 'feature')))
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
expect(branch.exists?).to eq false
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns false when branch does not exist' do
|
|
|
|
branch = described_class.new(project, double(raw.merge(ref: 'removed-branch')))
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
expect(branch.exists?).to eq false
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repo' do
|
|
|
|
it 'returns raw repo' do
|
|
|
|
branch = described_class.new(project, double(raw))
|
|
|
|
|
|
|
|
expect(branch.repo).to eq repo
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#sha' do
|
|
|
|
it 'returns raw sha' do
|
|
|
|
branch = described_class.new(project, double(raw))
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
expect(branch.sha).to eq commit.id
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns true when raw sha and ref are present' do
|
2016-06-02 11:05:42 +05:30
|
|
|
branch = described_class.new(project, double(raw))
|
|
|
|
|
|
|
|
expect(branch.valid?).to eq true
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'returns false when raw sha is blank' do
|
|
|
|
branch = described_class.new(project, double(raw.merge(sha: nil)))
|
|
|
|
|
|
|
|
expect(branch.valid?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when raw ref is blank' do
|
|
|
|
branch = described_class.new(project, double(raw.merge(ref: nil)))
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
expect(branch.valid?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|