license_finder 1.0.0.0-java → 1.1.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.force-build +0 -0
  3. data/.travis.yml +8 -7
  4. data/CHANGELOG.rdoc +29 -1
  5. data/Rakefile +2 -2
  6. data/db/migrate/201311192003_reassociate_manual_approval.rb +2 -3
  7. data/db/migrate/201403181732_rename_manual_fields.rb +10 -0
  8. data/db/migrate/201403190028_add_manual_approvals.rb +22 -0
  9. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +15 -0
  10. data/db/migrate/201403191645_remove_license_aliases.rb +23 -0
  11. data/features/cli.feature +21 -20
  12. data/features/cocoapods_dependencies.feature +10 -0
  13. data/features/configure_bundler_groups.feature +23 -0
  14. data/features/configure_ignore_dependencies.feature +16 -0
  15. data/features/{project_name.feature → configure_project_name.feature} +1 -1
  16. data/features/{whitelist.feature → configure_whitelist.feature} +6 -6
  17. data/features/manually_added.feature +19 -0
  18. data/features/{approve_dependencies.feature → manually_approved.feature} +2 -2
  19. data/features/manually_assigned_license.feature +16 -0
  20. data/features/{text_report.feature → report_csv.feature} +2 -2
  21. data/features/{html_report.feature → report_html.feature} +2 -2
  22. data/features/step_definitions/cli_steps.rb +22 -32
  23. data/features/step_definitions/cocoapod_steps.rb +8 -0
  24. data/features/step_definitions/configure_bundler_groups_steps.rb +30 -0
  25. data/features/step_definitions/configure_ignore_dependencies.rb +35 -0
  26. data/features/step_definitions/{project_name_steps.rb → configure_project_name_steps.rb} +0 -0
  27. data/features/step_definitions/configure_whitelist_steps.rb +45 -0
  28. data/features/step_definitions/gradle_steps.rb +2 -2
  29. data/features/step_definitions/manually_added_steps.rb +28 -0
  30. data/features/step_definitions/manually_approved_steps.rb +24 -0
  31. data/features/step_definitions/manually_assigned_license_steps.rb +34 -0
  32. data/features/step_definitions/maven_steps.rb +2 -2
  33. data/features/step_definitions/node_steps.rb +2 -2
  34. data/features/step_definitions/python_steps.rb +1 -1
  35. data/features/step_definitions/report_csv_steps.rb +20 -0
  36. data/features/step_definitions/report_html_steps.rb +60 -0
  37. data/features/step_definitions/shared_steps.rb +125 -104
  38. data/{files/license_finder.yml → lib/data/license_finder.example.yml} +3 -0
  39. data/lib/license_finder.rb +3 -2
  40. data/lib/license_finder/cli.rb +94 -49
  41. data/lib/license_finder/configuration.rb +21 -14
  42. data/lib/license_finder/dependency_manager.rb +27 -19
  43. data/lib/license_finder/license.rb +33 -19
  44. data/lib/license_finder/license/definitions.rb +153 -104
  45. data/lib/license_finder/license/matcher.rb +6 -1
  46. data/lib/license_finder/license/none_matcher.rb +9 -0
  47. data/lib/license_finder/license/text.rb +1 -0
  48. data/lib/license_finder/package.rb +30 -6
  49. data/lib/license_finder/package_managers/bower.rb +2 -2
  50. data/lib/license_finder/package_managers/bower_package.rb +2 -2
  51. data/lib/license_finder/package_managers/bundler.rb +9 -17
  52. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  53. data/lib/license_finder/package_managers/cocoa_pods.rb +35 -0
  54. data/lib/license_finder/package_managers/cocoa_pods_package.rb +19 -0
  55. data/lib/license_finder/package_managers/gradle.rb +9 -5
  56. data/lib/license_finder/package_managers/gradle_package.rb +4 -4
  57. data/lib/license_finder/package_managers/maven.rb +7 -3
  58. data/lib/license_finder/package_managers/maven_package.rb +5 -5
  59. data/lib/license_finder/package_managers/npm.rb +2 -2
  60. data/lib/license_finder/package_managers/npm_package.rb +2 -2
  61. data/lib/license_finder/package_managers/pip.rb +2 -2
  62. data/lib/license_finder/package_managers/pip_package.rb +7 -11
  63. data/lib/license_finder/package_saver.rb +12 -10
  64. data/lib/license_finder/possible_license_file.rb +1 -1
  65. data/lib/license_finder/possible_license_files.rb +11 -15
  66. data/lib/license_finder/reports/formatted_report.rb +25 -6
  67. data/lib/license_finder/reports/html_report.rb +2 -1
  68. data/lib/license_finder/reports/reporter.rb +3 -3
  69. data/lib/license_finder/tables.rb +6 -4
  70. data/lib/license_finder/tables/dependency.rb +36 -16
  71. data/lib/license_finder/tables/manual_approval.rb +13 -0
  72. data/lib/license_finder/yml_to_sql.rb +12 -9
  73. data/lib/templates/html_report.erb +68 -74
  74. data/lib/templates/markdown_report.erb +20 -21
  75. data/license_finder.gemspec +7 -7
  76. data/readme.md +76 -79
  77. data/spec/fixtures/Podfile +3 -0
  78. data/spec/lib/license_finder/cli_spec.rb +71 -23
  79. data/spec/lib/license_finder/configuration_spec.rb +61 -21
  80. data/spec/lib/license_finder/dependency_manager_spec.rb +52 -33
  81. data/spec/lib/license_finder/license/definitions_spec.rb +30 -14
  82. data/spec/lib/license_finder/license_spec.rb +55 -12
  83. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +38 -19
  84. data/spec/lib/license_finder/package_managers/bower_spec.rb +10 -16
  85. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +39 -15
  86. data/spec/lib/license_finder/package_managers/bundler_spec.rb +10 -22
  87. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +44 -0
  88. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +79 -0
  89. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +4 -5
  90. data/spec/lib/license_finder/package_managers/gradle_spec.rb +26 -20
  91. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +4 -5
  92. data/spec/lib/license_finder/package_managers/maven_spec.rb +16 -19
  93. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +39 -19
  94. data/spec/lib/license_finder/package_managers/npm_spec.rb +10 -16
  95. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +8 -8
  96. data/spec/lib/license_finder/package_managers/pip_spec.rb +10 -16
  97. data/spec/lib/license_finder/package_saver_spec.rb +27 -3
  98. data/spec/lib/license_finder/possible_license_file_spec.rb +25 -23
  99. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +6 -8
  100. data/spec/lib/license_finder/reports/html_report_spec.rb +45 -44
  101. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -9
  102. data/spec/lib/license_finder/reports/reporter_spec.rb +1 -1
  103. data/spec/lib/license_finder/reports/text_report_spec.rb +6 -8
  104. data/spec/lib/license_finder/tables/dependency_spec.rb +57 -41
  105. data/spec/lib/license_finder/yml_to_sql_spec.rb +94 -92
  106. data/spec/spec_helper.rb +1 -0
  107. data/spec/support/stdout_helpers.rb +25 -0
  108. metadata +86 -69
  109. data/MIT.LICENSE +0 -20
  110. data/features/ignore_bundle_groups.feature +0 -23
  111. data/features/manually_managed_dependencies.feature +0 -19
  112. data/features/set_license.feature +0 -10
  113. data/features/step_definitions/approve_dependencies_steps.rb +0 -25
  114. data/features/step_definitions/html_report_steps.rb +0 -62
  115. data/features/step_definitions/ignore_bundle_groups_steps.rb +0 -29
  116. data/features/step_definitions/manually_managed_steps.rb +0 -33
  117. data/features/step_definitions/set_license_steps.rb +0 -20
  118. data/features/step_definitions/text_report_steps.rb +0 -19
  119. data/features/step_definitions/whitelist_steps.rb +0 -45
  120. data/files/dependency_breakdown.png +0 -0
  121. data/files/report_breakdown.png +0 -0
  122. data/lib/license_finder/license_url.rb +0 -9
  123. data/lib/license_finder/tables/license_alias.rb +0 -22
  124. data/spec/lib/license_finder/license_url_spec.rb +0 -16
  125. data/spec/lib/license_finder/tables/license_alias_spec.rb +0 -37
  126. data/spec/support/silence_stdout.rb +0 -13
