0
require File.join(File.dirname(__FILE__), '..', "spec_helper")
0
+# Namespacing everything so that all the spec classes aren't shared
0
@@ -19,9 +21,12 @@ module ID
0
def url ; "awesome" ; end
0
- def to_s ; "user" ; end
0
- def name ; "carl" ; end
0
+ def to_s ; "user" ; end
0
+ def name ; "carl" ; end
0
+ def first_name ; "john" ; end
0
+ def last_name ; "doe" ; end
0
@@ -31,77 +36,128 @@ module ID
0
-describe "When generating URLs," do
0
- Merb::Router.prepare do
0
- identify ID::Account => :url, ID::User => :name, ID::ORM => :id, ID::Resource => :identifier do
0
+ describe "When generating URLs," do
0
+ Merb::Router.prepare do
0
+ identify Account => :url, User => :name, ORM => :id, Resource => :identifier do
0
+ match("/resources/:id").name(:resource)
0
- match("/resources/:id").name(:resource)
0
- describe "a route with custom identifiers" do
0
- it "should use #to_s if no other identifier is set" do
0
- url(:resource, :id => ID::Article.new).should == "/resources/article"
0
- url(:resource, :id => ID::Account.new).should == "/resources/account"
0
- url(:resource, :id => ID::User.new).should == "/resources/user"
0
- url(:resource, :id => ID::Something.new).should == "/resources/hello"
0
- it "should use the identifier for the object" do
0
- url(:user, :account => ID::Account.new, :id => ID::User.new).should == "/awesome/users/carl"
0
- it "should be able to use identifiers for parent classes" do
0
- url(:user, :account => ID::Article.new, :id => 1).should == "/10/users/1"
0
- it "should be able to use identifiers for included modules" do
0
- url(:user, :account =>ID:: WithInclusions.new, :id => '1').should == "/included/users/1"
0
- it "should not require a block" do
0
- Merb::Router.prepare do
0
- identify(ID::Account => :url).match("/:account").name(:account)
0
+ describe "a route with custom identifiers" do
0
+ it "should use #to_s if no other identifier is set" do
0
+ url(:resource, :id => Article.new).should == "/resources/article"
0
+ url(:resource, :id => Account.new).should == "/resources/account"
0
+ url(:resource, :id => User.new).should == "/resources/user"
0
+ url(:resource, :id => Something.new).should == "/resources/hello"
0
- url(:account, :account => ID::Account.new).should == "/awesome"
0
- it "should combine identifiers when nesting" do
0
- Merb::Router.prepare do
0
- identify ID::Account => :url do
0
- identify ID::User => :name do
0
- match("/:account").resources :users
0
+ it "should use #to_s if no other identifier is set when params are anonymous" do
0
+ url(:resource, Article.new).should == "/resources/article"
0
+ url(:resource, Account.new).should == "/resources/account"
0
+ url(:resource, User.new).should == "/resources/user"
0
+ url(:resource, Something.new).should == "/resources/hello"
0
+ it "should use the identifier for the object" do
0
+ url(:user, :account => Account.new, :id => User.new).should == "/awesome/users/carl"
0
+ it "should use the identifier for the object when the params are anonymous" do
0
+ url(:user, Account.new, User.new).should == "/awesome/users/carl"
0
+ it "should be able to use identifiers for parent classes" do
0
+ url(:user, :account => Article.new, :id => 1).should == "/10/users/1"
0
+ it "should be able to use identifiers for parent classes when the params are anonymous" do
0
+ url(:user, Article.new, 1).should == "/10/users/1"
0
+ it "should be able to use identifiers for included modules" do
0
+ url(:user, :account => WithInclusions.new, :id => '1').should == "/included/users/1"
0
+ it "should be able to use identifiers for included modules when the params are anonymous" do
0
+ url(:user, WithInclusions.new, '1').should == "/included/users/1"
0
+ it "should be able to specify an array of identifiers" do
0
+ Merb::Router.prepare do
0
+ identify(User => [:last_name, :first_name]) do
0
+ match("/users/:last_name/:first_name").name(:users)
0
+ url(:users, :last_name => User.new, :first_name => User.new).should == "/users/doe/john"
0
- url(:user, :account => ID::Account.new, :id => ID::User.new).should == "/awesome/users/carl"
0
- it "should retain previously set conditions" do
0
- Merb::Router.prepare do
0
- register.name(:account)
0
- identify ID::Account => :url do
0
+ it "should be able to specify an array of identifiers when the params are anonymous" do
0
+ Merb::Router.prepare do
0
+ identify(User => [:last_name, :first_name]) do
0
+ match("/users/:last_name/:first_name").name(:users)
0
+ url(:users, User.new).should == "/users/doe/john"
0
- url(:account, :account => ID::Account.new).should == "/account"
0
- url(:user, :account => ID::Account.new, :id => ID::User.new).should == "/awesome/users/user"
0
+ it "should be able to treat :id correctly with Array identifiers" do
0
+ Merb::Router.prepare do
0
+ identify(User => [:name, :id]) do
0
+ resources :users, :keys => [:name, :id] do
0
+ url(:user_comments, :name => User.new, :user_id => User.new).should == "/users/carl/10/comments"
0
+ it "should not require a block" do
0
+ Merb::Router.prepare do
0
+ identify(Account => :url).match("/:account").name(:account)
0
+ url(:account, :account => Account.new).should == "/awesome"
0
+ it "should combine identifiers when nesting" do
0
+ Merb::Router.prepare do
0
+ identify Account => :url do
0
+ identify User => :name do
0
+ match("/:account").resources :users
0
+ url(:user, :account => Account.new, :id => User.new).should == "/awesome/users/carl"
0
+ it "should retain previously set conditions" do
0
+ Merb::Router.prepare do
0
+ register.name(:account)
0
+ identify Account => :url do
0
+ url(:account, :account => Account.new).should == "/account"
0
+ url(:user, :account => Account.new, :id => User.new).should == "/awesome/users/user"
0
\ No newline at end of file
Comments
No one has commented yet.