Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
Use specificity root_default for files without a specificity folder.
Browse files Browse the repository at this point in the history
This is things like files/foo.txt or templates/config.erb, added in
Chef 12. Also adds unit tests for Cookbook#file_specificity.
  • Loading branch information
coderanger committed May 31, 2015
1 parent 8dfb7b4 commit eb949a8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ridley/chef/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def file_specificity(category, target)
case category
when :files, :templates
relpath = target.relative_path_from(path).to_s
relpath.slice(/(.+)\/(.+)\/.+/, 2)
relpath.slice(/(.+)\/(.+)\/.+/, 2) || 'root_default'
else
'default'
end
Expand Down
39 changes: 39 additions & 0 deletions spec/unit/ridley/chef/cookbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,45 @@
end
end

describe "#file_specificity" do
let(:category) { :templates }
let(:relpath) { 'default.rb' }
let(:file) { subject.path.join(category.to_s, relpath) }
before(:each) { @specificity = subject.file_specificity(category, file) }

context "given a recipe file" do
let(:category) { :recipes }

it "has a specificity of 'default'" do
@specificity.should eql("default")
end
end

context "given a template 'default/config.erb'" do
let(:relpath) { 'default/config.erb' }

it "has a specificity of 'default'" do
@specificity.should eql("default")
end
end

context "given a template 'centos/config.erb'" do
let(:relpath) { 'centos/config.erb' }

it "has a specificity of 'centos'" do
@specificity.should eql("centos")
end
end

context "given a template 'config.erb'" do
let(:relpath) { 'config.erb' }

it "has a specificity of 'root_default'" do
@specificity.should eql("root_default")
end
end
end

describe "#to_hash" do
subject { cookbook.to_hash }

Expand Down

0 comments on commit eb949a8

Please sign in to comment.