Skip to content

Commit

Permalink
Some initial specs for routing added (not much :)
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed May 1, 2008
1 parent 8ff9e8d commit 56dcfd0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/zoid/application.rb
Expand Up @@ -3,5 +3,19 @@ module Zoid
Application = StrokeDB::Meta.new do
validates_presence_of :name
validates_presence_of :nsurl

def route_for(method, path)
case path
when /^\/(\w+)(\/)?$/
app_module.const_get($1.camelize)
end
end

private

def app_module
@module ||= Module.find_by_nsurl(nsurl)
end

end
end
19 changes: 19 additions & 0 deletions spec/routing_spec.rb
@@ -0,0 +1,19 @@
require File.dirname(__FILE__) + '/spec_helper'

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)
end

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')
end

end
7 changes: 7 additions & 0 deletions spec/spec.opts
@@ -0,0 +1,7 @@
--colour
--format
progress
--loadby
mtime
--reverse
--backtrace
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,11 @@
$LOAD_PATH.unshift( File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) ).uniq!
require 'zoid'

SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
TEMP_DIR = SPEC_ROOT + '/tmp'
TEMP_STORAGES = TEMP_DIR + '/storages'

def setup_default_store
FileUtils.rm_rf TEMP_STORAGES + '/spec'
StrokeDB::Config.build :default => true, :base_path => TEMP_STORAGES + '/spec'
end

0 comments on commit 56dcfd0

Please sign in to comment.