diff options
author | Robert Speicher <robert@gitlab.com> | 2016-04-20 01:38:49 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-04-20 01:38:49 +0000 |
commit | 3d4875f86a3b23789f5ea801c096754fced25166 (patch) | |
tree | 3d3c370437a606dcdf2498546f5efd1f13eb44b6 /spec/models | |
parent | 9617c274ab301e4d2401b2d9a179f40649259d3c (diff) | |
parent | 50bee8e9198f65a692e32710a32089270e166f6b (diff) | |
download | gitlab-ce-3d4875f86a3b23789f5ea801c096754fced25166.tar.gz |
Merge branch 'license-templates-and-api-12804' into 'master'
License templates when creating/editing a LICENSE file
Closes #12804
See merge request !3660
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/repository_spec.rb | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 35d7dcd8aea..b561aa663d1 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -135,22 +135,69 @@ describe Repository, models: true do 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 'favors license file with no extension' do + repository.commit_file(user, 'LICENSE', Licensee::License.new('mit').content, 'Add LICENSE', 'master', false) + repository.commit_file(user, 'LICENSE.md', Licensee::License.new('mit').content, 'Add LICENSE.md', 'master', false) + + expect(repository.license_blob.name).to eq('LICENSE') + end + + it 'favors .md file to .txt' do + repository.commit_file(user, 'LICENSE.md', Licensee::License.new('mit').content, 'Add LICENSE.md', 'master', false) + repository.commit_file(user, 'LICENSE.txt', Licensee::License.new('mit').content, 'Add LICENSE.txt', 'master', false) + + expect(repository.license_blob.name).to eq('LICENSE.md') + end + + it 'favors LICENCE to LICENSE' do + repository.commit_file(user, 'LICENSE', Licensee::License.new('mit').content, 'Add LICENSE', 'master', false) + repository.commit_file(user, 'LICENCE', Licensee::License.new('mit').content, 'Add LICENCE', 'master', false) + + expect(repository.license_blob.name).to eq('LICENCE') + end + + it 'favors LICENSE to COPYING' do + repository.commit_file(user, 'LICENSE', Licensee::License.new('mit').content, 'Add LICENSE', 'master', false) + repository.commit_file(user, 'COPYING', Licensee::License.new('mit').content, 'Add COPYING', 'master', false) + + expect(repository.license_blob.name).to eq('LICENSE') + end + + it 'favors LICENCE to COPYING' do + repository.commit_file(user, 'LICENCE', Licensee::License.new('mit').content, 'Add LICENCE', 'master', false) + repository.commit_file(user, 'COPYING', Licensee::License.new('mit').content, 'Add COPYING', 'master', false) + + expect(repository.license_blob.name).to eq('LICENCE') + end + end + + describe '#license_key' do + before do + repository.send(:cache).expire(:license_key) + repository.remove_file(user, 'LICENSE', 'Remove LICENSE', 'master') + end - expect(repository.license.name).to eq('license') + it 'returns "no-license" when no license is detected' do + expect(repository.license_key).to eq('no-license') 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 |