diff options
Diffstat (limited to 'ruby/spec/lib/gitlab')
-rw-r--r-- | ruby/spec/lib/gitlab/git/branch_spec.rb | 19 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/commit_spec.rb | 207 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/hook_spec.rb | 144 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/popen_spec.rb | 108 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/push_options_spec.rb | 32 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_spec.rb | 249 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/user_spec.rb | 47 |
7 files changed, 0 insertions, 806 deletions
diff --git a/ruby/spec/lib/gitlab/git/branch_spec.rb b/ruby/spec/lib/gitlab/git/branch_spec.rb deleted file mode 100644 index 3381fc230..000000000 --- a/ruby/spec/lib/gitlab/git/branch_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require "spec_helper" - -describe Gitlab::Git::Branch do - include TestRepo - - let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) } - - subject { repository.branches } - - it { is_expected.to be_an(Array) } - - describe '#size' do - subject { super().size } - - it { is_expected.to eq(SeedRepo::Repo::BRANCHES.size) } - end - - it { expect(repository.branches.size).to eq(SeedRepo::Repo::BRANCHES.size) } -end diff --git a/ruby/spec/lib/gitlab/git/commit_spec.rb b/ruby/spec/lib/gitlab/git/commit_spec.rb deleted file mode 100644 index bd2b5aeeb..000000000 --- a/ruby/spec/lib/gitlab/git/commit_spec.rb +++ /dev/null @@ -1,207 +0,0 @@ -require "spec_helper" - -describe Gitlab::Git::Commit do - include TestRepo - - let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } - let(:rugged_repo) { Rugged::Repository.new(repository.path) } - let(:commit) { described_class.find(repository, SeedRepo::Commit::ID) } - let(:rugged_commit) { rugged_repo.lookup(SeedRepo::Commit::ID) } - - describe "Commit info" do - let(:committer) do - { - email: 'mike@smith.com', - name: "Mike Smith", - time: Time.new(2000, 1, 1, 0, 0, 0, "+08:00") - } - end - let(:author) do - { - email: 'john@smith.com', - name: "John Smith", - time: Time.new(2000, 1, 1, 0, 0, 0, "-08:00") - } - end - let(:parents) { [rugged_repo.head.target] } - let(:gitlab_parents) do - parents.map { |c| described_class.find(repository, c.oid) } - end - let(:tree) { parents.first.tree } - let(:sha) do - Rugged::Commit.create( - rugged_repo, - author: author, - committer: committer, - tree: tree, - parents: parents, - message: "Refactoring specs", - update_ref: "HEAD" - ) - end - let(:rugged_commit) { rugged_repo.lookup(sha) } - let(:commit) { described_class.find(repository, sha) } - - it { expect(commit.short_id).to eq(rugged_commit.oid[0..10]) } - it { expect(commit.id).to eq(rugged_commit.oid) } - it { expect(commit.sha).to eq(rugged_commit.oid) } - it { expect(commit.safe_message).to eq(rugged_commit.message) } - it { expect(commit.date).to eq(rugged_commit.committer[:time]) } - it { expect(commit.author_email).to eq(author[:email]) } - it { expect(commit.author_name).to eq(author[:name]) } - it { expect(commit.committer_name).to eq(committer[:name]) } - it { expect(commit.committer_email).to eq(committer[:email]) } - it { expect(commit.parents).to eq(gitlab_parents) } - it { expect(commit.no_commit_message).to eq("--no commit message") } - end - - describe "Commit info from gitaly commit" do - let(:subject) { "My commit".b } - let(:body) { subject + "My body".b } - let(:body_size) { body.length } - let(:gitaly_commit) { build(:gitaly_commit, subject: subject, body: body, body_size: body_size) } - let(:id) { gitaly_commit.id } - let(:committer) { gitaly_commit.committer } - let(:author) { gitaly_commit.author } - let(:commit) { described_class.new(repository, gitaly_commit) } - - it { expect(commit.short_id).to eq(id[0..10]) } - it { expect(commit.id).to eq(id) } - it { expect(commit.sha).to eq(id) } - it { expect(commit.safe_message).to eq(body) } - it { expect(commit.author_email).to eq(author.email) } - it { expect(commit.author_name).to eq(author.name) } - it { expect(commit.committer_name).to eq(committer.name) } - it { expect(commit.committer_email).to eq(committer.email) } - it { expect(commit.parent_ids).to eq(gitaly_commit.parent_ids) } - - context 'non-UTC dates' do - let(:seconds) { Time.now.to_i } - - it 'sets timezones correctly' do - gitaly_commit.author.date.seconds = seconds - gitaly_commit.author.timezone = '-0800' - gitaly_commit.committer.date.seconds = seconds - gitaly_commit.committer.timezone = '+0800' - - expect(commit.authored_date).to eq(Time.at(seconds, in: '-08:00')) - expect(commit.committed_date).to eq(Time.at(seconds, in: '+08:00')) - end - end - - context 'body_size != body.size' do - let(:body) { "".b } - - context 'zero body_size' do - it { expect(commit.safe_message).to eq(subject) } - end - end - end - - context 'Class methods' do - describe '.find' do - it "returns an array of parent ids" do - expect(described_class.find(repository, SeedRepo::Commit::ID).parent_ids).to be_an(Array) - end - - it "should return valid commit for tag" do - expect(described_class.find(repository, 'v1.0.0').id).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') - end - - it "should return nil for non-commit ids" do - blob_id = repository.lookup("#{SeedRepo::Commit::ID}:files/ruby/popen.rb") - expect(described_class.find(repository, blob_id)).to be_nil - end - - it "should return nil for parent of non-commit object" do - blob_id = repository.lookup("#{SeedRepo::Commit::ID}:files/ruby/popen.rb") - expect(described_class.find(repository, "#{blob_id}^")).to be_nil - end - - it "should return nil for nonexisting ids" do - expect(described_class.find(repository, "+123_4532530XYZ")).to be_nil - end - - context 'with broken repo' do - let(:repository) { gitlab_git_from_gitaly(new_broken_test_repo) } - - it 'returns nil' do - expect(described_class.find(repository, SeedRepo::Commit::ID)).to be_nil - end - end - end - - describe '.shas_with_signatures' do - let(:signed_shas) { %w[5937ac0a7beb003549fc5fd26fc247adbce4a52e 570e7b2abdd848b95f2f578043fc23bd6f6fd24d] } - let(:unsigned_shas) { %w[19e2e9b4ef76b422ce1154af39a91323ccc57434 c642fe9b8b9f28f9225d7ea953fe14e74748d53b] } - let(:first_signed_shas) { %w[5937ac0a7beb003549fc5fd26fc247adbce4a52e c642fe9b8b9f28f9225d7ea953fe14e74748d53b] } - - it 'has 2 signed shas' do - ret = described_class.shas_with_signatures(repository, signed_shas) - expect(ret).to eq(signed_shas) - end - - it 'has 0 signed shas' do - ret = described_class.shas_with_signatures(repository, unsigned_shas) - expect(ret).to eq([]) - end - - it 'has 1 signed sha' do - ret = described_class.shas_with_signatures(repository, first_signed_shas) - expect(ret).to contain_exactly(first_signed_shas.first) - end - end - end - - describe '#init_from_rugged' do - let(:gitlab_commit) { described_class.new(repository, rugged_commit) } - subject { gitlab_commit } - - describe '#id' do - subject { super().id } - it { is_expected.to eq(SeedRepo::Commit::ID) } - end - end - - describe '#init_from_hash' do - let(:commit) { described_class.new(repository, sample_commit_hash) } - subject { commit } - - describe '#id' do - subject { super().id } - it { is_expected.to eq(sample_commit_hash[:id]) } - end - - describe '#message' do - subject { super().message } - it { is_expected.to eq(sample_commit_hash[:message]) } - end - end - - describe '#to_hash' do - let(:hash) { commit.to_hash } - subject { hash } - - it { is_expected.to be_kind_of Hash } - - describe '#keys' do - subject { super().keys.sort } - it { is_expected.to match(sample_commit_hash.keys.sort) } - end - end - - def sample_commit_hash - { - author_email: "dmitriy.zaporozhets@gmail.com", - author_name: "Dmitriy Zaporozhets", - authored_date: "2012-02-27 20:51:12 +0200", - committed_date: "2012-02-27 20:51:12 +0200", - committer_email: "dmitriy.zaporozhets@gmail.com", - committer_name: "Dmitriy Zaporozhets", - id: SeedRepo::Commit::ID, - message: "tree css fixes", - parent_ids: ["874797c3a73b60d2187ed6e2fcabd289ff75171e"], - trailers: [] - } - end -end diff --git a/ruby/spec/lib/gitlab/git/hook_spec.rb b/ruby/spec/lib/gitlab/git/hook_spec.rb deleted file mode 100644 index 1d5454728..000000000 --- a/ruby/spec/lib/gitlab/git/hook_spec.rb +++ /dev/null @@ -1,144 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::Hook do - include TestRepo - - describe '.directory' do - it 'does not raise an KeyError' do - expect { described_class.directory }.not_to raise_error - end - end - - describe '#trigger' do - let(:tmp_dir) { Dir.mktmpdir } - let(:hook_names) { %w[pre-receive post-receive update] } - let(:repo) { gitlab_git_from_gitaly(test_repo_read_only) } - let(:push_options) do - Gitlab::Git::PushOptions.new(['ci.skip']) - end - - def trigger_with_stub_data(hook, push_options) - hook.trigger('user-1', 'admin', '0' * 40, 'a' * 40, 'master', push_options: push_options) - end - - before do - hook_names.each do |f| - path = File.join(tmp_dir, f) - File.write(path, script) - FileUtils.chmod("u+x", path) - end - - allow(Gitlab.config.git).to receive(:hooks_directory).and_return(tmp_dir) - end - - after do - FileUtils.remove_entry(tmp_dir) - end - - context 'when the hooks require environment variables' do - let(:vars) do - { - 'GITALY_HOOKS_PAYLOAD' => Base64.strict_encode64({ - repository: repo.gitaly_repository.to_json, - binary_directory: Gitlab.config.gitaly.bin_dir, - git_path: Gitlab.config.git.bin_path, - internal_socket: Gitlab.config.gitaly.internal_socket, - internal_socket_token: nil, - user_details: { - userid: 'user-123', - username: 'janedoe', - protocol: 'web' - } - }.to_json), - 'PWD' => repo.path, - 'GIT_DIR' => repo.path - } - end - - let(:script) do - [ - "#!/bin/sh", - vars.map do |key, value| - <<-SCRIPT - if [ x$#{key} != x#{value} ]; then - echo "unexpected value: #{key}=$#{key}" - exit 1 - fi - SCRIPT - end.join, - "exit 0" - ].join("\n") - end - - it 'returns true' do - hook_names.each do |hook| - trigger_result = described_class.new(hook, repo) - .trigger('user-123', 'janedoe', '0' * 40, 'a' * 40, 'master', push_options: push_options) - - expect(trigger_result.first).to be(true), "#{hook} failed: #{trigger_result.last}" - end - end - end - - context 'when the hooks are successful' do - let(:script) { "#!/bin/sh\nexit 0\n" } - - it 'returns true' do - hook_names.each do |hook| - trigger_result = described_class.new(hook, repo) - .trigger('user-456', 'admin', '0' * 40, 'a' * 40, 'master', push_options: push_options) - - expect(trigger_result.first).to be(true) - end - end - end - - context 'when the hooks fail' do - let(:script) { "#!/bin/sh\nexit 1\n" } - - it 'returns false' do - hook_names.each do |name| - hook = described_class.new(name, repo) - trigger_result = trigger_with_stub_data(hook, push_options) - - expect(trigger_result.first).to be(false) - end - end - end - - context 'when push options are passed' do - let(:script) do - <<~HOOK - #!/usr/bin/env ruby - unless ENV['GIT_PUSH_OPTION_COUNT'] == '1' && ENV['GIT_PUSH_OPTION_0'] == 'ci.skip' - abort 'missing GIT_PUSH_OPTION env vars' - end - HOOK - end - - context 'for pre-receive and post-receive hooks' do - let(:hooks) do - %w[pre-receive post-receive].map { |name| described_class.new(name, repo) } - end - - it 'sets the push options environment variables' do - hooks.each do |hook| - trigger_result = trigger_with_stub_data(hook, push_options) - - expect(trigger_result.first).to be(true) - end - end - end - - context 'for update hook' do - let(:hook) { described_class.new('update', repo) } - - it 'does not set the push options environment variables' do - trigger_result = trigger_with_stub_data(hook, push_options) - - expect(trigger_result.first).to be(false) - end - end - end - end -end diff --git a/ruby/spec/lib/gitlab/git/popen_spec.rb b/ruby/spec/lib/gitlab/git/popen_spec.rb deleted file mode 100644 index 6272b7c17..000000000 --- a/ruby/spec/lib/gitlab/git/popen_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'spec_helper' - -describe 'Gitlab::Git::Popen' do - let(:path) { Dir.mktmpdir } - - let(:klass) do - Class.new(Object) do - include Gitlab::Git::Popen - end - end - - after do - FileUtils.remove_entry path - end - - context 'popen' do - context 'zero status' do - let(:result) { klass.new.popen(%w(ls), path) } - let(:status) { result.last } - - it { expect(status).to be_zero } - end - - context 'non-zero status' do - let(:result) { klass.new.popen(%w(cat NOTHING), path) } - let(:output) { result.first } - let(:status) { result.last } - - it { expect(status).to eq(1) } - it { expect(output).to include('No such file or directory') } - end - - context 'when stderr is not included' do - let(:result) { klass.new.popen(%w(cat NOTHING), path, include_stderr: false) } - let(:output) { result.first } - let(:status) { result.last } - - it { expect(status).to eq(1) } - it { expect(output).to eq('') } - end - - context 'when stderr is included' do - let(:result) { klass.new.popen(['ruby', '-e', 'warn "hello world"'], path, include_stderr: true) } - let(:output) { result.first } - let(:status) { result.last } - - it { expect(status).to eq(0) } - it { expect(output).to eq("hello world\n") } - end - - context 'unsafe string command' do - it 'raises an error when it gets called with a string argument' do - expect { klass.new.popen('ls', path) }.to raise_error(RuntimeError) - end - end - - context 'with custom options' do - let(:vars) { { 'foobar' => 123, 'PWD' => path } } - let(:options) { { chdir: path } } - - it 'calls popen3 with the provided environment variables' do - expect(Open3).to receive(:popen3).with(vars, 'ls', options) - - klass.new.popen(%w(ls), path, { 'foobar' => 123 }) # rubocop:disable Style/BracesAroundHashParameters: - end - end - - context 'use stdin' do - let(:result) { klass.new.popen(%w[cat], path) { |stdin| stdin.write 'hello' } } - let(:output) { result.first } - let(:status) { result.last } - - it { expect(status).to be_zero } - it { expect(output).to eq('hello') } - end - - context 'with lazy block' do - it 'yields a lazy io' do - expect_lazy_io = lambda do |io| - expect(io).to be_a Enumerator::Lazy - expect(io.inspect).to include('#<IO:fd') - end - - klass.new.popen(%w[ls], path, lazy_block: expect_lazy_io) - end - - it "doesn't wait for process exit" do - Timeout.timeout(2) do - klass.new.popen(%w[yes], path, lazy_block: ->(io) {}) - end - end - end - - context 'with non ASCII output' do - let(:stdin) { StringIO.new } - let(:stdout) { StringIO.new("Preparando \xC3\xA1rbol de trabajo") } - let(:stderr) { StringIO.new("UTF-8 error é").set_encoding('UTF-8') } - let(:process_status) { double('Process::Status', exitstatus: 0) } - let(:wait_thr) { double('Process::Waiter', value: process_status) } - - it "handles the output correctly" do - expect(Open3).to receive(:popen3).and_yield(stdin, stdout, stderr, wait_thr) - - klass.new.popen(%w[ls], path) - end - end - end -end diff --git a/ruby/spec/lib/gitlab/git/push_options_spec.rb b/ruby/spec/lib/gitlab/git/push_options_spec.rb deleted file mode 100644 index d2c74f399..000000000 --- a/ruby/spec/lib/gitlab/git/push_options_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Git::PushOptions do - subject { described_class.new(options) } - - describe '#env_data' do - context 'when push options are set' do - let(:options) { ['ci.skip', 'test=value'] } - - it 'sets GIT_PUSH_OPTION environment variables' do - env_data = subject.env_data - - expect(env_data.count).to eq(3) - expect(env_data['GIT_PUSH_OPTION_COUNT']).to eq('2') - expect(env_data['GIT_PUSH_OPTION_0']).to eq('ci.skip') - expect(env_data['GIT_PUSH_OPTION_1']).to eq('test=value') - end - end - - context 'when push options are not set' do - let(:options) { [] } - - it 'does not set any variable' do - env_data = subject.env_data - - expect(env_data).to eq({}) - end - end - end -end diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb deleted file mode 100644 index 573058b25..000000000 --- a/ruby/spec/lib/gitlab/git/repository_spec.rb +++ /dev/null @@ -1,249 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength - include TestRepo - include Gitlab::EncodingHelper - using RSpec::Parameterized::TableSyntax - - let(:mutable_repository) { gitlab_git_from_gitaly(new_mutable_git_test_repo) } - let(:repository) { gitlab_git_from_gitaly(git_test_repo_read_only) } - let(:repository_path) { repository.path } - let(:repository_rugged) { Rugged::Repository.new(repository_path) } - let(:storage_path) { DEFAULT_STORAGE_DIR } - let(:user) { Gitlab::Git::User.new('johndone', 'John Doe', 'johndoe@mail.com', 'user-1') } - - describe '.from_gitaly_with_block' do - let(:call_metadata) do - { - 'user-agent' => 'grpc-go/1.9.1', - 'gitaly-storage-path' => DEFAULT_STORAGE_DIR, - 'gitaly-repo-path' => TEST_REPO_PATH, - 'gitaly-gl-repository' => 'project-52', - 'gitaly-repo-alt-dirs' => '' - } - end - let(:call) { double(metadata: call_metadata) } - - it 'cleans up the repository' do - described_class.from_gitaly_with_block(test_repo_read_only, call) do |repository| - expect(repository.rugged).to receive(:close) - end - end - - it 'returns the passed result of the block passed' do - result = described_class.from_gitaly_with_block(test_repo_read_only, call) { 'Hello world' } - - expect(result).to eq('Hello world') - end - end - - describe "Respond to" do - subject { repository } - - it { is_expected.to respond_to(:root_ref) } - it { is_expected.to respond_to(:tags) } - end - - describe '#root_ref' do - it 'calls #discover_default_branch' do - expect(repository).to receive(:discover_default_branch) - repository.root_ref - end - end - - describe '#branch_names' do - subject { repository.branch_names } - - it 'has SeedRepo::Repo::BRANCHES.size elements' do - expect(subject.size).to eq(SeedRepo::Repo::BRANCHES.size) - end - - it { is_expected.to include("master") } - it { is_expected.not_to include("branch-from-space") } - end - - describe '#tags' do - describe 'first tag' do - let(:tag) { repository.tags.first } - - it { expect(tag.name).to eq("v1.0.0") } - it { expect(tag.target).to eq("f4e6814c3e4e7a0de82a9e7cd20c626cc963a2f8") } - it { expect(tag.dereferenced_target.sha).to eq("6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9") } - it { expect(tag.message).to eq("Release") } - end - - describe 'last tag' do - let(:tag) { repository.tags.last } - - it { expect(tag.name).to eq("v1.2.1") } - it { expect(tag.target).to eq("2ac1f24e253e08135507d0830508febaaccf02ee") } - it { expect(tag.dereferenced_target.sha).to eq("fa1b1e6c004a68b7d8763b86455da9e6b23e36d6") } - it { expect(tag.message).to eq("Version 1.2.1") } - end - - it { expect(repository.tags.size).to eq(SeedRepo::Repo::TAGS.size) } - end - - describe '#empty?' do - it { expect(repository).not_to be_empty } - end - - describe '#merge_base' do - where(:from, :to, :result) do - '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' | '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' - '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' - '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | 'foobar' | nil - 'foobar' | '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | nil - end - - with_them do - it { expect(repository.merge_base(from, to)).to eq(result) } - end - end - - describe '#find_branch' do - it 'should return a Branch for master' do - branch = repository.find_branch('master') - - expect(branch).to be_a_kind_of(Gitlab::Git::Branch) - expect(branch.name).to eq('master') - end - - it 'should handle non-existent branch' do - branch = repository.find_branch('this-is-garbage') - - expect(branch).to eq(nil) - end - end - - describe '#branches' do - subject { repository.branches } - - context 'with local and remote branches' do - let(:repository) { mutable_repository } - - before do - create_remote_branch('joe', 'remote_branch', 'master') - create_branch(repository, 'local_branch', 'master') - end - - it 'returns the local and remote branches' do - expect(subject.any? { |b| b.name == 'joe/remote_branch' }).to eq(true) - expect(subject.any? { |b| b.name == 'local_branch' }).to eq(true) - end - end - end - - describe '#branch_exists?' do - it 'returns true for an existing branch' do - expect(repository.branch_exists?('master')).to eq(true) - end - - it 'returns false for a non-existing branch' do - expect(repository.branch_exists?('kittens')).to eq(false) - end - - it 'returns false when using an invalid branch name' do - expect(repository.branch_exists?('.bla')).to eq(false) - end - end - - describe '#with_repo_branch_commit' do - context 'when repository is empty' do - let(:repository) { gitlab_git_from_gitaly(new_empty_test_repo) } - - it 'yields nil' do - expect do |block| - repository.with_repo_branch_commit('master', &block) - end.to yield_with_args(nil) - end - end - - context 'when repository is not empty' do - let(:start_commit) { repository.commit } - - it 'yields the commit for the SHA' do - expect do |block| - repository.with_repo_branch_commit(start_commit.sha, &block) - end.to yield_with_args(start_commit) - end - - it 'yields the commit for the branch' do - expect do |block| - repository.with_repo_branch_commit('master', &block) - end.to yield_with_args(start_commit) - end - end - end - - describe '#cleanup' do - context 'when Rugged has been called' do - it 'calls close on Rugged::Repository' do - rugged = repository.rugged - - expect(rugged).to receive(:close).and_call_original - - repository.cleanup - end - end - - context 'when Rugged has not been called' do - it 'does not call close on Rugged::Repository' do - expect(repository).not_to receive(:rugged) - - repository.cleanup - end - end - end - - describe '#rugged' do - after do - Thread.current[described_class::RUGGED_KEY] = nil - end - - it 'stores reference in Thread.current' do - Thread.current[described_class::RUGGED_KEY] = [] - - 2.times do - rugged = repository.rugged - - expect(rugged).to be_a(Rugged::Repository) - expect(Thread.current[described_class::RUGGED_KEY]).to eq([rugged]) - end - end - - it 'does not store reference if Thread.current is not set up' do - rugged = repository.rugged - - expect(rugged).to be_a(Rugged::Repository) - expect(Thread.current[described_class::RUGGED_KEY]).to be_nil - end - end - - describe '#head_symbolic_ref' do - subject { repository.head_symbolic_ref } - - it 'returns the symbolic ref in HEAD' do - expect(subject).to eq('master') - end - - context 'when repo is empty' do - let(:repository) { gitlab_git_from_gitaly(new_empty_test_repo) } - - it 'returns the symbolic ref in HEAD' do - repository.rugged.head = 'refs/heads/foo' - - expect(subject).to eq('foo') - end - end - end - - def create_remote_branch(remote_name, branch_name, source_branch_name) - source_branch = repository.branches.find { |branch| branch.name == source_branch_name } - repository_rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha) - end - - def create_branch(repository, branch_name, start_point = 'HEAD') - repository.rugged.branches.create(branch_name, start_point) - end -end diff --git a/ruby/spec/lib/gitlab/git/user_spec.rb b/ruby/spec/lib/gitlab/git/user_spec.rb deleted file mode 100644 index 778fc3c80..000000000 --- a/ruby/spec/lib/gitlab/git/user_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::User do - let(:username) { 'janedoe' } - let(:name) { 'Jane Doé' } - let(:email) { 'janedoé@example.com' } - let(:gl_id) { 'user-123' } - let(:user) do - described_class.new(username, name, email, gl_id) - end - - subject { described_class.new(username, name, email, gl_id) } - - describe '.from_gitaly' do - let(:gitaly_user) do - Gitaly::User.new(gl_username: username, name: name.b, email: email.b, gl_id: gl_id) - end - - subject { described_class.from_gitaly(gitaly_user) } - - it { expect(subject).to eq(user) } - end - - describe '#==' do - def eq_other(username, name, email, gl_id) - eq(described_class.new(username, name, email, gl_id)) - end - - it { expect(subject).to eq_other(username, name, email, gl_id) } - - it { expect(subject).not_to eq_other(nil, nil, nil, nil) } - it { expect(subject).not_to eq_other(username + 'x', name, email, gl_id) } - it { expect(subject).not_to eq_other(username, name + 'x', email, gl_id) } - it { expect(subject).not_to eq_other(username, name, email + 'x', gl_id) } - it { expect(subject).not_to eq_other(username, name, email, gl_id + 'x') } - end - - describe '#git_env' do - let(:git_env) { subject.git_env } - - it 'returns the user environment variables' do - expect(git_env['GIT_COMMITTER_NAME']).to eq(name) - expect(git_env['GIT_COMMITTER_EMAIL']).to eq(email) - expect(git_env['GL_ID']).to eq(gl_id) - end - end -end |