license_finder 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +0 -1
  3. data/bin/license_finder +21 -1
  4. data/features/approve_dependencies.feature +10 -0
  5. data/features/license_finder.feature +13 -3
  6. data/features/license_finder_rake_task.feature +3 -3
  7. data/features/set_license.feature +14 -0
  8. data/features/step_definitions/steps.rb +5 -0
  9. data/lib/license_finder.rb +13 -2
  10. data/lib/license_finder/bundle.rb +25 -3
  11. data/lib/license_finder/bundle_syncer.rb +12 -0
  12. data/lib/license_finder/bundled_gem.rb +12 -1
  13. data/lib/license_finder/cli.rb +42 -3
  14. data/lib/license_finder/configuration.rb +1 -31
  15. data/lib/license_finder/dependency.rb +30 -94
  16. data/lib/license_finder/dependency_report.rb +30 -0
  17. data/lib/license_finder/html_report.rb +14 -0
  18. data/lib/license_finder/persistence.rb +1 -0
  19. data/lib/license_finder/persistence/yaml.rb +7 -0
  20. data/lib/license_finder/persistence/yaml/configuration.rb +34 -0
  21. data/lib/license_finder/persistence/yaml/dependency.rb +127 -0
  22. data/lib/license_finder/reporter.rb +7 -38
  23. data/lib/license_finder/source_syncer.rb +40 -0
  24. data/lib/license_finder/text_report.rb +9 -0
  25. data/lib/templates/dependency.html.erb +2 -2
  26. data/lib/templates/html_report.erb +93 -0
  27. data/lib/templates/text_report.erb +2 -0
  28. data/license_finder.gemspec +2 -2
  29. data/{README.markdown → readme.md} +22 -11
  30. data/spec/lib/license_finder/bundle_spec.rb +58 -0
  31. data/spec/lib/license_finder/bundle_syncer_spec.rb +22 -0
  32. data/spec/lib/license_finder/bundled_gem_spec.rb +17 -14
  33. data/spec/lib/license_finder/cli_spec.rb +38 -0
  34. data/spec/lib/license_finder/dependency_spec.rb +130 -223
  35. data/spec/lib/license_finder/html_report_spec.rb +67 -0
  36. data/spec/lib/license_finder/persistence/yaml/configuration_spec.rb +5 -0
  37. data/spec/lib/license_finder/persistence/yaml/dependency_spec.rb +5 -0
  38. data/spec/lib/license_finder/possible_license_file_spec.rb +4 -9
  39. data/spec/lib/license_finder/reporter_spec.rb +0 -1
  40. data/spec/lib/license_finder/source_syncer_spec.rb +37 -0
  41. data/spec/lib/license_finder/text_report_spec.rb +29 -0
  42. data/spec/lib/license_finder_spec.rb +9 -11
  43. data/spec/spec_helper.rb +1 -1
  44. data/spec/support/license_examples.rb +1 -1
  45. data/spec/support/shared_examples/persistence/configuration.rb +34 -0
  46. data/spec/support/shared_examples/persistence/dependency.rb +139 -0
  47. metadata +38 -26
  48. data/lib/license_finder/dependency_list.rb +0 -80
  49. data/lib/license_finder/viewable.rb +0 -31
  50. data/lib/templates/dependency_list.html.erb +0 -38
  51. data/spec/lib/license_finder/dependency_list_spec.rb +0 -243
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "license_finder"
3
- s.version = "0.6.0"
3
+ s.version = "0.7.0"
4
4
  s.authors = ["Jacob Maine", "Matthew Kane Parker", "Ian Lesperance", "David Edwards", "Paul Meskers"]
5
5
  s.email = ["brent@pivotalabs.com"]
6
6
  s.homepage = "https://github.com/pivotal/LicenseFinder"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_dependency "bundler"
20
20
  s.add_development_dependency "rails", ">=3"
21
- %w(rspec rr rake cucumber rails pry capybara).each do |gem|
21
+ %w(rspec rake cucumber rails pry capybara).each do |gem|
22
22
  s.add_development_dependency gem
