2020-06-04 05:08:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-26 05:08:59 -04:00
|
|
|
RSpec.describe ExtractsRef do
|
2020-06-04 05:08:01 -04:00
|
|
|
include described_class
|
|
|
|
include RepoHelpers
|
|
|
|
|
|
|
|
let_it_be(:owner) { create(:user) }
|
|
|
|
let_it_be(:container) { create(:snippet, :repository, author: owner) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2020-06-04 05:08:01 -04:00
|
|
|
let(:ref) { sample_commit[:id] }
|
2022-02-09 19:15:43 -05:00
|
|
|
let(:path) { sample_commit[:line_code_path] }
|
|
|
|
let(:params) { ActionController::Parameters.new(path: path, ref: ref) }
|
2020-06-04 05:08:01 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
ref_names = ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', 'release/app', 'release/app/v1.0.0']
|
|
|
|
|
|
|
|
allow(container.repository).to receive(:ref_names).and_return(ref_names)
|
|
|
|
allow_any_instance_of(described_class).to receive(:repository_container).and_return(container)
|
|
|
|
end
|
|
|
|
|
2020-11-16 07:09:05 -05:00
|
|
|
describe '#assign_ref_vars' do
|
|
|
|
it_behaves_like 'assigns ref vars'
|
|
|
|
|
|
|
|
context 'ref and path are nil' do
|
2022-02-09 19:15:43 -05:00
|
|
|
let(:ref) { nil }
|
|
|
|
let(:path) { nil }
|
2020-11-16 07:09:05 -05:00
|
|
|
|
|
|
|
it 'does not set commit' do
|
|
|
|
expect(container.repository).not_to receive(:commit).with('')
|
|
|
|
|
|
|
|
assign_ref_vars
|
|
|
|
|
|
|
|
expect(@commit).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2022-02-09 19:15:43 -05:00
|
|
|
|
|
|
|
context 'when ref and path have incorrect format' do
|
|
|
|
let(:ref) { { wrong: :format } }
|
|
|
|
let(:path) { { also: :wrong } }
|
|
|
|
|
|
|
|
it 'does not raise an exception' do
|
|
|
|
expect { assign_ref_vars }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2020-11-16 07:09:05 -05:00
|
|
|
end
|
|
|
|
|
2020-06-04 05:08:01 -04:00
|
|
|
it_behaves_like 'extracts refs'
|
|
|
|
end
|