summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/auth/request_authenticator_spec.rb10
-rw-r--r--spec/lib/gitlab/auth/user_auth_finders_spec.rb46
-rw-r--r--spec/lib/gitlab/bitbucket_import/importer_spec.rb30
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb6
-rw-r--r--spec/lib/gitlab/git/commit_spec.rb4
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb4
-rw-r--r--spec/lib/gitlab/gitlab_import/importer_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml5
-rw-r--r--spec/lib/gitlab/import_export/relation_factory_spec.rb19
-rw-r--r--spec/lib/gitlab/import_export/safe_model_attributes.yml13
10 files changed, 117 insertions, 24 deletions
diff --git a/spec/lib/gitlab/auth/request_authenticator_spec.rb b/spec/lib/gitlab/auth/request_authenticator_spec.rb
index ffcd90b9fcb..242ab4a91dd 100644
--- a/spec/lib/gitlab/auth/request_authenticator_spec.rb
+++ b/spec/lib/gitlab/auth/request_authenticator_spec.rb
@@ -39,19 +39,19 @@ describe Gitlab::Auth::RequestAuthenticator do
describe '#find_sessionless_user' do
let!(:access_token_user) { build(:user) }
- let!(:rss_token_user) { build(:user) }
+ let!(:feed_token_user) { build(:user) }
it 'returns access_token user first' do
allow_any_instance_of(described_class).to receive(:find_user_from_access_token).and_return(access_token_user)
- allow_any_instance_of(described_class).to receive(:find_user_from_rss_token).and_return(rss_token_user)
+ allow_any_instance_of(described_class).to receive(:find_user_from_feed_token).and_return(feed_token_user)
expect(subject.find_sessionless_user).to eq access_token_user
end
- it 'returns rss_token user if no access_token user found' do
- allow_any_instance_of(described_class).to receive(:find_user_from_rss_token).and_return(rss_token_user)
+ it 'returns feed_token user if no access_token user found' do
+ allow_any_instance_of(described_class).to receive(:find_user_from_feed_token).and_return(feed_token_user)
- expect(subject.find_sessionless_user).to eq rss_token_user
+ expect(subject.find_sessionless_user).to eq feed_token_user
end
it 'returns nil if no user found' do
diff --git a/spec/lib/gitlab/auth/user_auth_finders_spec.rb b/spec/lib/gitlab/auth/user_auth_finders_spec.rb
index 2733eef6611..136646bd4ee 100644
--- a/spec/lib/gitlab/auth/user_auth_finders_spec.rb
+++ b/spec/lib/gitlab/auth/user_auth_finders_spec.rb
@@ -46,34 +46,54 @@ describe Gitlab::Auth::UserAuthFinders do
end
end
- describe '#find_user_from_rss_token' do
+ describe '#find_user_from_feed_token' do
context 'when the request format is atom' do
before do
env['HTTP_ACCEPT'] = 'application/atom+xml'
end
- it 'returns user if valid rss_token' do
- set_param(:rss_token, user.rss_token)
+ context 'when feed_token param is provided' do
+ it 'returns user if valid feed_token' do
+ set_param(:feed_token, user.feed_token)
- expect(find_user_from_rss_token).to eq user
- end
+ expect(find_user_from_feed_token).to eq user
+ end
+
+ it 'returns nil if feed_token is blank' do
+ expect(find_user_from_feed_token).to be_nil
+ end
+
+ it 'returns exception if invalid feed_token' do
+ set_param(:feed_token, 'invalid_token')
- it 'returns nil if rss_token is blank' do
- expect(find_user_from_rss_token).to be_nil
+ expect { find_user_from_feed_token }.to raise_error(Gitlab::Auth::UnauthorizedError)
+ end
end
- it 'returns exception if invalid rss_token' do
- set_param(:rss_token, 'invalid_token')
+ context 'when rss_token param is provided' do
+ it 'returns user if valid rssd_token' do
+ set_param(:rss_token, user.feed_token)
- expect { find_user_from_rss_token }.to raise_error(Gitlab::Auth::UnauthorizedError)
+ expect(find_user_from_feed_token).to eq user
+ end
+
+ it 'returns nil if rss_token is blank' do
+ expect(find_user_from_feed_token).to be_nil
+ end
+
+ it 'returns exception if invalid rss_token' do
+ set_param(:rss_token, 'invalid_token')
+
+ expect { find_user_from_feed_token }.to raise_error(Gitlab::Auth::UnauthorizedError)
+ end
end
end
context 'when the request format is not atom' do
it 'returns nil' do
- set_param(:rss_token, user.rss_token)
+ set_param(:feed_token, user.feed_token)
- expect(find_user_from_rss_token).to be_nil
+ expect(find_user_from_feed_token).to be_nil
end
end
@@ -81,7 +101,7 @@ describe Gitlab::Auth::UserAuthFinders do
it 'the method call does not modify the original value' do
env['action_dispatch.request.formats'] = nil
- find_user_from_rss_token
+ find_user_from_feed_token
expect(env['action_dispatch.request.formats']).to be_nil
end
diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb
index c63120b0b29..05c232d22cf 100644
--- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb
+++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb
@@ -19,6 +19,18 @@ describe Gitlab::BitbucketImport::Importer do
]
end
+ let(:reporters) do
+ [
+ nil,
+ { "username" => "reporter1" },
+ nil,
+ { "username" => "reporter2" },
+ { "username" => "reporter1" },
+ nil,
+ { "username" => "reporter3" }
+ ]
+ end
+
let(:sample_issues_statuses) do
issues = []
@@ -36,6 +48,10 @@ describe Gitlab::BitbucketImport::Importer do
}
end
+ reporters.map.with_index do |reporter, index|
+ issues[index]['reporter'] = reporter
+ end
+
issues
end
@@ -147,5 +163,19 @@ describe Gitlab::BitbucketImport::Importer do
expect(importer.errors).to be_empty
end
end
+
+ describe 'issue import' do
+ it 'maps reporters to anonymous if bitbucket reporter is nil' do
+ allow(importer).to receive(:import_wiki)
+ importer.execute
+
+ expect(project.issues.size).to eq(7)
+ expect(project.issues.where("description LIKE ?", '%Anonymous%').size).to eq(3)
+ expect(project.issues.where("description LIKE ?", '%reporter1%').size).to eq(2)
+ expect(project.issues.where("description LIKE ?", '%reporter2%').size).to eq(1)
+ expect(project.issues.where("description LIKE ?", '%reporter3%').size).to eq(1)
+ expect(importer.errors).to be_empty
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index e2547ed0311..94eaf86ef80 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -22,6 +22,12 @@ describe Gitlab::Git::Blob, seed_helper: true do
it { expect(blob).to eq(nil) }
end
+ context 'utf-8 branch' do
+ let(:blob) { Gitlab::Git::Blob.find(repository, 'Ääh-test-utf-8', "files/ruby/popen.rb")}
+
+ it { expect(blob.id).to eq(SeedRepo::RubyBlob::ID) }
+ end
+
context 'blank path' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, '') }
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb
index 08c6d1e55e9..89be8a1b7f2 100644
--- a/spec/lib/gitlab/git/commit_spec.rb
+++ b/spec/lib/gitlab/git/commit_spec.rb
@@ -603,8 +603,8 @@ describe Gitlab::Git::Commit, seed_helper: true do
let(:commit) { described_class.find(repository, 'master') }
subject { commit.ref_names(repository) }
- it 'has 1 element' do
- expect(subject.size).to eq(1)
+ it 'has 2 element' do
+ expect(subject.size).to eq(2)
end
it { is_expected.to include("master") }
it { is_expected.not_to include("feature") }
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index af6a486ab20..dd5c498706d 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1374,7 +1374,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#branch_count' do
it 'returns the number of branches' do
- expect(repository.branch_count).to eq(10)
+ expect(repository.branch_count).to eq(11)
end
context 'with local and remote branches' do
@@ -2248,7 +2248,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
describe '#checksum' do
it 'calculates the checksum for non-empty repo' do
- expect(repository.checksum).to eq '54f21be4c32c02f6788d72207fa03ad3bce725e4'
+ expect(repository.checksum).to eq '4be7d24ce7e8d845502d599b72d567d23e6a40c0'
end
it 'returns 0000000000000000000000000000000000000000 for an empty repo' do
diff --git a/spec/lib/gitlab/gitlab_import/importer_spec.rb b/spec/lib/gitlab/gitlab_import/importer_spec.rb
index e1d935602b5..200edceca8c 100644
--- a/spec/lib/gitlab/gitlab_import/importer_spec.rb
+++ b/spec/lib/gitlab/gitlab_import/importer_spec.rb
@@ -20,7 +20,7 @@ describe Gitlab::GitlabImport::Importer do
}
}
])
- stub_request('issues/2579857/notes', [])
+ stub_request('issues/3/notes', [])
end
it 'persists issues' do
@@ -43,7 +43,7 @@ describe Gitlab::GitlabImport::Importer do
end
def stub_request(path, body)
- url = "https://gitlab.com/api/v3/projects/asd%2Fvim/#{path}?page=1&per_page=100"
+ url = "https://gitlab.com/api/v4/projects/asd%2Fvim/#{path}?page=1&per_page=100"
WebMock.stub_request(:get, url)
.to_return(
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index fb5fd300dbb..a129855dbd8 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -310,3 +310,8 @@ lfs_file_locks:
- user
project_badges:
- project
+metrics:
+- merge_request
+- latest_closed_by
+- merged_by
+- pipeline
diff --git a/spec/lib/gitlab/import_export/relation_factory_spec.rb b/spec/lib/gitlab/import_export/relation_factory_spec.rb
index 5f0dfd64b15..cf9e0f71910 100644
--- a/spec/lib/gitlab/import_export/relation_factory_spec.rb
+++ b/spec/lib/gitlab/import_export/relation_factory_spec.rb
@@ -119,6 +119,25 @@ describe Gitlab::ImportExport::RelationFactory do
end
end
+ context 'overrided model with pluralized name' do
+ let(:relation_sym) { :metrics }
+
+ let(:relation_hash) do
+ {
+ 'id' => 99,
+ 'merge_request_id' => 99,
+ 'merged_at' => Time.now,
+ 'merged_by_id' => 99,
+ 'latest_closed_at' => nil,
+ 'latest_closed_by_id' => nil
+ }
+ end
+
+ it 'does not raise errors' do
+ expect { created_object }.not_to raise_error
+ end
+ end
+
context 'Project references' do
let(:relation_sym) { :project_foo_model }
let(:relation_hash) do
diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml
index 3d5271cd030..74e7a45fd6c 100644
--- a/spec/lib/gitlab/import_export/safe_model_attributes.yml
+++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml
@@ -205,6 +205,19 @@ MergeRequestDiffFile:
- b_mode
- too_large
- binary
+MergeRequest::Metrics:
+- id
+- created_at
+- updated_at
+- merge_request_id
+- pipeline_id
+- latest_closed_by_id
+- latest_closed_at
+- merged_by_id
+- merged_at
+- latest_build_started_at
+- latest_build_finished_at
+- first_deployed_to_production_at
Ci::Pipeline:
- id
- project_id