23
23
  end
24
24
 
@@ -10,7 +10,7 @@ With bundler it's easy for your project to depend on many gems. This decomposit
10
10
  Add license_finder to your Rails project's Gemfile and `bundle`:
11
11
 
12
12
  ```ruby
13
- gem 'license_finder'
13
+ gem 'license_finder', git: "https://github.com/pivotal/LicenseFinder.git"
14
14
  ```
15
15
 
16
16
  ## Usage
@@ -62,11 +62,26 @@ unapproved dependency to the project.
62
62
  It will also merge in an existing dependencies.yml file, if one exists (i.e., you've previously run this command
63
63
  and then edited the resulting file).
64
64
 
65
+ ### Manually recording licenses
66
+
67
+ When you have dependencies marked as having an 'other' license, `license_finder` will output
68
+ the license and readme file locations for the dependency, allowing you to manually research what the actual
69
+ license is. Once this has been established, you can record this information with the `-l` option
70
+ as such:
71
+
72
+ ```sh
73
+ $ license_finder -l MIT my_unknown_dependency
74
+ ```
75
+
76
+ This command would assign the MIT license to the dependency `my_unknown_dependency`.
77
+
65
78
  ### Manually approving dependencies
66
79
 
67
80
  Whenever you have a dependency that falls outside of your whitelist, `license_finder` will tell you.
68
- If your business decides that this is an acceptable risk, you can manually approve the dependency by finding its
69
- section in the `dependencies.yml` file and setting its `approved` attribute to true. For example, lets assume you've only
81
+ If your business decides that this is an acceptable risk, you can manually approve the dependency by using the `-a` or
82
+ `--approve` option of the `license_finder` command.
83
+
84
+ For example, lets assume you've only
70
85
  whitelisted the "MIT" license in your `config/license_finder.yml`. You then add the 'awesome_gpl_gem' to your Gemfile,
71
86
  which we'll assume is licensed with the `GPL` license. You then run `license_finder` and see
72
87
  the gem listed in the output:
@@ -75,14 +90,10 @@ the gem listed in the output:
75
90
  awesome_gpl_gem, 1.0.0, GPL
76
91
  ```
77
92
 
78
- Your business tells you that in this case, it's acceptable to use this gem. You should now update your `dependencies.yml`
79
- file, setting the `approved` attribute to `true` for the `awesome_gpl_gem` section:
93
+ Your business tells you that in this case, it's acceptable to use this gem. You now run:
80
94
 
81
- ```yaml
82
- - name: awesome_gpl_gem
83
- version: 1.0.0
84
- license: GPL
85
- approved: true
95
+ ```sh
96
+ $ bundle exec license_finder -a awesome_gpl_gem
86
97
  ```
87
98
 
88
99
  If you rerun `license_finder`, you should no longer see `awesome_gpl_gem` in the output.
@@ -141,4 +152,4 @@ And add a `LICENSE` file to your gem that contains your license text.
141
152
 
142
153
  ## License
143
154
 
