Permalink
Browse files

fix approval/license setting bug when merging

  • Loading branch information...
1 parent 1d42bf3 commit 6c751c779cd94244c60d0aa4799900529e0067e9 Matthew Kane Parker committed Sep 25, 2012
@@ -7,7 +7,10 @@ Feature: Approving non-whitelisted Dependencies
Given I have an app with license finder
And my app depends on a gem "gpl_gem" licensed with "GPL"
When I run "license_finder"
+ Then I should see "gpl_gem" in its output
When I run "license_finder -a gpl_gem"
+ When I run "license_finder"
+ Then I should not see "gpl_gem" in its output
Then I should see the "gpl_gem" in the html flagged as "approved"
Scenario: Manually approving a non-whitelisted dependency
@@ -38,7 +38,9 @@ Feature: License Finder command line executable
Scenario: Auditing an application with whitelisted licenses
Given I have an app with license finder
And my app depends on a gem "mit_licensed_gem" licensed with "MIT"
- And I whitelist the following licenses: "MIT, other"
When I run "license_finder"
- Then it should exit with status code 0
- And I should see "All gems are approved for use" in its output
+ Then I should see "mit_licensed_gem" in its output
+ When I whitelist the following licenses: "MIT, other"
+ And I run "license_finder"
+ Then I should see "All gems are approved for use" in its output
+ And it should exit with status code 0
@@ -1,8 +1,7 @@
module LicenseFinder
class Dependency < LicenseFinder::Persistence::Dependency
def approved
- return super unless super.nil?
-
+ return super if super
self.approved = LicenseFinder.config.whitelist.include?(license)
end
@@ -38,12 +37,13 @@ def license_url
def merge(other)
raise "Cannot merge dependencies with different names. Expected #{name}, was #{other.name}." unless other.name == name
- new_attributes = other.attributes.merge(:notes => notes)
+ new_attributes = other.attributes.merge("notes" => notes)
if other.license == license || other.license == 'other'
- new_attributes[:approved] = approved
+ new_attributes["approved"] = approved
+ new_attributes["license"] = license
else
- new_attributes[:approved] = nil
+ new_attributes["approved"] = nil
end
update_attributes new_attributes
@@ -109,29 +109,51 @@ module LicenseFinder
merged.notes.should == 'old notes'
end
- it 'should return the new license and approval if the license is different' do
- subject.license = "MIT"
- subject.approved = true
+ context "license changes to something other than 'other'" do
+ before { new_dep.license = 'new license' }
- new_dep.license = "GPLv2"
- new_dep.approved = false
+ context "new license is whitelisted" do
+ before { LicenseFinder.config.stub(:whitelist).and_return [new_dep.license] }
- merged = subject.merge(new_dep)
+ it "should set the approval to true" do
+ merged = subject.merge new_dep
+ merged.should be_approved
+ end
+ end
- merged.license.should == "GPLv2"
- merged.approved.should == false
+ context "new license is not whitelisted" do
+ it "should set the approval to false" do
+ merged = subject.merge new_dep
+ merged.should_not be_approved
+ end
+ end
end
- it 'should return the old license and approval if the new license is the same or "other"' do
- subject.approved = false
- subject.approved.should be_false
- new_dep.approved = true
+ context "license changes to unknown (i.e., 'other')" do
+ before { new_dep.license = 'other' }
- subject.merge(new_dep).approved.should == false
+ it "should not change the license" do
+ merged = subject.merge new_dep
+ merged.license.should == 'MIT'
+ end
- new_dep.license = 'other'
+ it "should not change the approval" do
+ approved = subject.approved?
+ merged = subject.merge new_dep
+ merged.approved?.should == approved
+ end
+ end
- subject.merge(new_dep).approved.should == false
+ context "license does not change" do
+ before { new_dep.license.should == subject.license }
+
+ it "should not change the license or approval" do
+ existing_license = subject.license
+ existing_approval = subject.approved?
+ merged = subject.merge new_dep
+ merged.approved?.should == existing_approval
+ merged.license.should == existing_license
+ end
end
end

0 comments on commit 6c751c7

Please sign in to comment.