2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-11 18:12:34 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Files::CreateService do
|
2018-01-11 18:12:34 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
2018-09-17 09:14:58 -04:00
|
|
|
let(:user) { create(:user, :commit_email) }
|
2018-01-11 18:12:34 -05:00
|
|
|
let(:file_content) { 'Test file content' }
|
|
|
|
let(:branch_name) { project.default_branch }
|
|
|
|
let(:start_branch) { branch_name }
|
|
|
|
|
|
|
|
let(:commit_params) do
|
|
|
|
{
|
|
|
|
file_path: file_path,
|
|
|
|
commit_message: "Update File",
|
|
|
|
file_content: file_content,
|
|
|
|
file_content_encoding: "text",
|
|
|
|
start_project: project,
|
|
|
|
start_branch: start_branch,
|
|
|
|
branch_name: branch_name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-09-17 09:14:58 -04:00
|
|
|
let(:commit) { repository.head_commit }
|
|
|
|
|
2018-01-11 18:12:34 -05:00
|
|
|
subject { described_class.new(project, user, commit_params) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2018-01-11 18:12:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute" do
|
|
|
|
context 'when file matches LFS filter' do
|
|
|
|
let(:file_path) { 'test_file.lfs' }
|
|
|
|
let(:branch_name) { 'lfs' }
|
|
|
|
|
|
|
|
context 'with LFS disabled' do
|
|
|
|
it 'skips gitattributes check' do
|
|
|
|
expect(repository).not_to receive(:attributes_at)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't create LFS pointers" do
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
blob = repository.blob_at('lfs', file_path)
|
|
|
|
|
2018-03-16 09:35:03 -04:00
|
|
|
expect(blob.data).not_to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
|
2018-01-11 18:12:34 -05:00
|
|
|
expect(blob.data).to eq(file_content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with LFS enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates an LFS pointer' do
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
blob = repository.blob_at('lfs', file_path)
|
|
|
|
|
2018-03-16 09:35:03 -04:00
|
|
|
expect(blob.data).to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
|
2018-01-11 18:12:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates an LfsObject with the file's content" do
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(LfsObject.last.file.read).to eq file_content
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'links the LfsObject to the project' do
|
|
|
|
expect do
|
|
|
|
subject.execute
|
|
|
|
end.to change { project.lfs_objects.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-09-17 09:14:58 -04:00
|
|
|
|
|
|
|
context 'commit attribute' do
|
|
|
|
let(:file_path) { 'test-commit-attributes.txt' }
|
|
|
|
|
|
|
|
it 'uses the commit email' do
|
|
|
|
subject.execute
|
|
|
|
|
2018-09-18 05:04:15 -04:00
|
|
|
expect(user.commit_email).not_to eq(user.email)
|
2018-09-17 09:14:58 -04:00
|
|
|
expect(commit.author_email).to eq(user.commit_email)
|
|
|
|
expect(commit.committer_email).to eq(user.commit_email)
|
|
|
|
end
|
|
|
|
end
|
2018-01-11 18:12:34 -05:00
|
|
|
end
|