ref: refs/heads/master
commit 8e3443d941f7bf8ed06991bff78e0fb49f6c5ead
Author: Klaus Kämpf
Date: Thu Jul 9 16:20:10 2009 +0200
Support nested resources (below non-singulars only for now)
---
webservice/lib/resource_registration.rb | 13 +++++++++----
.../test/functional/resources_registration_test.rb | 20 +++++++++++++++++++-
.../nested/config/resources/nested.yml | 7 +++++++
.../config/resources/nested_singluar.yml | 8 ++++++++
4 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/webservice/lib/resource_registration.rb b/webservice/lib/resource_registration.rb
index 8bfaa98..acc127c 100644
--- a/webservice/lib/resource_registration.rb
+++ b/webservice/lib/resource_registration.rb
@@ -32,7 +32,6 @@ public
#
def self.register(file, interface = nil, controller = nil)
-# $stderr.puts "register #{file}"
require 'yaml'
@@in_production = (RAILS_ENV == "production")
name = name || File.basename(file, ".*")
@@ -62,8 +61,12 @@ public
error "#{file}: has non-plural interface #{interface} without being flagged as singular" if !singular and name != name.pluralize
+ # nested: is optional, defaults to nil
+ nested = resource["nested"]
+ error "#{file}: singular resources don't support nested" if singular and nested
+
resources[interface] ||= Array.new
- resources[interface] << { :controller => controller, :singular => singular }
+ resources[interface] << { :controller => controller, :singular => singular, :nested => nested }
end
# register routes from a plugin
@@ -73,7 +76,7 @@ public
# $stderr.puts "checking #{res_path}"
Dir.glob(File.join(res_path, 'routes.rb')).each do |route|
basename = File.basename(plugin.directory)
- $stderr.puts "***Error: Plugin #{basename} does private routing, please remove #{basename}/config/routes.rb."
+# $stderr.puts "***Error: Plugin #{basename} does private routing, please remove #{basename}/config/routes.rb."
end
res_path = File.join(res_path, 'resources')
# $stderr.puts "self.register_plugin #{res_path}"
@@ -119,7 +122,9 @@ public
if implementation[:singular]
toplevel.resource name, :controller => namespaces.join("/"), :except => [ :new, :edit ]
else
- toplevel.resources name, :except => [ :new, :edit ]
+ toplevel.resources name, :except => [ :new, :edit ] do |mapping|
+ nested = implementation[:nested] && mapping.resources(nested)
+ end
end
end
end
diff --git a/webservice/test/functional/resources_registration_test.rb b/webservice/test/functional/resources_registration_test.rb
index 2144884..4507b17 100644
--- a/webservice/test/functional/resources_registration_test.rb
+++ b/webservice/test/functional/resources_registration_test.rb
@@ -16,7 +16,7 @@ end
class ResourceRegistrationTest < ActiveSupport::TestCase
- require "lib/resource_registration"
+ require File.expand_path(File.dirname(__FILE__) + "/../../lib/resource_registration")
# Create resources from .yml file
@@ -27,6 +27,15 @@ class ResourceRegistrationTest < ActiveSupport::TestCase
assert !ResourceRegistration.resources.empty?
end
+ # Create nested resources from .yml file
+
+ test "resource creation nested" do
+ plugin = TestPlugin.new "test/resource_fixtures/nested"
+ ResourceRegistration.register_plugin plugin
+
+ assert !ResourceRegistration.resources.empty?
+ end
+
# Catch errors in interface
test "bad interface" do
@@ -68,6 +77,15 @@ class ResourceRegistrationTest < ActiveSupport::TestCase
end
end
+ # Catch nested singular, which is not supported (yet?)
+
+ test "nesting inside a singular resource" do
+ plugin = TestPlugin.new "test/resource_fixtures/nested_singular"
+ assert_raise RuntimeError do
+ ResourceRegistration.register_plugin plugin
+ end
+ end
+
# Pass bad values to register_plugin
test "pass bad values to register_plugin" do
diff --git a/webservice/test/resource_fixtures/nested/config/resources/nested.yml b/webservice/test/resource_fixtures/nested/config/resources/nested.yml
new file mode 100644
index 0000000..3b2fef6
--- /dev/null
+++ b/webservice/test/resource_fixtures/nested/config/resources/nested.yml
@@ -0,0 +1,7 @@
+#
+# test/fixtures/resources/nested.yaml
+#
+
+interface: org.opensuse.yast.printer.devices
+controller: yast/printer/devices
+nested: queue
diff --git a/webservice/test/resource_fixtures/nested_singular/config/resources/nested_singluar.yml b/webservice/test/resource_fixtures/nested_singular/config/resources/nested_singluar.yml
new file mode 100644
index 0000000..ab49bcd
--- /dev/null
+++ b/webservice/test/resource_fixtures/nested_singular/config/resources/nested_singluar.yml
@@ -0,0 +1,8 @@
+#
+# test/fixtures/resources/nested_singular.yaml
+#
+
+interface: org.opensuse.yast.printer.device
+controller: yast/printer/device
+singular: true
+nested: queue
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org