You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/09/21 12:23:23 UTC
git commit: Core: Fixed url helper to generate routes for
entity_metadata
Updated Branches:
refs/heads/master be2581b43 -> ec31c7c37
Core: Fixed url helper to generate routes for entity_metadata
Since entity_metadata does not have plural index action,
we need to force the Rabbit URL helper to artificially create
the plural form for this collection.
If you then call the #show URL helper without :id parameter
URL helper will call the #index helper instead.
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ec31c7c3
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ec31c7c3
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ec31c7c3
Branch: refs/heads/master
Commit: ec31c7c37c02f75dea93b032e7e277bf3cf700e3
Parents: be2581b
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu Sep 20 18:45:02 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Fri Sep 21 12:23:53 2012 +0200
----------------------------------------------------------------------
server/lib/deltacloud/helpers/rabbit_helper.rb | 4 ++
server/tests/cimi/collections/url_helper_test.rb | 31 +++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ec31c7c3/server/lib/deltacloud/helpers/rabbit_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/rabbit_helper.rb b/server/lib/deltacloud/helpers/rabbit_helper.rb
index ef8080f..8f6e264 100644
--- a/server/lib/deltacloud/helpers/rabbit_helper.rb
+++ b/server/lib/deltacloud/helpers/rabbit_helper.rb
@@ -56,6 +56,7 @@ module Sinatra::Rabbit
# Construct OPERATION_COLLECTION_URL helper
# The :index and :create operation does not get any prefix
#
+
helper_method_name = case operation_name
when 'index' then collection_name
when 'show' then collection_name.singularize
@@ -63,12 +64,15 @@ module Sinatra::Rabbit
end
helper_method_name += '_url'
+
[Proc.new do
define_method helper_method_name do |*args|
if (opts = args.first).kind_of? Hash
path = operation.full_path.convert_query_params(opts)
elsif !args.empty? and (obj_id = args.first)
path = operation.full_path.convert_query_params(:id => obj_id)
+ elsif operation_name == 'show'
+ path = collection.operation(:index).full_path
else
path = operation.full_path
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ec31c7c3/server/tests/cimi/collections/url_helper_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/url_helper_test.rb b/server/tests/cimi/collections/url_helper_test.rb
new file mode 100644
index 0000000..eed7ac2
--- /dev/null
+++ b/server/tests/cimi/collections/url_helper_test.rb
@@ -0,0 +1,31 @@
+require 'rubygems'
+require 'require_relative' if RUBY_VERSION < '1.9'
+
+require 'minitest/autorun'
+require_relative './common.rb'
+
+class CIMITestHelper
+ def settings; OpenStruct.new(:root_url => '//'); end
+ def url(path); '/cimi' + path; end
+ include Sinatra::Rabbit::URLFor(CIMI.collections)
+end
+
+describe CIMI do
+
+ before do
+ @api = CIMITestHelper.new
+ end
+
+ it 'generate url helpers for CIMI model' do
+ @api.machines_url.must_equal '/cimi/machines'
+ @api.machine_url('123').must_equal '/cimi/machines/123'
+ @api.machines_url(:format => 'json').must_equal '/cimi/machines?format=json'
+ end
+
+ it 'generate proper url for EntityMetadata' do
+ @api.entity_metadata_url.must_equal '/cimi/entity_metadata'
+ @api.entity_metadata_url('123').must_equal '/cimi/entity_metadata/123'
+ @api.entity_metadata_url(:format => 'json').must_equal '/cimi/entity_metadata/?format=json'
+ end
+
+end