From 4644ec5255fd548bb8c8ed0303d3937df09f2a1d Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Thu, 1 May 2008 07:18:06 +0300 Subject: [PATCH] View routing --- lib/zoid/application.rb | 7 ++++++- spec/routing_spec.rb | 16 ++++++++++++---- spec/spec_helper.rb | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/zoid/application.rb b/lib/zoid/application.rb index 53616b3..ad4222f 100644 --- a/lib/zoid/application.rb +++ b/lib/zoid/application.rb @@ -7,7 +7,12 @@ module Zoid def route_for(method, path) case path when /^\/(\w+)[\/]?$/ - app_module.const_get($1.camelize) + case entity = app_module.const_get($1.camelize) + when StrokeDB::Meta + entity.document + when StrokeDB::View + entity + end when /^\/(\w+)\/#{StrokeDB::UUID_RE}$/ store.find($2) when /^\/(\w+)\/#{StrokeDB::UUID_RE}.#{StrokeDB::UUID_RE}$/ diff --git a/spec/routing_spec.rb b/spec/routing_spec.rb index a1d734e..82c6fcf 100644 --- a/spec/routing_spec.rb +++ b/spec/routing_spec.rb @@ -4,20 +4,28 @@ module RoutingExample nsurl 'http://strokedb.com/zoid/spec#routing' remove_const(:SomeName) if defined?(SomeName) SomeName = StrokeDB::Meta.new + SomeView = StrokeDB::View.create!("SomeView") do |view| + def view.map(key,val) + end + end end describe Zoid::Application, "router" do before(:each) do - setup_default_store @app = Zoid::Application.create!(:name => 'Routing Application', :nsurl => RoutingExample.nsurl) end # GET - it "should route GET + /name(/)? to a named entity within application module" do - @app.route_for('GET', '/some_name').should == RoutingExample::SomeName - @app.route_for('GET', '/some_name/').should ==RoutingExample::SomeName + it "should route GET + /name(/)? to a meta document within application module" do + @app.route_for('GET', '/some_name').should == RoutingExample::SomeName.document + @app.route_for('GET', '/some_name/').should == RoutingExample::SomeName.document + end + + it "should route GET + /name(/)? to a view document within application module" do + @app.route_for('GET', '/some_view').should == RoutingExample::SomeView + @app.route_for('GET', '/some_view/').should == RoutingExample::SomeView end it "should route GET + /name/uuid to a named entity with specified UUID" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index defd629..cf23199 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,4 +8,10 @@ def setup_default_store FileUtils.rm_rf TEMP_STORAGES + '/spec' StrokeDB::Config.build :default => true, :base_path => TEMP_STORAGES + '/spec' +end + +setup_default_store + +at_exit do + FileUtils.rm_rf TEMP_STORAGES + '/spec' end \ No newline at end of file