144
- LicenseFinder is released under the terms of the MIT License. http://www.opensource.org/licenses/mit-license
155
+ LicenseFinder is released under the MIT License. http://www.opensource.org/licenses/mit-license
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe Bundle do
5
+ def build_gemspec(name, version, dependency=nil)
6
+ Gem::Specification.new do |s|
7
+ s.name = name
8
+ s.version = version
9
+ s.summary = 'summary'
10
+ s.description = 'description'
11
+
12
+ if dependency
13
+ s.add_dependency dependency
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '.from_bundler(bundle)' do
19
+ let(:definition) do
20
+ double('definition', {
21
+ :dependencies => [],
22
+ :groups => [],
23
+ :specs_for => [
24
+ build_gemspec('gem1', '1.2.3'),
25
+ build_gemspec('gem2', '0.4.2')
26
+ ]
27
+ })
28
+ end
29
+
30
+ subject do
31
+ Bundle.new(definition).gems.map(&:to_dependency)
32
+ end
33
+
34
+ its(:count) { should == 2 }
35
+
36
+ it "should have 2 dependencies" do
37
+ subject.size.should == 2
38
+ end
39
+
40
+ context "when initialized with a parent and child gem" do
41
+ before do
42
+ definition.stub(:specs_for).and_return([
43
+ build_gemspec('gem1', '1.2.3', 'gem2'),
44
+ build_gemspec('gem2', '0.4.2')
45
+ ])
46
+ end
47
+
48
+ it "should update the child dependency with its parent data" do
49
+ gem1 = subject.first
50
+ gem2 = subject.last
51
+
52
+ gem2.parents.should == [gem1.name]
53
+ gem1.children.should == [gem2.name]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe BundleSyncer do
5
+ describe "#sync!" do
6
+ it "should delegate the bundled dependencies and the persisted bundled dependencies to the source syncer" do
7
+ gem = double :gem, :to_dependency => double(:gem_dependency)
8
+ bundled_dep = double :bundled_dep, source: "bundle"
9
+ manual_dep = double :manual_dep, source: nil
10
+ syncer = double :source_syncer
11
+
12
+ Bundle.stub_chain(:new, :gems).and_return [gem]
13
+ Dependency.stub(:all).and_return [bundled_dep, manual_dep]
14
+ SourceSyncer.should_receive(:new).with([gem.to_dependency], [bundled_dep]).and_return syncer
15
+ syncer.should_receive(:sync!)
16
+
17
+ BundleSyncer.sync!
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -10,6 +10,8 @@ describe LicenseFinder::BundledGem do
10
10
  s.summary = 'summary'
11
11
  s.description = 'description'
12
12
  s.homepage = 'homepage'
13
+
14
+ s.add_dependency 'foo'
13
15
  end
14
16
  end
15
17
 
@@ -25,26 +27,26 @@ describe LicenseFinder::BundledGem do
25
27
  describe "#determine_license" do
26
28
  subject do
27
29
  details = LicenseFinder::BundledGem.new(gemspec)
28
- stub(details).license_files { [license_file] }
30
+ details.stub(:license_files).and_return([license_file])
29
31
  details
30
32
  end
31
33
 
32
34
  let(:license_file) { LicenseFinder::PossibleLicenseFile.new('gem', 'gem/license/path') }
33
35
 
34
36
  it "returns the license from the gemspec if provided" do
35
- stub(gemspec).license { "Some License" }
37
+ gemspec.stub(:license).and_return('Some License')
36
38
 
37
39
  subject.determine_license.should == "Some License"
38
40
  end
39
41
 
40
42
  it "returns the matched license if detected" do
41
- stub(license_file).license { "Detected License" }
43
+ license_file.stub(:license).and_return('Detected License')
42
44
 
43
45
  subject.determine_license.should == "Detected License"
44
46
  end
45
47
 
46
48
  it "returns 'other' otherwise" do
47
- stub(license_file).license { nil }
49
+ license_file.stub(:license).and_return(nil)
48
50
 
49
51
  subject.determine_license.should == "other"
50
52
  end
@@ -56,14 +58,14 @@ describe LicenseFinder::BundledGem do
56
58
  end
57
59
 
58
60
  it "includes files with names like LICENSE, License or COPYING" do
59
- stub(gemspec).full_gem_path { fixture_path('license_names') }
61
+ gemspec.stub(:full_gem_path).and_return(fixture_path('license_names'))
60
62
 
61
63
  subject.license_files.map(&:file_name).should =~
62
64
  %w[COPYING.txt LICENSE Mit-License README.rdoc Licence.rdoc]
63
65
  end
64
66
 
65
67
  it "includes files deep in the hierarchy" do
66
- stub(gemspec).full_gem_path { fixture_path('nested_gem') }
68
+ gemspec.stub(:full_gem_path).and_return(fixture_path('nested_gem'))
67
69
 
