From e15e376668cfa638da83d9a78edf3232cd07890f Mon Sep 17 00:00:00 2001 From: Brett and Tristan Date: Mon, 25 Aug 2014 11:25:18 -0400 Subject: Add supermarket_attributes to Metadata Allow the metadata.rb in a cookbook to specify arbitrary attributes for use from Supermarket. The usecase for this right now would be setting the issues and source URLs for that Cookbook instead of specifying them in the Supermarket UI. --- spec/unit/cookbook/metadata_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/unit/cookbook') diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index e61c85b42b..a99131e33e 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -140,6 +140,9 @@ describe Chef::Cookbook::Metadata do metadata.recipes.should eq(Mash.new) end + it "has an empty supermarket_attributes list" do + metadata.supermarket_attributes.should eq(Mash.new) + end end describe "validation" do @@ -732,4 +735,18 @@ describe Chef::Cookbook::Metadata do end + describe "supermarket_attributes" do + it "should set supermarket_attributes equal to a given hash" do + attrs = Mash.new( + :source_url => "https://github.com/opscode-cookbooks/supermarket", + :issues_url => "https://github.com/opscode-cookbooks/supermarket/issues" + ) + + metadata.supermarket_attributes(attrs) + + metadata.supermarket_attributes[:source_url].should == attrs[:source_url] + metadata.supermarket_attributes[:issues_url].should == attrs[:issues_url] + end + end + end -- cgit v1.2.1 From fe6d60f7a9456a97457f37a20729e366a714f428 Mon Sep 17 00:00:00 2001 From: Brett Chalupa Date: Tue, 26 Aug 2014 10:51:50 -0400 Subject: Use individual URL attributes in metadata Instead of having an arbitrary Hash/Mash of supermarket_attributes, use two explicit URL attributes at the top level of the metadata: the source_url and issues_url. --- spec/unit/cookbook/metadata_spec.rb | 56 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'spec/unit/cookbook') diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index a99131e33e..8f287a5b13 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -29,7 +29,8 @@ describe Chef::Cookbook::Metadata do @fields = [ :name, :description, :long_description, :maintainer, :maintainer_email, :license, :platforms, :dependencies, :recommendations, :suggestions, :conflicting, :providing, - :replacing, :attributes, :groupings, :recipes, :version] + :replacing, :attributes, :groupings, :recipes, :version, + :source_url, :issues_url ] end it "does not depend on object identity for equality" do @@ -140,8 +141,12 @@ describe Chef::Cookbook::Metadata do metadata.recipes.should eq(Mash.new) end - it "has an empty supermarket_attributes list" do - metadata.supermarket_attributes.should eq(Mash.new) + it "has an empty source_url string" do + metadata.source_url.should eq('') + end + + it "has an empty issues_url string" do + metadata.issues_url.should eq('') end end @@ -191,7 +196,9 @@ describe Chef::Cookbook::Metadata do :license => "Apache v2.0", :description => "Foobar!", :long_description => "Much Longer\nSeriously", - :version => "0.6.0" + :version => "0.6.0", + :source_url => "http://example.com", + :issues_url => "http://example.com/issues" } params.sort { |a,b| a.to_s <=> b.to_s }.each do |field, field_value| describe field do @@ -336,7 +343,9 @@ describe Chef::Cookbook::Metadata do "type" => 'string', "required" => 'recommended', "recipes" => [ "mysql::server", "mysql::master" ], - "default" => [ ] + "default" => [ ], + "source_url" => "http://example.com", + "issues_url" => "http://example.com/issues" } metadata.attribute("/db/mysql/databases", attrs).should == attrs end @@ -359,6 +368,24 @@ describe Chef::Cookbook::Metadata do }.should raise_error(ArgumentError) end + it "should not accept anything but a string for the source_url" do + lambda { + metadata.attribute("db/mysql/databases", :source_url => "foo") + }.should_not raise_error + lambda { + metadata.attribute("db/mysql/databases", :source_url => Hash.new) + }.should raise_error(ArgumentError) + end + + it "should not accept anything but a string for the issues_url" do + lambda { + metadata.attribute("db/mysql/databases", :issues_url => "foo") + }.should_not raise_error + lambda { + metadata.attribute("db/mysql/databases", :issues_url => Hash.new) + }.should raise_error(ArgumentError) + end + it "should not accept anything but an array of strings for choice" do lambda { metadata.attribute("db/mysql/databases", :choice => ['dedicated', 'shared']) @@ -651,6 +678,8 @@ describe Chef::Cookbook::Metadata do attributes recipes version + source_url + issues_url }.each do |t| it "should include '#{t}'" do deserialized_metadata[t].should == metadata.send(t.to_sym) @@ -684,6 +713,8 @@ describe Chef::Cookbook::Metadata do attributes recipes version + source_url + issues_url }.each do |t| it "should match '#{t}'" do deserialized_metadata.send(t.to_sym).should == metadata.send(t.to_sym) @@ -734,19 +765,4 @@ describe Chef::Cookbook::Metadata do end end - - describe "supermarket_attributes" do - it "should set supermarket_attributes equal to a given hash" do - attrs = Mash.new( - :source_url => "https://github.com/opscode-cookbooks/supermarket", - :issues_url => "https://github.com/opscode-cookbooks/supermarket/issues" - ) - - metadata.supermarket_attributes(attrs) - - metadata.supermarket_attributes[:source_url].should == attrs[:source_url] - metadata.supermarket_attributes[:issues_url].should == attrs[:issues_url] - end - end - end -- cgit v1.2.1