Merge pull request #39 from benbalter/no-license

Properly return nil from license_hash when no_license is found
This commit is contained in:
Ben Balter 2015-07-20 19:15:07 -04:00
commit 67ed5ecf8f
9 changed files with 31 additions and 20 deletions

View File

@ -62,7 +62,9 @@ class Licensee
# Detects the license file, if any
# Returns the blob hash as detected in the tree
def license_hash
tree.sort_by { |blob| self.class.match_license_file(blob[:name]) }.last
hashes = tree.map { |blob| [self.class.match_license_file(blob[:name]), blob] }
hash = hashes.select { |hash| hash[0] > 0 }.sort_by { |hash| hash[0] }.last
hash[1] if hash
end
def license_blob

1
test/fixtures/no-license.git/HEAD vendored Normal file
View File

@ -0,0 +1 @@
ref: refs/heads/master

6
test/fixtures/no-license.git/config vendored Normal file
View File

@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true

View File

@ -0,0 +1 @@
e1d9b2a3d41c2ea74a520e66da2b5c63b2f6202f

View File

@ -76,6 +76,10 @@ class TestLicenseeProject < Minitest::Test
assert_equal "mit", project.license.key
end
should "detect an unlicensed project" do
project = make_project "no-license.git", as_git
assert_equal nil, project.license
end
end
end

View File

@ -1,31 +1,28 @@
require 'helper'
class TestLicenseeVendor < Minitest::Test
should "detect each vendored license" do
licenses = Dir["#{Licensee::Licenses.base}/*"].shuffle
licenses.each do |license|
Dir["#{Licensee::Licenses.base}/*"].shuffle.each do |license|
should "detect the #{license} license" do
verify_license_file(license)
end
end
should "detect each vendored license when modified" do
licenses = Dir["#{Licensee::Licenses.base}/*"].shuffle
licenses.each do |license|
verify_license_file(license, true) unless license =~ /no-license\.txt$/
context "when modified" do
should "detect the #{license} license" do
verify_license_file(license, true) unless license =~ /no-license\.txt$/
end
end
end
should "detect each vendored license with different line lengths" do
licenses = Dir["#{Licensee::Licenses.base}/*"].shuffle
licenses.each do |license|
verify_license_file(license, false, 50)
end
end
context "different line lengths" do
should "detect the #{license} license" do
verify_license_file(license, false, 50)
end
should "detect each vendored license with different line lengths when modified" do
licenses = Dir["#{Licensee::Licenses.base}/*"].shuffle
licenses.each do |license|
verify_license_file(license, true, 50) unless license =~ /no-license\.txt$/
context "when modified" do
should "detect the #{license} license" do
verify_license_file(license, true, 50) unless license =~ /no-license\.txt$/
end
end
end
end
end