diff options
author | sdelano <stephen@opscode.com> | 2010-08-18 01:26:22 -0700 |
---|---|---|
committer | sdelano <stephen@opscode.com> | 2010-08-26 13:19:11 -0700 |
commit | 95c9a158abd179c36cbadccefc5109bd9af8e670 (patch) | |
tree | 5aa14620976fc348076cdec1efd0bba6a746f97d | |
parent | b058bb7ac8f63316e02c64752945c683d5d6f6eb (diff) | |
download | chef-95c9a158abd179c36cbadccefc5109bd9af8e670.tar.gz |
add cookbooks/_latest api endpoint
-rw-r--r-- | chef-server-api/app/controllers/cookbooks.rb | 8 | ||||
-rw-r--r-- | chef-server-api/config/router.rb | 2 | ||||
-rw-r--r-- | features/api/cookbooks/list_cookbooks.feature | 14 |
3 files changed, 19 insertions, 5 deletions
diff --git a/chef-server-api/app/controllers/cookbooks.rb b/chef-server-api/app/controllers/cookbooks.rb index e0e9f9fbb6..4bc82faabf 100644 --- a/chef-server-api/app/controllers/cookbooks.rb +++ b/chef-server-api/app/controllers/cookbooks.rb @@ -48,13 +48,11 @@ class Cookbooks < Application display response end - #FIXME: this is different from the rest of the API, but in a useful way... def index_latest cookbook_list = Chef::CookbookVersion.cdb_list_latest(true) - response = Hash.new - cookbook_list.map! do |cookbook_name, cookbook_version| - response[cookbook_name]={ :url=>absolute_url(:cookbook, :cookbook_name => cookbook_name, :cookbook_version => cookbook_version), - :cookbook_name => cookbook_name, :cookbook_version=>cookbook_version} + response = cookbook_list.inject({}) do |res, cv| + res[cv.name] = absolute_url(:cookbook_version, :cookbook_name => cv.name, :cookbook_version => cv.version) + res end display response end diff --git a/chef-server-api/config/router.rb b/chef-server-api/config/router.rb index 2fa72ee627..8344b815d8 100644 --- a/chef-server-api/config/router.rb +++ b/chef-server-api/config/router.rb @@ -31,6 +31,8 @@ Merb::Router.prepare do :method => 'get' ).to(:controller => "cookbooks", :action => "index") + match("/cookbooks/_latest", :method=>'get').to(:controller=>'cookbooks',:action=>'index_latest') + match("/cookbooks/_recipes", :method=>'get').to(:controller=>'cookbooks',:action=>'index_recipes') match("/cookbooks/:cookbook_name/:cookbook_version", diff --git a/features/api/cookbooks/list_cookbooks.feature b/features/api/cookbooks/list_cookbooks.feature index 5a86d34bd4..f5e494f2aa 100644 --- a/features/api/cookbooks/list_cookbooks.feature +++ b/features/api/cookbooks/list_cookbooks.feature @@ -9,6 +9,20 @@ Feature: List cookbooks via the REST API Given I am <user_type> And I upload multiple versions of the 'version_test' cookbook When I 'GET' the path '/cookbooks' + And the inflated responses key 'attribute_include' should match 'http://.+/cookbooks/attribute_include' + And the inflated responses key 'deploy' should match 'http://.+/cookbooks/deploy' + And the inflated responses key 'metadata' should match 'http://.+/cookbooks/metadata' + And the inflated responses key 'version_test' should match 'http://.+/cookbooks/version_test' + + Examples: + | user_type | + | an administrator | + | a non-admin | + + Scenario Outline: List all cookbooks with the latest version + Given I am <user_type> + And I upload multiple versions of the 'version_test' cookbook + When I 'GET' the path '/cookbooks/_latest' And the inflated responses key 'attribute_include' should match 'http://.+/cookbooks/attribute_include/0\.1\.0' And the inflated responses key 'deploy' should match 'http://.+/cookbooks/deploy/0\.0\.0' And the inflated responses key 'metadata' should match 'http://.+/cookbooks/metadata/1\.0\.0' |