diff options
Diffstat (limited to 'spec/lib/gitlab/git/tree_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git/tree_spec.rb | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb index 97ba177da71..172d7a3f27b 100644 --- a/spec/lib/gitlab/git/tree_spec.rb +++ b/spec/lib/gitlab/git/tree_spec.rb @@ -3,6 +3,8 @@ require "spec_helper" RSpec.describe Gitlab::Git::Tree, :seed_helper do + let_it_be(:user) { create(:user) } + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') } shared_examples :repo do @@ -85,51 +87,29 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do context :flat_path do let(:filename) { 'files/flat/path/correct/content.txt' } - let(:sha) { create_file(filename) } let(:path) { 'files/flat' } # rubocop: disable Rails/FindBy # This is not ActiveRecord where..first let(:subdir_file) { entries.first } # rubocop: enable Rails/FindBy - let(:repository_rugged) { Rugged::Repository.new(File.join(SEED_STORAGE_PATH, TEST_REPO_PATH)) } - - it { expect(subdir_file.flat_path).to eq('files/flat/path/correct') } - end - - def create_file(path) - oid = repository_rugged.write('test', :blob) - index = repository_rugged.index - index.add(path: filename, oid: oid, mode: 0100644) - - options = commit_options( - repository_rugged, - index, - repository_rugged.head.target, - 'HEAD', - 'Add new file') + let!(:sha) do + repository.multi_action( + user, + branch_name: 'HEAD', + message: "Create #{filename}", + actions: [{ + action: :create, + file_path: filename, + contents: 'test' + }] + ).newrev + end - Rugged::Commit.create(repository_rugged, options) - end + after do + ensure_seeds + end - # Build the options hash that's passed to Rugged::Commit#create - def commit_options(repo, index, target, ref, message) - options = {} - options[:tree] = index.write_tree(repo) - options[:author] = { - email: "test@example.com", - name: "Test Author", - time: Time.gm(2014, "mar", 3, 20, 15, 1) - } - options[:committer] = { - email: "test@example.com", - name: "Test Author", - time: Time.gm(2014, "mar", 3, 20, 15, 1) - } - options[:message] ||= message - options[:parents] = repo.empty? ? [] : [target].compact - options[:update_ref] = ref - - options + it { expect(subdir_file.flat_path).to eq('files/flat/path/correct') } end end |