@@ -41,26 +41,20 @@ module LicenseFinder
41
41
  end
42
42
 
43
43
  describe '.active?' do
44
- let(:requirements) { Pathname.new('requirements.txt').expand_path }
44
+ let(:requirements) { double(:requirements_file) }
45
45
 
46
- context 'with a requirements file' do
47
- before :each do
48
- allow(File).to receive(:exists?).with(requirements).and_return(true)
49
- end
50
-
51
- it 'returns true' do
52
- expect(Pip.active?).to eq(true)
53
- end
46
+ before do
47
+ Pip.stub(requirements_path: requirements)
54
48
  end
55
49
 
56
- context 'without a requirements file' do
57
- before :each do
58
- allow(File).to receive(:exists?).with(requirements).and_return(false)
59
- end
50
+ it 'is true with a requirements.txt file' do
51
+ requirements.stub(:exist? => true)
52
+ expect(Pip).to be_active
53
+ end
60
54
 
61
- it 'returns false' do
62
- expect(Pip.active?).to eq(false)
63
- end
55
+ it 'is false without a requirements.txt file' do
56
+ requirements.stub(:exist? => false)
57
+ expect(Pip).to_not be_active
64
58
  end
65
59
  end
66
60
  end
@@ -5,7 +5,7 @@ module LicenseFinder
5
5
  let(:package) do
