summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/files/create_service_spec.rb4
-rw-r--r--spec/services/files/multi_service_spec.rb72
-rw-r--r--spec/services/lfs/file_transformer_spec.rb97
-rw-r--r--spec/services/merge_requests/merge_request_diff_cache_service_spec.rb36
-rw-r--r--spec/services/projects/create_service_spec.rb4
-rw-r--r--spec/services/projects/fork_service_spec.rb2
-rw-r--r--spec/services/projects/transfer_service_spec.rb2
-rw-r--r--spec/services/projects/update_service_spec.rb11
8 files changed, 203 insertions, 25 deletions
diff --git a/spec/services/files/create_service_spec.rb b/spec/services/files/create_service_spec.rb
index 030263b1502..abe99b9e794 100644
--- a/spec/services/files/create_service_spec.rb
+++ b/spec/services/files/create_service_spec.rb
@@ -43,7 +43,7 @@ describe Files::CreateService do
blob = repository.blob_at('lfs', file_path)
- expect(blob.data).not_to start_with('version https://git-lfs.github.com/spec/v1')
+ expect(blob.data).not_to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
expect(blob.data).to eq(file_content)
end
end
@@ -58,7 +58,7 @@ describe Files::CreateService do
blob = repository.blob_at('lfs', file_path)
- expect(blob.data).to start_with('version https://git-lfs.github.com/spec/v1')
+ expect(blob.data).to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
end
it "creates an LfsObject with the file's content" do
diff --git a/spec/services/files/multi_service_spec.rb b/spec/services/files/multi_service_spec.rb
index b9971776b33..59984c10990 100644
--- a/spec/services/files/multi_service_spec.rb
+++ b/spec/services/files/multi_service_spec.rb
@@ -4,28 +4,30 @@ describe Files::MultiService do
subject { described_class.new(project, user, commit_params) }
let(:project) { create(:project, :repository) }
+ let(:repository) { project.repository }
let(:user) { create(:user) }
let(:branch_name) { project.default_branch }
let(:original_file_path) { 'files/ruby/popen.rb' }
let(:new_file_path) { 'files/ruby/popen.rb' }
+ let(:file_content) { 'New content' }
let(:action) { 'update' }
let!(:original_commit_id) do
Gitlab::Git::Commit.last_for_path(project.repository, branch_name, original_file_path).sha
end
- let(:actions) do
- [
- {
- action: action,
- file_path: new_file_path,
- previous_path: original_file_path,
- content: 'New content',
- last_commit_id: original_commit_id
- }
- ]
+ let(:default_action) do
+ {
+ action: action,
+ file_path: new_file_path,
+ previous_path: original_file_path,
+ content: file_content,
+ last_commit_id: original_commit_id
+ }
end
+ let(:actions) { [default_action] }
+
let(:commit_params) do
{
commit_message: "Update File",
@@ -110,6 +112,56 @@ describe Files::MultiService do
end
end
+ context 'when creating a file matching an LFS filter' do
+ let(:action) { 'create' }
+ let(:branch_name) { 'lfs' }
+ let(:new_file_path) { 'test_file.lfs' }
+
+ 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', new_file_path)
+
+ expect(blob.data).to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
+ end
+
+ it "creates an LfsObject with the file's content" do
+ subject.execute
+
+ expect(LfsObject.last.file.read).to eq file_content
+ end
+
+ context 'with base64 encoded content' do
+ let(:raw_file_content) { 'Raw content' }
+ let(:file_content) { Base64.encode64(raw_file_content) }
+ let(:actions) { [default_action.merge(encoding: 'base64')] }
+
+ it 'creates an LFS pointer' do
+ subject.execute
+
+ blob = repository.blob_at('lfs', new_file_path)
+
+ expect(blob.data).to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
+ end
+
+ it "creates an LfsObject with the file's content" do
+ subject.execute
+
+ expect(LfsObject.last.file.read).to eq raw_file_content
+ end
+ end
+
+ it 'links the LfsObject to the project' do
+ expect do
+ subject.execute
+ end.to change { project.lfs_objects.count }.by(1)
+ end
+ end
+
context 'when file status validation is skipped' do
let(:action) { 'create' }
let(:new_file_path) { 'files/ruby/new_file.rb' }
diff --git a/spec/services/lfs/file_transformer_spec.rb b/spec/services/lfs/file_transformer_spec.rb
new file mode 100644
index 00000000000..e8938338cb7
--- /dev/null
+++ b/spec/services/lfs/file_transformer_spec.rb
@@ -0,0 +1,97 @@
+require "spec_helper"
+
+describe Lfs::FileTransformer do
+ let(:project) { create(:project, :repository) }
+ let(:repository) { project.repository }
+ let(:file_content) { 'Test file content' }
+ let(:branch_name) { 'lfs' }
+ let(:file_path) { 'test_file.lfs' }
+
+ subject { described_class.new(project, branch_name) }
+
+ describe '#new_file' do
+ context 'with lfs disabled' do
+ it 'skips gitattributes check' do
+ expect(repository.raw).not_to receive(:blob_at)
+
+ subject.new_file(file_path, file_content)
+ end
+
+ it 'returns untransformed content' do
+ result = subject.new_file(file_path, file_content)
+
+ expect(result.content).to eq(file_content)
+ end
+
+ it 'returns untransformed encoding' do
+ result = subject.new_file(file_path, file_content, encoding: 'base64')
+
+ expect(result.encoding).to eq('base64')
+ end
+ end
+
+ context 'with lfs enabled' do
+ before do
+ allow(project).to receive(:lfs_enabled?).and_return(true)
+ end
+
+ it 'reuses cached gitattributes' do
+ second_file = 'another_file.lfs'
+
+ expect(repository.raw).to receive(:blob_at).with(branch_name, '.gitattributes').once
+
+ subject.new_file(file_path, file_content)
+ subject.new_file(second_file, file_content)
+ end
+
+ it "creates an LfsObject with the file's content" do
+ subject.new_file(file_path, file_content)
+
+ expect(LfsObject.last.file.read).to eq file_content
+ end
+
+ it 'returns an LFS pointer' do
+ result = subject.new_file(file_path, file_content)
+
+ expect(result.content).to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
+ end
+
+ it 'returns LFS pointer encoding as text' do
+ result = subject.new_file(file_path, file_content, encoding: 'base64')
+
+ expect(result.encoding).to eq('text')
+ end
+
+ context "when doesn't use LFS" do
+ let(:file_path) { 'other.filetype' }
+
+ it "doesn't create LFS pointers" do
+ new_content = subject.new_file(file_path, file_content).content
+
+ expect(new_content).not_to start_with(Gitlab::Git::LfsPointerFile::VERSION_LINE)
+ expect(new_content).to eq(file_content)
+ end
+ end
+
+ it 'links LfsObjects to project' do
+ expect do
+ subject.new_file(file_path, file_content)
+ end.to change { project.lfs_objects.count }.by(1)
+ end
+
+ context 'when LfsObject already exists' do
+ let(:lfs_pointer) { Gitlab::Git::LfsPointerFile.new(file_content) }
+
+ before do
+ create(:lfs_object, oid: lfs_pointer.sha256, size: lfs_pointer.size)
+ end
+
+ it 'links LfsObjects to project' do
+ expect do
+ subject.new_file(file_path, file_content)
+ end.to change { project.lfs_objects.count }.by(1)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/services/merge_requests/merge_request_diff_cache_service_spec.rb b/spec/services/merge_requests/merge_request_diff_cache_service_spec.rb
index bb46e1dd9ab..57b6165cfb0 100644
--- a/spec/services/merge_requests/merge_request_diff_cache_service_spec.rb
+++ b/spec/services/merge_requests/merge_request_diff_cache_service_spec.rb
@@ -1,19 +1,39 @@
require 'spec_helper'
-describe MergeRequests::MergeRequestDiffCacheService do
+describe MergeRequests::MergeRequestDiffCacheService, :use_clean_rails_memory_store_caching do
let(:subject) { described_class.new }
+ let(:merge_request) { create(:merge_request) }
describe '#execute' do
- it 'retrieves the diff files to cache the highlighted result' do
- merge_request = create(:merge_request)
- cache_key = [merge_request.merge_request_diff, 'highlighted-diff-files', Gitlab::Diff::FileCollection::MergeRequestDiff.default_options]
-
- expect(Rails.cache).to receive(:read).with(cache_key).and_return({})
- expect(Rails.cache).to receive(:write).with(cache_key, anything)
+ before do
allow_any_instance_of(Gitlab::Diff::File).to receive(:text?).and_return(true)
allow_any_instance_of(Gitlab::Diff::File).to receive(:diffable?).and_return(true)
+ end
+
+ it 'retrieves the diff files to cache the highlighted result' do
+ new_diff = merge_request.merge_request_diff
+ cache_key = new_diff.diffs.cache_key
+
+ expect(Rails.cache).to receive(:read).with(cache_key).and_call_original
+ expect(Rails.cache).to receive(:write).with(cache_key, anything, anything).and_call_original
+
+ subject.execute(merge_request, new_diff)
+ end
+
+ it 'clears the cache for older diffs on the merge request' do
+ old_diff = merge_request.merge_request_diff
+ old_cache_key = old_diff.diffs.cache_key
+
+ subject.execute(merge_request, old_diff)
+
+ new_diff = merge_request.create_merge_request_diff
+ new_cache_key = new_diff.diffs.cache_key
+
+ expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original
+ expect(Rails.cache).to receive(:read).with(new_cache_key).and_call_original
+ expect(Rails.cache).to receive(:write).with(new_cache_key, anything, anything).and_call_original
- subject.execute(merge_request)
+ subject.execute(merge_request, new_diff)
end
end
end
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index 9a44dfde41b..8471467d2fa 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -164,7 +164,7 @@ describe Projects::CreateService, '#execute' do
context 'with legacy storage' do
before do
- gitlab_shell.add_repository(repository_storage, "#{user.namespace.full_path}/existing")
+ gitlab_shell.create_repository(repository_storage, "#{user.namespace.full_path}/existing")
end
after do
@@ -200,7 +200,7 @@ describe Projects::CreateService, '#execute' do
end
before do
- gitlab_shell.add_repository(repository_storage, hashed_path)
+ gitlab_shell.create_repository(repository_storage, hashed_path)
end
after do
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 409d5de8d43..d1011b07db6 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -108,7 +108,7 @@ describe Projects::ForkService do
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage]['path'] }
before do
- gitlab_shell.add_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}")
+ gitlab_shell.create_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}")
end
after do
diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb
index ae0e22e3dc0..ce567fe3879 100644
--- a/spec/services/projects/transfer_service_spec.rb
+++ b/spec/services/projects/transfer_service_spec.rb
@@ -151,7 +151,7 @@ describe Projects::TransferService do
before do
group.add_owner(user)
- unless gitlab_shell.add_repository(repository_storage, "#{group.full_path}/#{project.path}")
+ unless gitlab_shell.create_repository(repository_storage, "#{group.full_path}/#{project.path}")
raise 'failed to add repository'
end
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index ad5a289290c..f3f97b6b921 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -132,6 +132,15 @@ describe Projects::UpdateService do
expect(result).to eq({ status: :success })
expect(project.wiki_repository_exists?).to be false
end
+
+ it 'handles empty project feature attributes' do
+ project.project_feature.update(wiki_access_level: ProjectFeature::DISABLED)
+
+ result = update_project(project, user, { name: 'test1' })
+
+ expect(result).to eq({ status: :success })
+ expect(project.wiki_repository_exists?).to be false
+ end
end
context 'when enabling a wiki' do
@@ -187,7 +196,7 @@ describe Projects::UpdateService do
let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
before do
- gitlab_shell.add_repository(repository_storage, "#{user.namespace.full_path}/existing")
+ gitlab_shell.create_repository(repository_storage, "#{user.namespace.full_path}/existing")
end
after do