Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

View routing

  • Loading branch information...
commit 4644ec5255fd548bb8c8ed0303d3937df09f2a1d 1 parent 9aac0cf
Yurii Rashkovskii authored
7 lib/zoid/application.rb
View
@@ -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}$/
16 spec/routing_spec.rb
View
@@ -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
6 spec/spec_helper.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.