Skip to content

Commit

Permalink
More primitive routing has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed May 1, 2008
1 parent b348cb2 commit 9aac0cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/zoid/application.rb
Expand Up @@ -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

Expand Down
28 changes: 21 additions & 7 deletions spec/routing_spec.rb
@@ -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.