6
6
  double(
7
7
  :package,
8
- license: 'license',
8
+ license: License.find_by_name('license'),
9
9
  children: ['child'],
10
10
  groups: [:group],
11
11
  summary: 'summary',
@@ -34,7 +34,7 @@ module LicenseFinder
34
34
  summary: 'old summary',
35
35
  description: 'old desription',
36
36
  homepage: 'old homepage',
37
- license: LicenseAlias.named('old license')
37
+ license_name: 'old license'
38
38
  )
39
39
  dep.add_bundler_group BundlerGroup.named("old group")
40
40
  dep.add_child Dependency.named("old child")
@@ -56,13 +56,37 @@ module LicenseFinder
56
56
  it "keeps approval" do
57
57
  dep = Dependency.create(
58
58
  name: 'spec_name',
59
- manually_approved: true
60
59
  )
60
+ dep.approve!
61
61
  saver = described_class.new(dep, package)
62
62
  subject = saver.save
63
63
 
64
64
  subject.should be_approved
65
65
  end
66
+
67
+ context "to minimize db changes" do
68
+ it "does not re-save unchanged dependencies" do
69
+ # See note in PackageSaver#save
70
+
71
+ first_run = described_class.find_or_create_by_name(package)
72
+ # Can't set this expectation, because rspec method expectations
73
+ # have no way to allow the real save to happen.
74
+ # expect(first_run.dependency).to receive(:save)
75
+ first_run.save
76
+
77
+ second_run = described_class.find_or_create_by_name(package)
78
+ expect(second_run.dependency).to_not receive(:save)
79
+ second_run.save
80
+ end
81
+
82
+ it "saves new dependencies" do
83
+ # Just a sanity check that the above test is testing what we think it
84
+ # is testing.
85
+ saver = described_class.find_or_create_by_name(package)
86
+ expect(saver.dependency).to receive(:save)
87
+ saver.save
88
+ end
89
+ end
66
90
  end
67
91
  end
68
92
  end
@@ -1,36 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LicenseFinder::PossibleLicenseFile do
4
- context "file parsing" do
5
- subject { LicenseFinder::PossibleLicenseFile.new('root', 'root/nested/path') }
6
-
7
- context "ignoring text" do
8
- before do
9
- subject.stub(:text).and_return('file text')
3
+ module LicenseFinder
4
+ describe PossibleLicenseFile do
5
+ context "file parsing" do
6
+ subject { described_class.new('root', 'root/nested/path') }
7
+
8
+ context "ignoring text" do
9
+ before do
10
+ subject.stub(:text).and_return('file text')
11
+ end
12
+
13
+ its(:file_path) { should == 'nested/path' }
14
+ its(:text) { should == 'file text' } # this is a terrible test, considering the stubbing
10
15
  end
11
-
12
- its(:file_path) { should == 'nested/path' }
13
- its(:text) { should == 'file text' } # this is a terrible test, considering the stubbing
14
16
  end
15
- end
16
17
 
17
- subject { LicenseFinder::PossibleLicenseFile.new('gem', 'gem/license/path') }
18
+ subject { described_class.new('gem', 'gem/license/path') }
18
19
 
