Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-10-15 06:00:48 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-10-30 19:30:00 +0300
commit9dade0bc0f2b4259cdcd52bd4f68a81e161745ed (patch)
tree9bd0166c86af927f2981b00de46bbf3b7e1e34ef
parent800dbbe9360fe7acd26d45d9b382cb61b54965ec (diff)
Add user spec examples and remove unused code
-rw-r--r--ruby/lib/gitlab/git/operation_service.rb5
-rw-r--r--ruby/lib/gitlab/git/repository.rb2
-rw-r--r--ruby/lib/gitlab/git/user.rb8
-rw-r--r--ruby/spec/lib/gitlab/git/user_spec.rb47
4 files changed, 48 insertions, 14 deletions
diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb
index c7a24958f..649337dd9 100644
--- a/ruby/lib/gitlab/git/operation_service.rb
+++ b/ruby/lib/gitlab/git/operation_service.rb
@@ -21,10 +21,7 @@ module Gitlab
attr_reader :user, :repository
def initialize(user, new_repository)
- if user
- user = Gitlab::Git::User.from_gitlab(user) unless user.respond_to?(:gl_id)
- @user = user
- end
+ @user = user
# Refactoring aid
Gitlab::Git.check_namespace!(new_repository)
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index 22723943e..e15e3658c 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -315,8 +315,6 @@ module Gitlab
target_object = Ref.dereference_object(lookup(target))
raise InvalidRef, "target not found: #{target}" unless target_object
- user = Gitlab::Git::User.from_gitlab(user) unless user.respond_to?(:gl_id)
-
options = nil # Use nil, not the empty hash. Rugged cares about this.
if message
options = {
diff --git a/ruby/lib/gitlab/git/user.rb b/ruby/lib/gitlab/git/user.rb
index 41e14dca8..9ed75f7f7 100644
--- a/ruby/lib/gitlab/git/user.rb
+++ b/ruby/lib/gitlab/git/user.rb
@@ -3,10 +3,6 @@ module Gitlab
class User
attr_reader :username, :name, :email, :gl_id
- def self.from_gitlab(gitlab_user)
- new(gitlab_user.username, gitlab_user.name, gitlab_user.email, Gitlab::GlId.gl_id(gitlab_user))
- end
-
def self.from_gitaly(gitaly_user)
new(
gitaly_user.gl_username,
@@ -27,10 +23,6 @@ module Gitlab
[username, name, email, gl_id] == [other.username, other.name, other.email, other.gl_id]
end
- def to_gitaly
- Gitaly::User.new(gl_username: username, gl_id: gl_id, name: name.b, email: email.b)
- end
-
def git_env
{
'GIT_COMMITTER_NAME' => name,
diff --git a/ruby/spec/lib/gitlab/git/user_spec.rb b/ruby/spec/lib/gitlab/git/user_spec.rb
new file mode 100644
index 000000000..778fc3c80
--- /dev/null
+++ b/ruby/spec/lib/gitlab/git/user_spec.rb
@@ -0,0 +1,47 @@
+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