Permalink
Browse files

More primitive routing has been added

  • Loading branch information...
1 parent b348cb2 commit 9aac0cf6842f71ccc8bd8732341bbcd3c07a7051 @yrashk committed May 1, 2008
Showing with 26 additions and 8 deletions.
  1. +5 −1 lib/zoid/application.rb
  2. +21 −7 spec/routing_spec.rb
View
@@ -6,8 +6,12 @@ module Zoid
def route_for(method, path)
case path
- when /^\/(\w+)(\/)?$/
+ when /^\/(\w+)[\/]?$/
app_module.const_get($1.camelize)
+ when /^\/(\w+)\/#{StrokeDB::UUID_RE}$/
+ store.find($2)
+ when /^\/(\w+)\/#{StrokeDB::UUID_RE}.#{StrokeDB::UUID_RE}$/
+ store.find($2,$3)
end
end
View
@@ -1,19 +1,33 @@
require File.dirname(__FILE__) + '/spec_helper'
+module RoutingExample
+ nsurl 'http://strokedb.com/zoid/spec#routing'
+ remove_const(:SomeName) if defined?(SomeName)
+ SomeName = StrokeDB::Meta.new
+end
+
+
describe Zoid::Application, "router" do
before(:each) do
setup_default_store
- @module = Module.new do
- nsurl 'http://strokedb.com/zoid/spec#routing'
- SomeName = StrokeDB::Meta.new
- end
- @app = Zoid::Application.create!(:name => 'Routing Application', :nsurl => @module.nsurl)
+ @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 == @module.const_get('SomeName')
- @app.route_for('GET', '/some_name/').should == @module.const_get('SomeName')
+ @app.route_for('GET', '/some_name').should == RoutingExample::SomeName
+ @app.route_for('GET', '/some_name/').should ==RoutingExample::SomeName
+ end
+
+ it "should route GET + /name/uuid to a named entity with specified UUID" do
+ doc = RoutingExample::SomeName.create!
+ @app.route_for('GET', "/some_name/#{doc.uuid}").should == doc
+ end
+
+ it "should route GET + /name/uuid.version to a named entity with specified UUID" do
+ doc = RoutingExample::SomeName.create!.versions.current
+ @app.route_for('GET', "/some_name/#{doc.uuid}.#{doc.version}").should == doc
end
end

0 comments on commit 9aac0cf

Please sign in to comment.