19
- context "with a known license" do
20
- before do
21
- subject.stub(:text).and_return('a known license')
20
+ context "with a known license" do
21
+ before do
22
+ subject.stub(:text).and_return('a known license')
22
23
 
23
- LicenseFinder::License.stub(:find_by_text).with('a known license').and_return(LicenseFinder::License.find_by_name("MIT"))
24
+ License.stub(:find_by_text).with('a known license').and_return(License.find_by_name("MIT"))
25
+ end
26
+
27
+ its(:license) { should == License.find_by_name("MIT") }
24
28
  end
25
29
 
26
- its(:license) { should == "MIT" }
27
- end
30
+ context "with an unknown license" do
31
+ before do
32
+ subject.stub(:text).and_return('')
33
+ end
28
34
 
29
- context "with an unknown license" do
30
- before do
31
- subject.stub(:text).and_return('')
35
+ its(:license) { should be_nil }
32
36
  end
33
-
34
- its(:license) { should be_nil }
35
37
  end
36
38
  end
@@ -4,25 +4,23 @@ module LicenseFinder
4
4
  describe DetailedTextReport do
5
5
  describe '#to_s' do
6
6
  let(:dep1) do
7
- dependency = Dependency.new(
7
+ Dependency.new(
8
8
  'name' => 'gem_a',
9
9
  'version' => '1.0',
10
10
  'summary' => 'Summary',
11
- 'description' => 'Description'
11
+ 'description' => 'Description',
12
+ 'license' => License.find_by_name('MIT')
12
13
  )
13
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
14
- dependency
15
14
  end
16
15
 
17
16
  let(:dep2) do
18
- dependency = Dependency.new(
17
+ Dependency.new(
19
18
  'name' => 'gem_b',
20
19
  'version' => '1.0',
21
20
  'summary' => 'Summary',
22
- 'description' => 'Description'
21
+ 'description' => 'Description',
22
+ 'license' => License.find_by_name('MIT')
23
23
  )
24
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
25
- dependency
26
24
  end
27
25
 
28
26
  subject { DetailedTextReport.new([dep2, dep1]).to_s }
@@ -4,78 +4,79 @@ require "capybara"
4
4
  module LicenseFinder
5
5
  describe HtmlReport do
6
6
  describe "#to_s" do
7
+ let(:dependency_name) { "the-name" }
7
8
  let(:dependency) do
8
- dep = Dependency.new name: "the-name", manually_approved: true
9
- dep.license = LicenseAlias.create name: 'MIT'
9
+ dep = Dependency.create name: dependency_name
10
+ dep.apply_better_license License.find_by_name("MIT")
10
11
  dep
11
12
  end
12
13
 
13
14
  subject { Capybara.string(HtmlReport.new([dependency]).to_s) }
14
15
 
15
- context "when the dependency is approved" do
16
- it "should add an approved class to dependency's container" do
16
+ context "when the dependency is manually approved" do
17
+ before { dependency.approve! "the-approver", "the-approval-note" }
18
+
19
+ it "should show approved dependencies without action items" do
17
20
  should have_selector ".approved"
21
+ should_not have_selector ".action-items"
18
22
  end
19
23
 
20
- it "does not list the dependency in the action items" do
21
- should_not have_selector ".action-items"
24
+ it "shows the license, approver and approval notes" do
25
+ deps = subject.find ".dependencies"
26
+ deps.should have_content "MIT"
27
+ deps.should have_content "the-approver"
28
+ deps.should have_content "the-approval-note"
29
+ deps.should have_selector "time"
22
30
  end
23
31
  end
24
32
 
25
- context "when the dependency is not approved" do
26
- before { dependency.manually_approved = false }
27
-
28
- it "should not add an approved class to he dependency's container" do
29
- should have_selector ".unapproved"
30
- end
33
+ context "when the dependency is whitelisted" do
34
+ before { dependency.stub(whitelisted?: true) }
31
35
 
32
- it "lists the dependency in the action items" do
33
- should have_selector ".action-items li"
36
+ it "should show approved dependencies without action items" do
37
+ should have_selector ".approved"
38
+ should_not have_selector ".action-items"
34
39
  end
35
- end
36
40
 
37
- context "when the gem has at least one bundler group" do
38
- before { dependency.stub(bundler_groups: [double(name: "group")]) }
39
- it "should show the bundler group(s) in parens" do
40
- should have_text "(group)"
41
+ it "shows the license" do
42
+ deps = subject.find ".dependencies"
43
+ deps.should have_content "MIT"
41
44
  end
42
45
  end
43
46
 
44
- context "when the gem has no bundler groups" do
45
- before { dependency.stub(bundler_groups: []) }
46
-
47
- it "should not show any parens or bundler group info" do
48
- should_not have_text "()"
49
- end
50
-
51
- end
47
+ context "when the dependency is not approved" do
48
+ before {
49
+ dependency.license = License.find_by_name('GPL')
50
+ dependency.manual_approval = nil
51
+ }
52
52
 
53
- context "when the gem has at least one parent" do
54
- before { dependency.stub(parents: [double(:name => "foo parent")]) }
55
- it "should include a parents section" do
56
- should have_text "Parents"
57
- should have_text "foo parent"
53
+ it "should show unapproved dependencies with action items" do
54
+ should have_selector ".unapproved"
55
+ should have_selector ".action-items li"
58
56
  end
59
57
  end
60
58
 
61
- context "when the gem has no parents" do
62
- it "should not include any parents section in the output" do
63
- should_not have_text "Parents"
59
+ context "when the gem has many relationships" do
60
+ before do
61
+ dependency.stub(bundler_groups: [double(name: "foo group")],
62
+ parents: [double(name: "foo parent")],
63
+ children: [double(name: "foo child")])
64
64
  end
65
- end
66
65
 
67
- context "when the gem has at least one child" do
68
- before { dependency.stub(children: [double(:name => "foo child")]) }
69
-
70
- it "should include a Children section" do
71
- should have_text "Children"
66
+ it "should show the relationships" do
67
+ should have_text "(foo group)"
68
+ should have_text "#{dependency_name} is required by:"
69
+ should have_text "foo parent"
70
+ should have_text "#{dependency_name} relies on:"
72
71
  should have_text "foo child"
73
72
  end
74
73
  end
75
74
 
76
- context "when the gem has no children" do
77
- it "should not include any Children section in the output" do
78
- should_not have_text "Children"
75
+ context "when the gem has no relationships" do
76
+ it "should not show any relationships" do
77
+ should_not have_text "()"
78
+ should_not have_text "#{dependency_name} is required by:"
79
+ should_not have_text "#{dependency_name} relies on:"
79
80
  end
80
81
  end
81
82
  end
@@ -4,22 +4,20 @@ module LicenseFinder
4
4
  describe MarkdownReport do
5
5
  describe '#to_s' do
6
6
  let(:dep1) do
7
- dependency = Dependency.new(
7
+ Dependency.new(
8
8
  'name' => 'gem_a',
9
9
  'version' => '1.0',
10
- 'manually_approved' => false
10
+ 'license' => License.find_by_name('other')
11
11
  )
12
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
13
- dependency
14
12
  end
15
13
 
16
14
  let(:dep2) do
17
- dependency = Dependency.new(
15
+ dependency = Dependency.create(
18
16
  'name' => 'gem_b',
19
17
  'version' => '2.3',
20
- 'manually_approved' => true
18
+ 'license' => License.find_by_name('BSD')
21
19
  )
22
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'BSD')
20
+ dependency.approve!
23
21
  dependency
24
22
  end
25
23
 
@@ -31,7 +29,8 @@ module LicenseFinder
31
29
  end
32
30
 
33
31
  it 'should list the total, and unapproved counts' do
34
- should match "2 total, _1 unapproved_"
32
+ should match "2 total"
33
+ should match /1 \*unapproved\*/
35
34
  end
36
35
 
37
36
  it "should list the unapproved dependency" do
@@ -40,7 +39,7 @@ module LicenseFinder
40
39
 
41
40
  it "should display a summary" do
42
41
  should match "## Summary"
43
- should match /\s+\* 1 MIT/
42
+ should match /\s+\* 1 other/
44
43
  should match /\s+\* 1 BSD/
45
44
  end
46
45
 
@@ -6,7 +6,7 @@ module LicenseFinder
6
6
  subject { Reporter.write_reports }
7
7
 
8
8
  before do
9
- Dependency.stub(:all) { [double(:dep)] }
9
+ Dependency.stub(:acknowledged) { [double(:dep)] }
10
10
 
11
11
  MarkdownReport.stub(:of) { 'markdown report' }
12
12
  DetailedTextReport.stub(:of) { 'detailed csv report' }
@@ -4,21 +4,19 @@ module LicenseFinder
4
4
  describe TextReport do
5
5
  describe '#to_s' do
6
6
  let(:dep1) do
7
- dependency = Dependency.new(
7
+ Dependency.new(
8
8
  'name' => 'gem_a',
9
- 'version' => '1.0'
9
+ 'version' => '1.0',
10
+ 'license' => License.find_by_name('MIT')
10
11
  )
11
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
12
- dependency
13
12
  end
14
13
 
15
14
  let(:dep2) do
16
- dependency = Dependency.new(
15
+ Dependency.new(
17
16
  'name' => 'gem_b',
18
- 'version' => '1.0'
17
+ 'version' => '1.0',
18
+ 'license' => License.find_by_name('MIT')
19
19
  )
20
- dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
21
- dependency
22
20
  end
23
21
 
24
22
  subject { TextReport.new([dep2, dep1]).to_s }
@@ -3,19 +3,19 @@ require 'spec_helper'
3
3
  module LicenseFinder
4
4
  describe Dependency do
5
5
  describe '.unapproved' do
6
- let(:config) { Configuration.new('whitelist' => ['MIT', 'other']) }
7
-
8
6
  before do
9
- LicenseFinder.stub(:config).and_return config
7
+ License.find_by_name('MIT').stub(:whitelisted? => true)
8
+ allow(LicenseFinder.config).to receive(:ignore_dependencies) { ['this ignored dependency', 'that ignored dependency'] }
10
9
  end
11
10
 
12
- it "should return all unapproved dependencies" do
11
+ it "should return all unapproved dependencies that are not ignored" do
13
12
  dependency = Dependency.create(name: "unapproved dependency", version: '0.0.1')
14
13
  approved = Dependency.create(name: "approved dependency", version: '0.0.1')
15
- approved.manually_approved = true
16
- approved.save
14
+ this_ignored = Dependency.create(name: "this ignored dependency", version: '0.0.1')
15
+ that_ignored = Dependency.create(name: "that ignored dependency", version: '0.0.1')
16
+ approved.approve!
17
17
  whitelisted = Dependency.create(name: "approved dependency", version: '0.0.1')
18
- whitelisted.license = LicenseAlias.create(name: 'MIT')
18
+ whitelisted.license = License.find_by_name('MIT')
19
19
  whitelisted.save
20
20
 
21
21
  unapproved = Dependency.unapproved
@@ -40,48 +40,64 @@ module LicenseFinder
40
40
  end
41
41
  end
42
42
 
43
+ describe ".acknowledged" do
44
+ it "returns all dependencies that are not ignored" do
45
+ acknowledged_dependency = Dependency.create(name: "acknowledged dependency", version: '0.0.1')
46
+ ignored_dependency = Dependency.create(name: "ignored dependency", version: '0.0.1')
47
+ allow(LicenseFinder.config).to receive(:ignore_dependencies) { [ignored_dependency.name] }
48
+
49
+ expect(Dependency.acknowledged).to match_array [acknowledged_dependency]
50
+ end
51
+ end
52
+
43
53
  describe '#approve!' do
44
54
  it "should update the database to show the dependency is approved" do
45
- dependency = Dependency.create(name: "foo", version: '0.0.1')
55
+ dependency = Dependency.named("foo")
46
56
  dependency.approve!
47
57
  dependency.reload.should be_approved
48
58
  end
59
+
60
+ it "should record the approver and notes" do
61
+ dependency = Dependency.named("foo")
62
+ dependency.approve!("Julian", "We really need this")
63
+ approval = dependency.reload.manual_approval
64
+ approval.approver.should eq "Julian"
65
+ approval.notes.should eq "We really need this"
66
+ end
49
67
  end
50
68
 
51
69
  describe "#approved?" do
52
- let(:not_manually_approved) { Dependency.create(name: 'some gem', manually_approved: false).reload }
53
- let(:manually_approved) { Dependency.create(name: 'some gem', manually_approved: true).reload }
70
+ let(:not_approved_manually) { Dependency.create(name: 'some gem').reload }
71
+ let(:approved_manually) { Dependency.create(name: 'some gem').approve!.reload }
54
72
 
55
73
  it "is true if its license is whitelisted" do
56
- not_manually_approved.stub_chain(:license, whitelisted?: true)
57
- not_manually_approved.should be_approved
74
+ not_approved_manually.stub_chain(:license, whitelisted?: true)
75
+ not_approved_manually.should be_approved
58
76
  end
59
77
 
60
78
  it "is true if it has been approved" do
61
- manually_approved.stub_chain(:license, whitelisted?: false)
62
- manually_approved.should be_approved
79
+ approved_manually.stub_chain(:license, whitelisted?: false)
80
+ approved_manually.should be_approved
63
81
  end
64
82
 
65
83
  it "is false otherwise" do
66
- not_manually_approved.stub_chain(:license, whitelisted?: false)
67
- not_manually_approved.should_not be_approved
84
+ not_approved_manually.stub_chain(:license, whitelisted?: false)
85
+ not_approved_manually.should_not be_approved
68
86
  end
69
87
  end
70
88
 
71
89
  describe "#set_license_manually!" do
72
- let(:license) { LicenseAlias.create(name: 'foolicense') }
73
90
  let(:dependency) { Dependency.create(name: 'foogem') }
74
91
 
75
92
  it "sets manual license to true" do
76
- dependency.license_manual.should be_false
77
- dependency.set_license_manually!('Updated')
78
- dependency.license_manual.should be_true
93
+ dependency.should_not be_license_assigned_manually
94
+ dependency.set_license_manually! License.find_by_name("Updated")
95
+ dependency.should be_license_assigned_manually
79
96
  end
80
97
 
81
98
  it "modifies the license" do
82
- LicenseAlias.should_receive(:named).with('Updated').and_return(license)
83
- dependency.set_license_manually!('Updated')
84
- dependency.reload.license.should == license
99
+ dependency.set_license_manually! License.find_by_name("Updated")
100
+ dependency.reload.license.name.should == 'Updated'
85
101
  end
86
102
  end
87
103
 
@@ -121,39 +137,39 @@ module LicenseFinder
121
137
  let(:dependency) { Dependency.named('some gem') }
122
138
 
123
139
  it "keeps a manually assigned license" do
124
- dependency.license = LicenseAlias.named("manual")
125
- dependency.license_manual = true
126
-
127
- dependency.apply_better_license "new"
140
+ dependency.set_license_manually! License.find_by_name("manual")
141
+ dependency.apply_better_license License.find_by_name("new")
128
142
  dependency.license.name.should == "manual"
129
143
  end
130
144
 
131
145
  it "saves a new license" do
132
- dependency.apply_better_license "new license"
146
+ dependency.apply_better_license License.find_by_name("new license")
133
147
  dependency.license.name.should == "new license"
134
148
  end
135
149
 
136
- it "re-uses an existing, unassociated, license alias" do
137
- dependency.license = LicenseAlias.named("old")
138
-
139
- new_license = LicenseAlias.named("new license")
150
+ it "updates the license's name" do
151
+ dependency.license = License.find_by_name("old")
140
152
 
141
- dependency.apply_better_license "new license"
142
- dependency.license.should == new_license
153
+ dependency.apply_better_license License.find_by_name("new license")
154
+ dependency.license.name.should == "new license"
143
155
  end
144
156
 
145
- it "updates the license's name" do
146
- dependency.license = LicenseAlias.named("old")
157
+ it "won't update the database if the license isn't changing" do
158
+ # See note in PackageSaver#save
159
+ dependency.license = License.find_by_name("same")
160
+ dependency.should be_modified
161
+ dependency.save
162
+ dependency.should_not be_modified
147
163
 
148
- dependency.apply_better_license "new license"
149
- dependency.license.name.should == "new license"
164
+ dependency.apply_better_license License.find_by_name("same")
165
+ dependency.should_not be_modified
150
166
  end
151
167
 
152
168
  it "does not change the approval" do
153
- dependency.license = LicenseAlias.named("old")
154
- dependency.manually_approved = true
169
+ dependency.license = License.find_by_name("old")
170
+ dependency.approve!
155
171
 
156
- dependency.apply_better_license "new license"
172
+ dependency.apply_better_license License.find_by_name("new license")
157
173
  dependency.should be_approved
158
174
  end
159
175
  end