Skip to content

Commit

Permalink
Merge pull request #101 from directionless/allow-empty-metadata
Browse files Browse the repository at this point in the history
Allow partially empty extended metadata
  • Loading branch information
sethvargo authored Jun 16, 2016
2 parents 9292151 + 612675a commit 67951f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/stove/cookbook/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def to_hash(extended_metadata = false)
}

if extended_metadata
hash['source_url'] = self.source_url
hash['issues_url'] = self.issues_url
hash['source_url'] = self.source_url unless self.source_url.empty?
hash['issues_url'] = self.issues_url unless self.issues_url.empty?
hash['chef_version'] = self.chef_version
hash['ohai_version'] = self.ohai_version
end
Expand Down
30 changes: 30 additions & 0 deletions spec/unit/cookbook/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,39 @@ class Stove::Cookbook

context 'when the extra metadata is included' do
it 'includes the new metadata fields' do
subject.source_url('http://foo.example.com')
subject.issues_url('http://bar.example.com')
hash = subject.to_hash(true)
expect(hash).to include('issues_url')
expect(hash['source_url']).to eq 'http://foo.example.com'
expect(hash).to include('source_url')
expect(hash['issues_url']).to eq 'http://bar.example.com'
end
end

context 'when the extra metadata is not defined' do
it 'does not include the new metadata fields' do
hash = subject.to_hash(true)
expect(hash).not_to include('source_url')
expect(hash).not_to include('issues_url')
end
end

context 'when only some of the extra metadata is defined' do
it 'only includes the source_url if issues_url is empty' do
subject.source_url('http://foo.example.com')
hash = subject.to_hash(true)
expect(hash).to include('source_url')
expect(hash['source_url']).to eq 'http://foo.example.com'
expect(hash).not_to include('issues_url')
end

it 'only includes the issues_url if source_url is empty' do
subject.issues_url('http://bar.example.com')
hash = subject.to_hash(true)
expect(hash).to include('issues_url')
expect(hash['issues_url']).to eq 'http://bar.example.com'
expect(hash).not_to include('source_url')
end
end
end
Expand Down

0 comments on commit 67951f7

Please sign in to comment.