Skip to content

Commit

Permalink
[Fixed] Action_items resolves decisions file path
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Collins <rcollins@pivotal.io>
  • Loading branch information
Daniil Kouznetsov authored and Ryan Collins committed Jan 12, 2018
1 parent 73c0b92 commit c2a92ab
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
38 changes: 38 additions & 0 deletions features/features/cli/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,42 @@
expect(developer).to be_seeing('No active and installed package managers found for project.')
expect(developer).to be_receiving_exit_code(0)
end

context 'running action_items --recursive' do
let(:action_items) { 'license_finder action_items --recursive' }
let(:action_items_prepare) { 'license_finder action_items --prepare --recursive' }
let(:whitelist) { 'license_finder whitelist add MIT' }
let(:approvals) { 'license_finder approvals add objenesis' }
let(:relative_decisions_path) { ' --decisions-file=folder-name/dependency_decisions.yml' }
let(:absolute_decisions_path) { ' --decisions-file=/folder-name/dependency_decisions.yml' }

before do
LicenseFinder::TestingDSL::CompositeProject.create
developer.execute_command(action_items_prepare)
end

specify 'uses default decisions-file' do
developer.execute_command(whitelist)
developer.execute_command(approvals)
developer.execute_command(action_items)
expect(developer).to_not be_seeing('objenesis')
expect(developer).to_not be_seeing('MIT')
end

specify 'uses decisions-file with relative path' do
developer.execute_command(whitelist + relative_decisions_path)
developer.execute_command(approvals + relative_decisions_path)
developer.execute_command(action_items + relative_decisions_path)
expect(developer).to_not be_seeing('objenesis')
expect(developer).to_not be_seeing('MIT')
end

specify 'uses decisions-file with absolute path' do
developer.execute_command(whitelist + absolute_decisions_path)
developer.execute_command(approvals + absolute_decisions_path)
developer.execute_command(action_items + absolute_decisions_path)
expect(developer).to_not be_seeing('objenesis')
expect(developer).to_not be_seeing('MIT')
end
end
end
6 changes: 4 additions & 2 deletions lib/license_finder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def mix_deps_dir
end

def decisions_file_path
path = get(:decisions_file) || 'doc/dependency_decisions.yml'
project_path.join(path).expand_path
path = File.join(project_path, 'doc/dependency_decisions.yml') unless project_path.nil?
path = get(:decisions_file) unless get(:decisions_file).nil?
path = 'doc/dependency_decisions.yml' if path.nil?
Pathname.new(path)
end

def project_path
Expand Down
4 changes: 3 additions & 1 deletion lib/license_finder/license_aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def finders
[LicenseFinder::Core.new(@config)]
else
@aggregate_paths.map do |path|
LicenseFinder::Core.new(@config.merge(project_path: path))
# Passing file paths as values instead of allowing them to evaluate in config
LicenseFinder::Core.new(@config.merge(project_path: path,
decisions_file: @config.decisions_file_path))
end
end
end
Expand Down
30 changes: 16 additions & 14 deletions spec/lib/license_finder/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ module LicenseFinder
end
end

describe 'decisions_file' do
describe '#decisions_file' do
it 'has default' do
subject = described_class.new(
{ decisions_file: nil },
'decisions_file' => nil
)
expect(subject.decisions_file_path.to_s).to end_with 'doc/dependency_decisions.yml'
end

it 'prefers primary value' do
subject = described_class.new(
{ decisions_file: 'primary' },
Expand All @@ -66,24 +74,18 @@ module LicenseFinder
expect(subject.decisions_file_path.to_s).to end_with 'secondary'
end

it 'has default' do
subject = described_class.new(
{ decisions_file: nil },
'decisions_file' => nil
)
expect(subject.decisions_file_path.to_s).to end_with 'doc/dependency_decisions.yml'
end

it 'prepends project path to default path if project_path option is set' do
subject = described_class.new({ project_path: 'magic_path' }, {})
expect(subject.decisions_file_path.to_s).to end_with 'magic_path/doc/dependency_decisions.yml'
end

it 'prepends project path to provided value' do
subject = described_class.new({ decisions_file: 'primary',
project_path: 'magic_path' },
'decisions_file' => 'secondary')
expect(subject.decisions_file_path.to_s).to end_with 'magic_path/primary'
it 'prefers decisions_file over project_path' do
subject = described_class.new(
{ project_path: 'magic_path',
decisions_file: 'better_path' },
'decisions_file' => nil
)
expect(subject.decisions_file_path.to_s).to end_with 'better_path'
end
end

Expand Down

0 comments on commit c2a92ab

Please sign in to comment.