mirror of https://github.com/licensee/licensee.git
Merge pull request #39 from benbalter/no-license
Properly return nil from license_hash when no_license is found
This commit is contained in:
commit
67ed5ecf8f
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ref: refs/heads/master
|
|
@ -0,0 +1,6 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
BIN
test/fixtures/no-license.git/objects/82/0c999cf27a6f71431646c404274c578f7a2869
vendored
Normal file
BIN
test/fixtures/no-license.git/objects/82/0c999cf27a6f71431646c404274c578f7a2869
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/no-license.git/objects/e1/d9b2a3d41c2ea74a520e66da2b5c63b2f6202f
vendored
Normal file
BIN
test/fixtures/no-license.git/objects/e1/d9b2a3d41c2ea74a520e66da2b5c63b2f6202f
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/no-license.git/objects/ff/1592f44259635df9feda5e02853964b26f9e4d
vendored
Normal file
BIN
test/fixtures/no-license.git/objects/ff/1592f44259635df9feda5e02853964b26f9e4d
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
e1d9b2a3d41c2ea74a520e66da2b5c63b2f6202f
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue