summaryrefslogtreecommitdiff
path: root/spec/models/repository_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb184
1 files changed, 168 insertions, 16 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index c163001b7c1..34a13f9b5c9 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -132,25 +132,92 @@ describe Repository, models: true do
it { expect(subject.basename).to eq('a/b/c') }
end
end
+ end
+
+ describe "#changelog" do
+ before do
+ repository.send(:cache).expire(:changelog)
+ end
+
+ it 'accepts changelog' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('changelog')])
+
+ expect(repository.changelog.name).to eq('changelog')
+ end
+
+ it 'accepts news instead of changelog' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('news')])
+
+ expect(repository.changelog.name).to eq('news')
+ end
+ it 'accepts history instead of changelog' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('history')])
+
+ expect(repository.changelog.name).to eq('history')
+ end
+
+ it 'accepts changes instead of changelog' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('changes')])
+
+ expect(repository.changelog.name).to eq('changes')
+ end
+
+ it 'is case-insensitive' do
+ expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('CHANGELOG')])
+
+ expect(repository.changelog.name).to eq('CHANGELOG')
+ end
end
- describe "#license" do
+ describe "#license_blob" do
before do
- repository.send(:cache).expire(:license)
+ repository.send(:cache).expire(:license_blob)
+ repository.remove_file(user, 'LICENSE', 'Remove LICENSE', 'master')
end
- it 'test selection preference' do
- files = [TestBlob.new('file'), TestBlob.new('license'), TestBlob.new('copying')]
- expect(repository.tree).to receive(:blobs).and_return(files)
+ it 'looks in the root_ref only' do
+ repository.remove_file(user, 'LICENSE', 'Remove LICENSE', 'markdown')
+ repository.commit_file(user, 'LICENSE', Licensee::License.new('mit').content, 'Add LICENSE', 'markdown', false)
+
+ expect(repository.license_blob).to be_nil
+ end
+
+ it 'detects license file with no recognizable open-source license content' do
+ repository.commit_file(user, 'LICENSE', 'Copyright!', 'Add LICENSE', 'master', false)
+
+ expect(repository.license_blob.name).to eq('LICENSE')
+ end
+
+ %w[LICENSE LICENCE LiCensE LICENSE.md LICENSE.foo COPYING COPYING.md].each do |filename|
+ it "detects '#{filename}'" do
+ repository.commit_file(user, filename, Licensee::License.new('mit').content, "Add #{filename}", 'master', false)
+
+ expect(repository.license_blob.name).to eq(filename)
+ end
+ end
+ end
+
+ describe '#license_key' do
+ before do
+ repository.send(:cache).expire(:license_key)
+ repository.remove_file(user, 'LICENSE', 'Remove LICENSE', 'master')
+ end
+
+ it 'returns nil when no license is detected' do
+ expect(repository.license_key).to be_nil
+ end
+
+ it 'detects license file with no recognizable open-source license content' do
+ repository.commit_file(user, 'LICENSE', 'Copyright!', 'Add LICENSE', 'master', false)
- expect(repository.license.name).to eq('license')
+ expect(repository.license_key).to be_nil
end
- it 'also accepts licence instead of license' do
- expect(repository.tree).to receive(:blobs).and_return([TestBlob.new('licence')])
+ it 'returns the license key' do
+ repository.commit_file(user, 'LICENSE', Licensee::License.new('mit').content, 'Add LICENSE', 'master', false)
- expect(repository.license.name).to eq('licence')
+ expect(repository.license_key).to eq('mit')
end
end
@@ -494,7 +561,7 @@ describe Repository, models: true do
end
describe :skip_merged_commit do
- subject { repository.commits(Gitlab::Git::BRANCH_REF_PREFIX + "'test'", nil, 100, 0, true).map{ |k| k.id } }
+ subject { repository.commits(Gitlab::Git::BRANCH_REF_PREFIX + "'test'", limit: 100, skip_merges: true).map{ |k| k.id } }
it { is_expected.not_to include('e56497bb5f03a90a51293fc6d516788730953899') }
end
@@ -541,6 +608,41 @@ describe Repository, models: true do
end
end
+ describe '#cherry_pick' do
+ let(:conflict_commit) { repository.commit('c642fe9b8b9f28f9225d7ea953fe14e74748d53b') }
+ let(:pickable_commit) { repository.commit('7d3b0f7cff5f37573aea97cebfd5692ea1689924') }
+ let(:pickable_merge) { repository.commit('e56497bb5f03a90a51293fc6d516788730953899') }
+
+ context 'when there is a conflict' do
+ it 'should abort the operation' do
+ expect(repository.cherry_pick(user, conflict_commit, 'master')).to eq(false)
+ end
+ end
+
+ context 'when commit was already cherry-picked' do
+ it 'should abort the operation' do
+ repository.cherry_pick(user, pickable_commit, 'master')
+
+ expect(repository.cherry_pick(user, pickable_commit, 'master')).to eq(false)
+ end
+ end
+
+ context 'when commit can be cherry-picked' do
+ it 'should cherry-pick the changes' do
+ expect(repository.cherry_pick(user, pickable_commit, 'master')).to be_truthy
+ end
+ end
+
+ context 'cherry-picking a merge commit' do
+ it 'should cherry-pick the changes' do
+ expect(repository.blob_at_branch('master', 'foo/bar/.gitkeep')).to be_nil
+
+ repository.cherry_pick(user, pickable_merge, 'master')
+ expect(repository.blob_at_branch('master', 'foo/bar/.gitkeep')).not_to be_nil
+ end
+ end
+ end
+
describe '#before_delete' do
describe 'when a repository does not exist' do
before do
@@ -693,6 +795,16 @@ describe Repository, models: true do
end
+ describe "#copy_gitattributes" do
+ it 'returns true with a valid ref' do
+ expect(repository.copy_gitattributes('master')).to be_truthy
+ end
+
+ it 'returns false with an invalid ref' do
+ expect(repository.copy_gitattributes('invalid')).to be_falsey
+ end
+ end
+
describe "#main_language" do
it 'shows the main language of the project' do
expect(repository.main_language).to eq("Ruby")
@@ -746,13 +858,30 @@ describe Repository, models: true do
end
describe '#add_tag' do
- it 'adds a tag' do
- expect(repository).to receive(:before_push_tag)
+ context 'with a valid target' do
+ let(:user) { build_stubbed(:user) }
- expect_any_instance_of(Gitlab::Shell).to receive(:add_tag).
- with(repository.path_with_namespace, '8.5', 'master', 'foo')
+ it 'creates the tag using rugged' do
+ expect(repository.rugged.tags).to receive(:create).
+ with('8.5', repository.commit('master').id,
+ hash_including(message: 'foo',
+ tagger: hash_including(name: user.name, email: user.email))).
+ and_call_original
- repository.add_tag('8.5', 'master', 'foo')
+ repository.add_tag(user, '8.5', 'master', 'foo')
+ end
+
+ it 'returns a Gitlab::Git::Tag object' do
+ tag = repository.add_tag(user, '8.5', 'master', 'foo')
+
+ expect(tag).to be_a(Gitlab::Git::Tag)
+ end
+ end
+
+ context 'with an invalid target' do
+ it 'returns false' do
+ expect(repository.add_tag(user, '8.5', 'bar', 'foo')).to be false
+ end
end
end
@@ -910,9 +1039,32 @@ describe Repository, models: true do
end
end
+ describe '.clean_old_archives' do
+ let(:path) { Gitlab.config.gitlab.repository_downloads_path }
+
+ context 'when the downloads directory does not exist' do
+ it 'does not remove any archives' do
+ expect(File).to receive(:directory?).with(path).and_return(false)
+
+ expect(Gitlab::Popen).not_to receive(:popen)
+
+ described_class.clean_old_archives
+ end
+ end
+
+ context 'when the downloads directory exists' do
+ it 'removes old archives' do
+ expect(File).to receive(:directory?).with(path).and_return(true)
+
+ expect(Gitlab::Popen).to receive(:popen)
+
+ described_class.clean_old_archives
+ end
+ end
+ end
+
def create_remote_branch(remote_name, branch_name, target)
rugged = repository.rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target)
end
-
end