license_finder 0.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +22 -0
  6. data/Rakefile +21 -0
  7. data/bin/license_finder +54 -0
  8. data/db/migrate/201303290935_create_dependencies.rb +14 -0
  9. data/db/migrate/201303291155_create_licenses.rb +13 -0
  10. data/db/migrate/201303291402_create_approvals.rb +13 -0
  11. data/db/migrate/201303291456_create_ancestries.rb +9 -0
  12. data/db/migrate/201303291519_create_bundler_groups.rb +13 -0
  13. data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +11 -0
  14. data/db/migrate/201303291753_allow_null_license_names.rb +7 -0
  15. data/db/migrate/201304011027_allow_null_dependency_version.rb +7 -0
  16. data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +5 -0
  17. data/features/approve_dependencies.feature +14 -0
  18. data/features/html_report.feature +38 -0
  19. data/features/ignore_bundle_groups.feature +11 -0
  20. data/features/license_finder.feature +47 -0
  21. data/features/license_finder_rake_task.feature +37 -0
  22. data/features/rails_rake.feature +9 -0
  23. data/features/set_license.feature +12 -0
  24. data/features/step_definitions/license_finder_steps.rb +25 -0
  25. data/features/step_definitions/steps.rb +376 -0
  26. data/features/text_report.feature +27 -0
  27. data/features/whitelist.feature +24 -0
  28. data/files/license_finder.yml +8 -0
  29. data/lib/data/licenses/Apache2.txt +172 -0
  30. data/lib/data/licenses/BSD.txt +24 -0
  31. data/lib/data/licenses/GPLv2.txt +339 -0
  32. data/lib/data/licenses/ISC.txt +2 -0
  33. data/lib/data/licenses/LGPL.txt +165 -0
  34. data/lib/data/licenses/MIT.txt +9 -0
  35. data/lib/data/licenses/NewBSD.txt +21 -0
  36. data/lib/data/licenses/Ruby.txt +52 -0
  37. data/lib/data/licenses/SimplifiedBSD.txt +23 -0
  38. data/lib/license_finder.rb +47 -0
  39. data/lib/license_finder/bundle.rb +48 -0
  40. data/lib/license_finder/bundle_syncer.rb +11 -0
  41. data/lib/license_finder/bundled_gem.rb +48 -0
  42. data/lib/license_finder/cli.rb +49 -0
  43. data/lib/license_finder/configuration.rb +71 -0
  44. data/lib/license_finder/dependency_report.rb +30 -0
  45. data/lib/license_finder/gem_saver.rb +69 -0
  46. data/lib/license_finder/html_report.rb +14 -0
  47. data/lib/license_finder/license.rb +90 -0
  48. data/lib/license_finder/license/apache2.rb +8 -0
  49. data/lib/license_finder/license/bsd.rb +4 -0
  50. data/lib/license_finder/license/gplv2.rb +4 -0
  51. data/lib/license_finder/license/isc.rb +3 -0
  52. data/lib/license_finder/license/lgpl.rb +3 -0
  53. data/lib/license_finder/license/mit.rb +23 -0
  54. data/lib/license_finder/license/new_bsd.rb +8 -0
  55. data/lib/license_finder/license/ruby.rb +11 -0
  56. data/lib/license_finder/license/simplified_bsd.rb +8 -0
  57. data/lib/license_finder/license_files.rb +36 -0
  58. data/lib/license_finder/license_url.rb +12 -0
  59. data/lib/license_finder/platform.rb +32 -0
  60. data/lib/license_finder/possible_license_file.rb +32 -0
  61. data/lib/license_finder/railtie.rb +7 -0
  62. data/lib/license_finder/reporter.rb +20 -0
  63. data/lib/license_finder/tables.rb +7 -0
  64. data/lib/license_finder/tables/approval.rb +4 -0
  65. data/lib/license_finder/tables/bundler_group.rb +4 -0
  66. data/lib/license_finder/tables/dependency.rb +31 -0
  67. data/lib/license_finder/tables/license_alias.rb +22 -0
  68. data/lib/license_finder/text_report.rb +9 -0
  69. data/lib/license_finder/yml_to_sql.rb +127 -0
  70. data/lib/tasks/license_finder.rake +7 -0
  71. data/lib/templates/html_report.erb +111 -0
  72. data/lib/templates/text_report.erb +3 -0
  73. data/license_finder.gemspec +36 -0
  74. data/readme.md +115 -0
  75. data/spec/fixtures/APACHE-2-LICENSE +202 -0
  76. data/spec/fixtures/GPLv2 +339 -0
  77. data/spec/fixtures/ISC-LICENSE +10 -0
  78. data/spec/fixtures/MIT-LICENSE +22 -0
  79. data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +22 -0
  80. data/spec/fixtures/README-with-MIT-LICENSE +222 -0
  81. data/spec/fixtures/license_directory/COPYING +0 -0
  82. data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +25 -0
  83. data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +339 -0
  84. data/spec/fixtures/license_directory/LICENSE/LICENSE +191 -0
  85. data/spec/fixtures/license_directory/LICENSE/MIT.txt +21 -0
  86. data/spec/fixtures/license_directory/LICENSE/RUBY.txt +60 -0
  87. data/spec/fixtures/license_names/COPYING.txt +0 -0
  88. data/spec/fixtures/license_names/LICENSE +0 -0
  89. data/spec/fixtures/license_names/Licence.rdoc +0 -0
  90. data/spec/fixtures/license_names/Mit-License +0 -0
  91. data/spec/fixtures/license_names/README.rdoc +0 -0
  92. data/spec/fixtures/mit_licensed_gem/LICENSE +22 -0
  93. data/spec/fixtures/nested_gem/vendor/LICENSE +0 -0
  94. data/spec/fixtures/nested_readme/vendor/README +0 -0
  95. data/spec/fixtures/other_licensed_gem/LICENSE +3 -0
  96. data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
  97. data/spec/fixtures/readme/README +0 -0
  98. data/spec/fixtures/readme/Readme.markdown +0 -0
  99. data/spec/fixtures/utf8_gem/README +210 -0
  100. data/spec/lib/license_finder/bundle_spec.rb +61 -0
  101. data/spec/lib/license_finder/bundle_syncer_spec.rb +16 -0
  102. data/spec/lib/license_finder/bundled_gem_spec.rb +62 -0
  103. data/spec/lib/license_finder/cli_spec.rb +38 -0
  104. data/spec/lib/license_finder/configuration_spec.rb +70 -0
  105. data/spec/lib/license_finder/gem_saver_spec.rb +155 -0
  106. data/spec/lib/license_finder/html_report_spec.rb +84 -0
  107. data/spec/lib/license_finder/license/apache_spec.rb +7 -0
  108. data/spec/lib/license_finder/license/bsd_spec.rb +41 -0
  109. data/spec/lib/license_finder/license/gplv2_spec.rb +7 -0
  110. data/spec/lib/license_finder/license/isc_spec.rb +7 -0
  111. data/spec/lib/license_finder/license/lgpl_spec.rb +7 -0
  112. data/spec/lib/license_finder/license/mit_spec.rb +33 -0
  113. data/spec/lib/license_finder/license/new_bsd_spec.rb +35 -0
  114. data/spec/lib/license_finder/license/ruby_spec.rb +19 -0
  115. data/spec/lib/license_finder/license/simplified_bsd_spec.rb +7 -0
  116. data/spec/lib/license_finder/license_files_spec.rb +50 -0
  117. data/spec/lib/license_finder/license_spec.rb +45 -0
  118. data/spec/lib/license_finder/license_url_spec.rb +20 -0
  119. data/spec/lib/license_finder/possible_license_file_spec.rb +37 -0
  120. data/spec/lib/license_finder/reporter_spec.rb +4 -0
  121. data/spec/lib/license_finder/tables/dependency_spec.rb +102 -0
  122. data/spec/lib/license_finder/tables/license_alias_spec.rb +54 -0
  123. data/spec/lib/license_finder/text_report_spec.rb +31 -0
  124. data/spec/lib/license_finder/yml_to_sql_spec.rb +99 -0
  125. data/spec/lib/license_finder_spec.rb +82 -0
  126. data/spec/spec_helper.rb +31 -0
  127. data/spec/support/license_examples.rb +30 -0
  128. metadata +435 -0
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe LicenseFinder::License::NewBSD do
4
+ subject { LicenseFinder::License::NewBSD.new("") }
5
+
6
+ it_behaves_like "a license matcher"
7
+
8
+ it "should match regardless of organization or copyright holder names" do
9
+ license = LicenseFinder::License::NewBSD.new <<-LICENSE
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+ * Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ * Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+ * Neither the name of Johnny %$#!.43298432, Guitar INC! nor the
18
+ names of its contributors may be used to endorse or promote products
19
+ derived from this software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL Johnny %$#!.43298432, Guitar BE LIABLE FOR ANY
25
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ LICENSE
32
+
33
+ license.should be_matches
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe LicenseFinder::License::Ruby do
4
+ subject { LicenseFinder::License::Ruby.new("") }
5
+
6
+ it_behaves_like "a license matcher"
7
+
8
+ describe "#matches?" do
9
+ it "should return true when the Ruby license URL is present" do
10
+ subject.text = "This gem is available under the following license:\nhttp://www.ruby-lang.org/en/LICENSE.txt\nOkay?"
11
+ should be_matches
12
+ end
13
+
14
+ it "should return false when the Ruby License URL is not present" do
15
+ subject.text = "This gem is available under the following license:\nhttp://www.example.com\nOkay?"
16
+ should_not be_matches
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe LicenseFinder::License::SimplifiedBSD do
4
+ subject { LicenseFinder::License::SimplifiedBSD.new("") }
5
+
6
+ it_behaves_like "a license matcher"
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe LicenseFiles do
5
+ def fixture_path(fixture)
6
+ Pathname.new(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec', 'fixtures', fixture)).realpath.to_s
7
+ end
8
+
9
+ describe "#files" do
10
+ it "is empty if there aren't any license files" do
11
+ subject = described_class.new('/not/a/dir')
12
+ subject.files.should == []
13
+ end
14
+
15
+ it "includes files with names like LICENSE, License or COPYING" do
16
+ subject = described_class.new(fixture_path('license_names'))
17
+
18
+ subject.files.map(&:file_name).should =~
19
+ %w[COPYING.txt LICENSE Mit-License README.rdoc Licence.rdoc]
20
+ end
21
+
22
+ it "includes files deep in the hierarchy" do
23
+ subject = described_class.new(fixture_path('nested_gem'))
24
+
25
+ subject.files.map { |f| [f.file_name, f.file_path] }.should =~ [
26
+ %w[LICENSE vendor/LICENSE]
27
+ ]
28
+ end
29
+
30
+ it "includes both files nested inside LICENSE directory and top level files" do
31
+ subject = described_class.new(fixture_path('license_directory'))
32
+ found_license_files = subject.files
33
+
34
+ found_license_files.map { |f| [f.file_name, f.file_path] }.should =~ [
35
+ %w[BSD-2-Clause.txt LICENSE/BSD-2-Clause.txt],
36
+ %w[GPL-2.0.txt LICENSE/GPL-2.0.txt],
37
+ %w[MIT.txt LICENSE/MIT.txt],
38
+ %w[RUBY.txt LICENSE/RUBY.txt],
39
+ %w[COPYING COPYING],
40
+ %w[LICENSE LICENSE/LICENSE]
41
+ ]
42
+ end
43
+
44
+ it "handles non UTF8 encodings" do
45
+ subject = described_class.new(fixture_path('utf8_gem'))
46
+ expect { subject.files }.not_to raise_error
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ class FooLicense < LicenseFinder::License::Base
4
+ self.alternative_names = ["the foo license"]
5
+ self.license_url = "http://foo.license.com"
6
+
7
+ def self.pretty_name
8
+ "Ye Ole Foo License"
9
+ end
10
+ end
11
+
12
+ module LicenseFinder
13
+ describe License do
14
+ describe ".find_by_name" do
15
+ it "should match on demodulized names" do
16
+ License.find_by_name("FooLicense").should == FooLicense
17
+ end
18
+
19
+ it "should match on pretty names" do
20
+ License.find_by_name("Ye Ole Foo License").should == FooLicense
21
+ end
22
+
23
+ it "should match on alternative names" do
24
+ License.find_by_name("the foo license").should == FooLicense
25
+ end
26
+
27
+ it "should return nil if no match" do
28
+ License.find_by_name(:unknown).should be_nil
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ describe LicenseFinder::License::Base do
35
+ describe ".names" do
36
+ subject do
37
+ Class.new(LicenseFinder::License::Base) do
38
+ def self.demodulized_name; "FooLicense"; end
39
+ self.alternative_names = ["foo license"]
40
+ end.names
41
+ end
42
+
43
+ it { should =~ ["FooLicense", "foo license"] }
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ class FooLicense < LicenseFinder::License::Base
4
+ self.alternative_names = ["the foo license"]
5
+ self.license_url = "http://foo.license.com"
6
+ end
7
+
8
+ describe LicenseFinder::LicenseUrl do
9
+ describe ".find_by_name" do
10
+ subject { LicenseFinder::LicenseUrl }
11
+
12
+ specify { subject.find_by_name("FooLicense").should == "http://foo.license.com" }
13
+ specify { subject.find_by_name("fOolICENse").should == "http://foo.license.com" }
14
+ specify { subject.find_by_name("the foo license").should == "http://foo.license.com" }
15
+
16
+ specify { subject.find_by_name(nil).should be_nil }
17
+ specify { subject.find_by_name("").should be_nil }
18
+ specify { subject.find_by_name("unknown license").should be_nil }
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
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')
10
+ end
11
+
12
+ its(:file_path) { should == 'nested/path' }
13
+ its(:file_name) { should == 'path' }
14
+ its(:text) { should == 'file text' }
15
+ end
16
+ end
17
+
18
+ subject { LicenseFinder::PossibleLicenseFile.new('gem', 'gem/license/path') }
19
+
20
+ context "with a known license" do
21
+ before do
22
+ subject.stub(:text).and_return('a known license')
23
+
24
+ LicenseFinder::License::MIT.stub(:new).with('a known license').and_return(double('MIT license', :matches? => true))
25
+ end
26
+
27
+ its(:license) { should == "MIT" }
28
+ end
29
+
30
+ context "with an unknown license" do
31
+ before do
32
+ subject.stub(:text).and_return('')
33
+ end
34
+
35
+ its(:license) { should be_nil }
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe LicenseFinder::Reporter do
4
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe Dependency do
5
+ let(:attributes) do
6
+ {
7
+ 'name' => "spec_name",
8
+ 'version' => "2.1.3",
9
+ 'license' => "GPLv2",
10
+ 'approved' => false,
11
+ 'notes' => 'some notes',
12
+ 'homepage' => 'homepage',
13
+ 'license_files' => ['/Users/pivotal/foo/lic1', '/Users/pivotal/bar/lic2'],
14
+ 'bundler_groups' => ["test"]
15
+ }
16
+ end
17
+
18
+ let(:config) { Configuration.new }
19
+
20
+ before do
21
+ LicenseFinder.stub(:config).and_return config
22
+ config.whitelist = ["MIT", "other"]
23
+ end
24
+
25
+ describe ".destroy_obsolete" do
26
+ it "destroys every dependency except for the ones provided as 'current'" do
27
+ cur1 = Dependency.create(name: "current dependency 1")
28
+ cur2 = Dependency.create(name: "current dependency 2")
29
+ Dependency.create(name: "old dependency 1")
30
+ Dependency.create(name: "old dependency 2")
31
+
32
+ Dependency.destroy_obsolete([cur1, cur2])
33
+ Dependency.all.should =~ [cur1, cur2]
34
+ end
35
+ end
36
+
37
+ describe '.unapproved' do
38
+ it "should return all unapproved dependencies" do
39
+ dependency = Dependency.create(name: "unapproved dependency", version: '0.0.1')
40
+ dependency.approval = Approval.create(state: false)
41
+ dependency.save
42
+ approved = Dependency.create(name: "approved dependency", version: '0.0.1')
43
+ approved.approval = Approval.create(state: true)
44
+ approved.save
45
+ whitelisted = Dependency.create(name: "approved dependency", version: '0.0.1')
46
+ whitelisted.license = LicenseAlias.create(name: 'MIT')
47
+ whitelisted.approval = Approval.create(state: false)
48
+ whitelisted.save
49
+
50
+ unapproved = Dependency.unapproved
51
+ unapproved.count.should == 1
52
+ unapproved.should_not be_any(&:approved?)
53
+ end
54
+ end
55
+
56
+ describe '#approve!' do
57
+ it "should update the database to show the dependency is approved" do
58
+ dependency = Dependency.create(name: "foo", version: '0.0.1')
59
+ dependency.approval = Approval.create(state: false)
60
+ dependency.save
61
+ dependency.approve!
62
+ dependency.reload.should be_approved
63
+ end
64
+ end
65
+
66
+ describe "#approved?" do
67
+ let(:dependency) { Dependency.create(name: 'some gem') }
68
+
69
+ it "is true if its license is whitelisted" do
70
+ dependency.stub_chain(:license, whitelisted?: true)
71
+ dependency.should be_approved
72
+ end
73
+
74
+ it "is true if it has been approved" do
75
+ dependency.stub_chain(:license, whitelisted?: false)
76
+ dependency.stub_chain(:approval, state: true)
77
+ dependency.should be_approved
78
+ end
79
+
80
+ it "is false otherwise" do
81
+ dependency.stub_chain(:license, whitelisted?: false)
82
+ dependency.stub_chain(:approval, state: false)
83
+ dependency.should_not be_approved
84
+ end
85
+ end
86
+
87
+ describe "#set_license_manually" do
88
+ let(:gem) do
89
+ dependency = Dependency.new(name: "bob", version: '0.0.1')
90
+ dependency.license = LicenseAlias.create(name: 'Original')
91
+ dependency.save
92
+ dependency
93
+ end
94
+
95
+ it "delegates to the license" do
96
+ gem.license.should_receive(:set_manually).with('Updated')
97
+ gem.set_license_manually('Updated')
98
+ end
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe LicenseAlias do
5
+ describe 'initializes' do
6
+ it "delegates to LicenseUrl.find_by_name for the url" do
7
+ LicenseUrl.stub(:find_by_name).with("MIT").and_return "http://license-url.com"
8
+ license = described_class.new(name: 'MIT')
9
+ license.url.should == "http://license-url.com"
10
+ end
11
+ end
12
+
13
+ describe "#set_manually" do
14
+ subject do
15
+ described_class.create(name: 'Original')
16
+ end
17
+
18
+ it "modifies the license" do
19
+ subject.set_manually('Updated')
20
+ subject.reload.name.should == 'Updated'
21
+ end
22
+
23
+ it "marks the approval as manual" do
24
+ subject.set_manually('Updated')
25
+ subject.reload.manual.should be_true
26
+ end
27
+ end
28
+
29
+ describe "#whitelisted?" do
30
+ let(:config) { Configuration.new }
31
+
32
+ before do
33
+ LicenseFinder.stub(:config).and_return config
34
+ config.whitelist = ["MIT", "other"]
35
+ end
36
+
37
+ it "should return true when the license is whitelisted" do
38
+ described_class.new(name: 'MIT').should be_whitelisted
39
+ end
40
+
41
+ it "should return true when the license is an alternative name of a whitelisted license" do
42
+ described_class.new(name: 'Expat').should be_whitelisted
43
+ end
44
+
45
+ it "should return true when the license has no matching license class, but is whitelisted anyways" do
46
+ described_class.new(name: 'other').should be_whitelisted
47
+ end
48
+
49
+ it "should return false when the license is not whitelisted" do
50
+ described_class.new(name: 'GPL').should_not be_whitelisted
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe TextReport do
5
+ describe '#to_s' do
6
+ let(:dep1) do
7
+ dependency = Dependency.new(
8
+ 'name' => 'gem_a',
9
+ 'version' => '1.0',
10
+ )
11
+ dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
12
+ dependency
13
+ end
14
+
15
+ let(:dep2) do
16
+ dependency = Dependency.new(
17
+ 'name' => 'gem_b',
18
+ 'version' => '1.0',
19
+ )
20
+ dependency.license = LicenseFinder::LicenseAlias.create(name: 'MIT')
21
+ dependency
22
+ end
23
+
24
+ subject { TextReport.new([dep2, dep1]).to_s }
25
+
26
+ it 'should generate a text report with the name, version, and license of each dependency, sorted by name' do
27
+ should == "gem_a, 1.0, MIT\ngem_b, 1.0, MIT"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe LicenseFinder::YmlToSql do
4
+ let(:legacy_attributes) do
5
+ {
6
+ 'name' => "spec_name",
7
+ 'version' => "2.1.3",
8
+ 'license' => "GPLv2",
9
+ 'license_url' => "www.license_url.org",
10
+ 'approved' => true,
11
+ 'manual' => true,
12
+ 'summary' => "some summary",
13
+ 'description' => "some description",
14
+ 'homepage' => 'www.homepage.com',
15
+ 'children' => ["child1_name"],
16
+ 'parents' => ["parent1_name"],
17
+ 'bundler_groups' => [:test],
18
+
19
+ 'notes' => 'some notes',
20
+ 'license_files' => ['/Users/pivotal/foo/lic1', '/Users/pivotal/bar/lic2'],
21
+ }
22
+ end
23
+ let(:config) { LicenseFinder::Configuration.new }
24
+
25
+ before do
26
+ LicenseFinder.stub(:config) { config }
27
+ end
28
+
29
+ describe ".needs_conversion?" do
30
+ it "is true if the yml still exists" do
31
+ config.stub(dependencies_dir: 'path/to')
32
+ File.should_receive(:exists?).with('path/to/dependencies.yml') { true }
33
+ described_class.needs_conversion?.should be_true
34
+ end
35
+
36
+ it "is false otherwise" do
37
+ config.stub(dependencies_dir: 'path/to')
38
+ File.should_receive(:exists?).with('path/to/dependencies.yml') { false }
39
+ described_class.needs_conversion?.should be_false
40
+ end
41
+ end
42
+
43
+ describe ".remove_yml" do
44
+ it "removes the yml file" do
45
+ config.stub(dependencies_dir: 'path/to')
46
+ File.should_receive(:delete).with('path/to/dependencies.yml')
47
+ described_class.remove_yml
48
+ end
49
+ end
50
+
51
+ describe '.convert_all' do
52
+ before do
53
+ (DB.tables - [:schema_migrations]).each { |table| DB[table].truncate }
54
+ end
55
+
56
+ it "persists all of the dependency's attributes" do
57
+ described_class.convert_all([legacy_attributes])
58
+
59
+ described_class::Sql::Dependency.count.should == 1
60
+ saved_dep = described_class::Sql::Dependency.first
61
+ saved_dep.name.should == "spec_name"
62
+ saved_dep.version.should == "2.1.3"
63
+ saved_dep.summary.should == "some summary"
64
+ saved_dep.description.should == "some description"
65
+ saved_dep.homepage.should == "www.homepage.com"
66
+ end
67
+
68
+ it "associates the license to the dependency" do
69
+ described_class.convert_all([legacy_attributes])
70
+
71
+ saved_dep = described_class::Sql::Dependency.first
72
+ saved_dep.license.name.should == "GPLv2"
73
+ saved_dep.license.url.should == "www.license_url.org"
74
+ saved_dep.license.manual.should == true
75
+ end
76
+
77
+ it "associates bundler groups" do
78
+ described_class.convert_all([legacy_attributes])
79
+
80
+ saved_dep = described_class::Sql::Dependency.first
81
+ saved_dep.bundler_groups.count.should == 1
82
+ saved_dep.bundler_groups.first.name.should == 'test'
83
+ end
84
+
85
+ it "associates children" do
86
+ child_attrs = {
87
+ 'name' => 'child1_name',
88
+ 'version' => '0.0.1',
89
+ 'license' => 'other'
90
+ }
91
+ described_class.convert_all([legacy_attributes, child_attrs])
92
+
93
+ described_class::Sql::Dependency.count.should == 2
94
+ saved_dep = described_class::Sql::Dependency.first(name: 'spec_name')
95
+ saved_dep.children.count.should == 1
96
+ saved_dep.children.first.name.should == 'child1_name'
97
+ end
98
+ end
99
+ end