68
70
  subject.license_files.map { |f| [f.file_name, f.file_path] }.should =~ [
69
71
  %w[LICENSE vendor/LICENSE]
@@ -71,7 +73,7 @@ describe LicenseFinder::BundledGem do
71
73
  end
72
74
 
73
75
  it "includes both files nested inside LICENSE directory and top level files" do
74
- stub(gemspec).full_gem_path { fixture_path('license_directory') }
76
+ gemspec.stub(:full_gem_path).and_return(fixture_path('license_directory'))
75
77
  found_license_files = subject.license_files
76
78
 
77
79
  found_license_files.map { |f| [f.file_name, f.file_path] }.should =~ [
@@ -91,7 +93,7 @@ describe LicenseFinder::BundledGem do
91
93
  end
92
94
 
93
95
  it "includes files with names like README, Readme or COPYING" do
94
- stub(gemspec).full_gem_path { fixture_path('readme') }
96
+ gemspec.stub(:full_gem_path).and_return(fixture_path('readme'))
95
97
 
96
98
  subject.readme_files.map(&:file_name).should =~ [
97
99
  "Project ReadMe",
@@ -101,7 +103,7 @@ describe LicenseFinder::BundledGem do
101
103
  end
102
104
 
103
105
  it "includes files deep in the hierarchy" do
104
- stub(gemspec).full_gem_path { fixture_path('nested_readme') }
106
+ gemspec.stub(:full_gem_path).and_return(fixture_path('nested_readme'))
105
107
 
106
108
  subject.readme_files.map { |f| [f.file_name, f.file_path] }.should =~ [
107
109
  %w[README vendor/README]
@@ -118,11 +120,12 @@ describe LicenseFinder::BundledGem do
118
120
  its(:source) { should == 'bundle' }
119
121
  its(:description) { should == 'description' }
120
122
  its(:homepage) { should == 'homepage' }
123
+ its(:children) { should == ['foo']}
121
124
 
122
125
  describe 'with a known license' do
123
126
  before do
124
- stub(gemspec).full_gem_path { fixture_path('mit_licensed_gem') }
125
- any_instance_of(LicenseFinder::PossibleLicenseFile, :license => 'Detected License')
127
+ gemspec.stub(:full_gem_path).and_return(fixture_path('mit_licensed_gem'))
128
+ LicenseFinder::PossibleLicenseFile.any_instance.stub(:license).and_return('Detected License')
126
129
  end
127
130
 
128
131
  its(:license) { should == 'Detected License' }
@@ -130,8 +133,8 @@ describe LicenseFinder::BundledGem do
130
133
 
131
134
  describe 'with an unknown license' do
132
135
  before do
133
- stub(gemspec).full_gem_path { fixture_path('other_licensed_gem') }
134
- any_instance_of(LicenseFinder::PossibleLicenseFile, :license => nil)
136
+ gemspec.stub(:full_gem_path).and_return(fixture_path('other_licensed_gem'))
137
+ LicenseFinder::PossibleLicenseFile.any_instance.stub(:license).and_return(nil)
135
138
  end
136
139
 
137
140
  its(:license) { should == 'other' }
@@ -139,7 +142,7 @@ describe LicenseFinder::BundledGem do
139
142
 
140
143
  describe 'with UTF8 file License' do
141
144
  before do
142
- stub(gemspec).full_gem_path { fixture_path('utf8_gem') }
145
+ gemspec.stub(:full_gem_path).and_return(fixture_path('utf8_gem'))
143
146
  end
144
147
 
145
148
  it "handles non UTF8 encodings" do
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ module LicenseFinder
4
+ describe CLI do
5
+ describe "#execute!(options)" do
6
+ before { CLI.stub(:check_for_action_items) }
7
+
8
+ context "when the approve option is provided" do
9
+ it "should approve the requested gem" do
10
+ dependency = double('dependency', :name => nil)
11
+ dependency.should_receive(:approve!)
12
+
13
+ Dependency.stub(:find_by_name).with('foo').and_return(dependency)
14
+
15
+ CLI.execute! approve: true, dependency: 'foo'
16
+ end
17
+ end
18
+
19
+ context "when the -l (--license) switch is provided" do
20
+ it "should update the license on the requested gem" do
21
+ dependency = double :dependency, :name => nil
22
+ dependency.should_receive(:update_attributes).with(:license => "foo")
23
+
24
+ Dependency.stub(:find_by_name).with("foo_gem").and_return dependency
25
+
26
+ CLI.execute! license: "foo", dependency: 'foo_gem'
27
+ end
28
+ end
29
+
30
+ context "when no options are provided" do
31
+ it "should check for action items" do
32
+ CLI.should_receive(:check_for_action_items)
33
+ CLI.execute!
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,273 +1,180 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LicenseFinder::Dependency do
4
- let(:attributes) do
5
- {
6
- 'name' => "spec_name",
7
- 'version' => "2.1.3",
8
- 'license' => "GPLv2",
9
- 'approved' => false,
10
- 'notes' => 'some notes',
11
- 'homepage' => 'homepage',
12
- 'license_files' => [{'path' => '/Users/pivotal/foo/lic1'}, {'path' => '/Users/pivotal/bar/lic2'}],
13
- 'readme_files' => [{'path' => '/Users/pivotal/foo/Readme1'}, {'path' => '/Users/pivotal/bar/Readme2'}],
14
- 'source' => "bundle",
15
- 'bundler_groups' => nil
16
- }
17
- end
18
-
19
- before do
20
- stub(LicenseFinder).config.stub!.whitelist { %w(MIT) }
21
- end
22
-
23
- describe '.new' do
24
- it "should mark it as approved when the license is whitelisted" do
25
- dependency = LicenseFinder::Dependency.new(attributes.merge('license' => 'MIT', 'approved' => false))
26
- dependency.approved.should == true
27
- end
28
-
29
- it "should not mark it as approved when the license is not whitelisted" do
30
- dependency = LicenseFinder::Dependency.new(attributes.merge('license' => 'GPL', 'approved' => false))
31
- dependency.approved.should == false
32
- end
33
-
34
- it "should leave it as approved when the license is not whitelisted but it has already been marked as approved" do
35
- dependency = LicenseFinder::Dependency.new(attributes.merge('license' => 'GPL', 'approved' => true))
36
- dependency.approved.should == true
37
- end
38
- end
39
-
40
- describe '.from_hash' do
41
- subject { LicenseFinder::Dependency.from_hash(attributes) }
42
-
43
- its(:name) { should == 'spec_name' }
44
- its(:version) { should == '2.1.3' }
45
- its(:license) { should == 'GPLv2' }
46
- its(:approved) { should == false }
47
- its(:notes) { should == "some notes" }
48
- its(:license_files) { should == %w(/Users/pivotal/foo/lic1 /Users/pivotal/bar/lic2) }
49
- its(:readme_files) { should == %w(/Users/pivotal/foo/Readme1 /Users/pivotal/bar/Readme2) }
50
- its(:source) { should == "bundle" }
51
- its(:bundler_groups) { should == [] }
52
-
53
- its(:as_yaml) do
54
- should == {
55
- 'name' => 'spec_name',
56
- 'version' => '2.1.3',
57
- 'license' => 'GPLv2',
3
+ module LicenseFinder
4
+ describe Dependency do
5
+ let(:attributes) do
6
+ {
7
+ 'name' => "spec_name",
8
+ 'version' => "2.1.3",
9
+ 'license' => "GPLv2",
58
10
  'approved' => false,
59
- 'source' => 'bundle',
60
- 'homepage' => 'homepage',
61
- 'license_url' => LicenseFinder::License::GPLv2.license_url,
62
11
  'notes' => 'some notes',
63
- 'license_files' => [
64
- {'path' => '/Users/pivotal/foo/lic1'},
65
- {'path' => '/Users/pivotal/bar/lic2'}
66
- ],
67
- 'readme_files' => [
68
- {'path' => '/Users/pivotal/foo/Readme1'},
69
- {'path' => '/Users/pivotal/bar/Readme2'}
70
- ]
12
+ 'homepage' => 'homepage',
13
+ 'license_files' => ['/Users/pivotal/foo/lic1', '/Users/pivotal/bar/lic2'],
14
+ 'readme_files' => ['/Users/pivotal/foo/Readme1', '/Users/pivotal/bar/Readme2'],
15
+ 'source' => "bundle",
16
+ 'bundler_groups' => ["test"]
71
17
  }
72
18
  end
73
19
 
74
- it 'should generate yaml' do
75
- yaml = YAML.load(subject.to_yaml)
76
- yaml.should == subject.as_yaml
20
+ before do
21
+ LicenseFinder.stub(:config).and_return(double('config', {
22
+ :whitelist => %w(MIT),
23
+ :dependencies_yaml => 'dependencies.yml'
24
+ }))
77
25
  end
78
- end
79
26
 
80
- describe '#license_url' do
81
- context "class exists for license type" do
82
- it "should return the license url configured in the class" do
83
- LicenseFinder::Dependency.new('license' => "GPLv2").license_url.should == LicenseFinder::License::GPLv2.license_url
27
+ describe "#approved" do
28
+ it "should return true when the license is whitelisted" do
29
+ dependency = Dependency.new('license' => 'MIT')
30
+ dependency.approved.should == true
84
31
  end
85
32
 
86
- it "should handle differences in case" do
87
- LicenseFinder::Dependency.new('license' => "gplv2").license_url.should == LicenseFinder::License::GPLv2.license_url
33
+ it "should return false when the license is not whitelisted" do
34
+ dependency = Dependency.new('license' => 'GPL')
35
+ dependency.approved.should == false
88
36
  end
89
- end
90
37
 
91
- context "class does not exist for license type" do
92
- it "should return nil" do
93
- LicenseFinder::Dependency.new('license' => "FakeLicense").license_url.should be_nil
38
+ it "should be overridable" do
39
+ dependency = Dependency.new
40
+ dependency.approved = true
41
+ dependency.approved.should == true
94
42
  end
95
43
  end
96
- end
97
-
98
- describe '#to_s' do
99
- let(:gem) do
100
- LicenseFinder::Dependency.new(
101
- 'name' => 'test_gem',
102
- 'version' => '1.0',
103
- 'summary' => 'summary foo',
104
- 'description' => 'description bar',
105
- 'license' => "MIT"
106
- )
107
- end
108
-
109
- subject { gem.to_s.strip }
110
-
111
- it 'should generate text with the gem name, version, and license' do
112
- should == "test_gem, 1.0, MIT"
113
- end
114
- end
115
44
 
116
- describe '#to_html' do
117
- let(:dependency) { LicenseFinder::Dependency.new 'approved' => true }
118
- subject { dependency.to_html }
119
-
120
- context "when the dependency is approved" do
121
- it "should add an approved class to dependency's container" do
122
- should include %{class="approved"}
45
+ describe '#license_url' do
46
+ it "should delegate to LicenseUrl.find_by_name" do
47
+ LicenseFinder::LicenseUrl.stub(:find_by_name).with("MIT").and_return "http://license-url.com"
48
+ Dependency.new(:license => "MIT").license_url.should == "http://license-url.com"
123
49
  end
124
50
  end
125
51
 
126
- context "when the dependency is not approved" do
127
- before { dependency.approved = false }
128
-
129
- it "should not add an approved class to he dependency's container" do
130
- should include %{class="unapproved"}
52
+ describe '#merge' do
53
+ subject do
54
+ Dependency.new(
55
+ 'name' => 'foo',
56
+ 'license' => 'MIT',
57
+ 'version' => '0.0.1',
58
+ 'license_files' => "old license files",
59
+ 'readme_files' => "old readme files"
60
+ )
131
61
  end
132
- end
133
62
 
134
- context "when the gem has at least one bundler group" do
135
- before { dependency.bundler_groups = ["group"] }
136
- it "should show the bundler group(s) in parens" do
137
- should include "(group)"
63
+ let(:new_dep) do
64
+ Dependency.new(
65
+ 'name' => 'foo',
66
+ 'license' => 'MIT',
67
+ 'version' => '0.0.2',
68
+ 'license_files' => "new license files",
69
+ 'readme_files' => "new readme files",
70
+ 'summary' => 'foo summary',
71
+ 'description' => 'awesome foo description!',
72
+ 'bundler_groups' => [1, 2, 3],
73
+ 'homepage' => "http://new.homepage"
74
+ )
138
75
  end
139
- end
140
76
 
141
- context "when the gem has no bundler groups" do
142
- before { dependency.bundler_groups = [] }
77
+ it 'should raise an error if the names do not match' do
78
+ new_dep.name = 'bar'
143
79
 
144
- it "should not show any parens or bundler group info" do
145
- should_not include "()"
80
+ expect {
81
+ subject.merge(new_dep)
82
+ }.to raise_error
146
83
  end
147
84
 
148
- end
149
-
150
- context "when the gem has at least one parent" do
151
- before { dependency.parents = [ OpenStruct.new(:name => "foo parent") ]}
152
- it "should include a parents section" do
153
- should include "Parents"
154
- end
155
- end
85
+ it 'should return the new version, license files, readme files, source, and homepage' do
86
+ merged = subject.merge(new_dep)
156
87
 
157
- context "when the gem has no parents" do
158
- it "should not include any parents section in the output" do
159
- should_not include "Parents"
88
+ merged.version.should == '0.0.2'
89
+ merged.license_files.should == new_dep.license_files
90
+ merged.readme_files.should == new_dep.readme_files
91
+ merged.source.should == new_dep.source
92
+ merged.homepage.should == new_dep.homepage
160
93
  end
161
- end
162
94
 
163
- context "when the gem has at least one child" do
164
- before { dependency.children = [ OpenStruct.new(:name => "foo child") ]}
95
+ it 'should return the new summary and description and bundle groups' do
96
+ merged = subject.merge new_dep
165
97
 
166
- it "should include a Children section" do
167
- should include "Children"
98
+ merged.summary.should == new_dep.summary
99
+ merged.description.should == new_dep.description
100
+ merged.bundler_groups.should == new_dep.bundler_groups
168
101
  end
169
- end
170
102
 
171
- context "when the gem has no children" do
172
- it "should not include any Children section in the output" do
173
- should_not include "Children"
174
- end
175
- end
176
- end
103
+ it 'should return the old notes' do
104
+ subject.notes = 'old notes'
105
+ new_dep.notes = 'new notes'
177
106
 
178
- describe '#source' do
179
- it "should default to nil" do
180
- LicenseFinder::Dependency.new.source.should be_nil
181
- end
107
+ merged = subject.merge(new_dep)
182
108
 
183
- it "should be overridable" do
184
- LicenseFinder::Dependency.new("source" => "foo").source.should == "foo"
185
- end
186
- end
109
+ merged.notes.should == 'old notes'
110
+ end
187
111
 
188
- describe '#merge' do
189
- subject do
190
- LicenseFinder::Dependency.new(
191
- 'name' => 'foo',
192
- 'license' => 'MIT',
193
- 'version' => '0.0.1',
194
- 'license_files' => "old license files",
195
- 'readme_files' => "old readme files",
196
- 'old_homepage' => "http://old.homepage"
197
- )
198
- end
112
+ context "license changes to something other than 'other'" do
113
+ before { new_dep.license = 'new license' }
199
114
 
200
- let(:new_dep) do
201
- LicenseFinder::Dependency.new(
202
- 'name' => 'foo',
203
- 'license' => 'MIT',
204
- 'version' => '0.0.2',
205
- 'license_files' => "new license files",
206
- 'readme_files' => "new readme files",
207
- 'summary' => 'foo summary',
208
- 'description' => 'awesome foo description!',
209
- 'bundler_groups' => [1,2,3],
210
- 'homepage' => "http://new.homepage"
211
- )
212
- end
115
+ context "new license is whitelisted" do
116
+ before { LicenseFinder.config.stub(:whitelist).and_return [new_dep.license] }
213
117
 
214
- it 'should raise an error if the names do not match' do
215
- new_dep.name = 'bar'
118
+ it "should set the approval to true" do
119
+ merged = subject.merge new_dep
120
+ merged.should be_approved
121
+ end
122
+ end
216
123
 
217
- expect {
218
- subject.merge(new_dep)
219
- }.to raise_error
220
- end
124
+ context "new license is not whitelisted" do
125
+ it "should set the approval to false" do
126
+ merged = subject.merge new_dep
127
+ merged.should_not be_approved
128
+ end
129
+ end
130
+ end
221
131
 
222
- it 'should return the new version, license files, readme files, source, and homepage' do
223
- merged = subject.merge(new_dep)
132
+ context "license changes to unknown (i.e., 'other')" do
133
+ before { new_dep.license = 'other' }
224
134
 
225
- merged.version.should == '0.0.2'
226
- merged.license_files.should == new_dep.license_files
227
- merged.readme_files.should == new_dep.readme_files
228
- merged.source.should == new_dep.source
229
- merged.homepage.should == new_dep.homepage
230
- end
231
-
232
- it 'should return the new summary and description and bundle groups' do
233
- merged = subject.merge new_dep
234
-
235
- merged.summary.should == new_dep.summary
236
- merged.description.should == new_dep.description
237
- merged.bundler_groups.should == new_dep.bundler_groups
238
- end
135
+ it "should not change the license" do
136
+ merged = subject.merge new_dep
137
+ merged.license.should == 'MIT'
138
+ end
239
139
 
240
- it 'should return the old notes' do
241
- subject.notes = 'old notes'
242
- new_dep.notes = 'new notes'
140
+ it "should not change the approval" do
141
+ approved = subject.approved?
142
+ merged = subject.merge new_dep
143
+ merged.approved?.should == approved
144
+ end
145
+ end
243
146
 
244
- merged = subject.merge(new_dep)
147
+ context "license does not change" do
148
+ before { new_dep.license.should == subject.license }
245
149
 
246
- merged.notes.should == 'old notes'
150
+ it "should not change the license or approval" do
151
+ existing_license = subject.license
152
+ existing_approval = subject.approved?
153
+ merged = subject.merge new_dep
154
+ merged.approved?.should == existing_approval
155
+ merged.license.should == existing_license
156
+ end
157
+ end
247
158
  end
248
159
 
249
- it 'should return the new license and approval if the license is different' do
250
- subject.license = "MIT"
251
- subject.approved = true
252
-
253
- new_dep.license = "GPLv2"
254
- new_dep.approved = false
255
-
256
- merged = subject.merge(new_dep)
257
-
258
- merged.license.should == "GPLv2"
259
- merged.approved.should == false
160
+ describe '#approve!' do
161
+ it "should update the yaml file to show the gem is approved" do
162
+ gem = Dependency.new(name: "foo")
163
+ gem.approve!
164
+ reloaded_gem = Dependency.find_by_name(gem.name)
165
+ reloaded_gem.approved.should be_true
166
+ end
260
167
  end
261
168
 
262
- it 'should return the old license and approval if the new license is the same or "other"' do
263
- subject.approved = false
264
- new_dep.approved = true
265
-
266
- subject.merge(new_dep).approved.should == false
267
-
268
- new_dep.license = 'other'
269
-
270
- subject.merge(new_dep).approved.should == false
169
+ describe "defaults" do
170
+ %w(license_files readme_files bundler_groups children parents).each do |attribute|
171
+ describe "##{attribute}" do
172
+ it "should default to an empty array" do
173
+ Dependency.new.send(attribute).should == []
174
+ end
175
+ end
176
+ end
271
177
  end
272
178
  end
273
179
  end
180
+