Skip to content

Commit

Permalink
View routing
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed May 1, 2008
1 parent 9aac0cf commit 4644ec5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/zoid/application.rb
Expand Up @@ -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}$/
Expand Down
16 changes: 12 additions & 4 deletions spec/routing_spec.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -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

0 comments on commit 4644ec5

Please sign in to comment.