Skip to content

Commit

Permalink
Added numeric id constraint to accounts/campaigns/contacts/leads/oppo…
Browse files Browse the repository at this point in the history
…rtunities/tasks/users. This allows plugins to define routes such as /contacts/action and not have it overriden by our app if the plugin loads later. If we can find a better way to load plugin routes before the main application routes then this is no longer necessary.
  • Loading branch information
steveyken committed Dec 7, 2011
1 parent 6507f7e commit 51fd182
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 10 deletions.
14 changes: 7 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
resources :emails
resources :passwords

resources :accounts do
resources :accounts, :id => /\d+/ do
collection do
post :filter
get :options
Expand All @@ -34,7 +34,7 @@
end
end

resources :campaigns do
resources :campaigns, :id => /\d+/ do
collection do
post :filter
get :options
Expand All @@ -49,7 +49,7 @@
end
end

resources :contacts do
resources :contacts, :id => /\d+/ do
collection do
post :filter
get :options
Expand All @@ -64,7 +64,7 @@
end
end

resources :leads do
resources :leads, :id => /\d+/ do
collection do
post :filter
get :options
Expand All @@ -82,7 +82,7 @@
end
end

resources :opportunities do
resources :opportunities, :id => /\d+/ do
collection do
post :filter
get :options
Expand All @@ -97,7 +97,7 @@
end
end

resources :tasks do
resources :tasks, :id => /\d+/ do
collection do
post :filter
post :auto_complete
Expand All @@ -107,7 +107,7 @@
end
end

resources :users do
resources :users, :id => /\d+/ do
member do
get :avatar
get :password
Expand Down
16 changes: 16 additions & 0 deletions spec/routing/accounts_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
it "recognizes and generates #show" do
{ :get => "/accounts/1" }.should route_to(:controller => "accounts", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/accounts/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/accounts/1/edit" }.should route_to(:controller => "accounts", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/accounts/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/accounts" }.should route_to(:controller => "accounts", :action => "create")
end
Expand All @@ -27,10 +35,18 @@
{ :put => "/accounts/1" }.should route_to(:controller => "accounts", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/accounts/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/accounts/1" }.should route_to(:controller => "accounts", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/accounts/aaron" }.should_not be_routable
end

it "recognizes and generates #search" do
{ :get => "/accounts/search" }.should route_to( :controller => "accounts", :action => "search" )
end
Expand Down
17 changes: 16 additions & 1 deletion spec/routing/campaigns_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
{ :get => "/campaigns/1" }.should route_to(:controller => "campaigns", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/campaigns/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/campaigns/1/edit" }.should route_to(:controller => "campaigns", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/campaigns/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/campaigns" }.should route_to(:controller => "campaigns", :action => "create")
end
Expand All @@ -27,10 +35,18 @@
{ :put => "/campaigns/1" }.should route_to(:controller => "campaigns", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/campaigns/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/campaigns/1" }.should route_to(:controller => "campaigns", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/campaigns/aaron" }.should_not be_routable
end

it "recognizes and generates #search" do
{ :get => "/campaigns/search" }.should route_to( :controller => "campaigns", :action => "search" )
end
Expand All @@ -44,4 +60,3 @@
end
end
end

16 changes: 16 additions & 0 deletions spec/routing/contacts_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
{ :get => "/contacts/1" }.should route_to(:controller => "contacts", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/contacts/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/contacts/1/edit" }.should route_to(:controller => "contacts", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/campaigns/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/contacts" }.should route_to(:controller => "contacts", :action => "create")
end
Expand All @@ -27,10 +35,18 @@
{ :put => "/contacts/1" }.should route_to(:controller => "contacts", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/campaigns/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/contacts/1" }.should route_to(:controller => "contacts", :action => "destroy", :id => "1")
end

it "doesn't recognize #delete with non-numeric id" do
{ :delete => "/campaigns/aaron" }.should_not be_routable
end

it "recognizes and generates #search" do
{ :get => "/contacts/search" }.should route_to( :controller => "contacts", :action => "search" )
end
Expand Down
30 changes: 29 additions & 1 deletion spec/routing/leads_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
{ :get => "/leads/1" }.should route_to(:controller => "leads", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/leads/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/leads/1/edit" }.should route_to(:controller => "leads", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/leads/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/leads" }.should route_to(:controller => "leads", :action => "create")
end
Expand All @@ -27,10 +35,18 @@
{ :put => "/leads/1" }.should route_to(:controller => "leads", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/leads/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/leads/1" }.should route_to(:controller => "leads", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/leads/aaron" }.should_not be_routable
end

it "recognizes and generates #search" do
{ :get => "/leads/search" }.should route_to( :controller => "leads", :action => "search" )
end
Expand All @@ -47,13 +63,25 @@
{ :get => "/leads/1/convert" }.should route_to( :controller => "leads", :action => "convert", :id => "1" )
end

it "doesn't recognize #convert with non-numeric id" do
{ :get => "/leads/aaron/convert" }.should_not be_routable
end

it "should generate params for #promote" do
{ :put => "/leads/1/promote" }.should route_to( :controller => "leads", :action => "promote", :id => "1" )
end

it "doesn't recognize #promote with non-numeric id" do
{ :put => "/leads/aaron/promote" }.should_not be_routable
end

it "should generate params for #reject" do
{ :put => "/leads/1/reject" }.should route_to( :controller => "leads", :action => "reject", :id => "1" )
end

it "doesn't recognize #reject with non-numeric id" do
{ :put => "/leads/aaron/reject" }.should_not be_routable
end

end
end

16 changes: 16 additions & 0 deletions spec/routing/opportunities_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
{ :get => "/opportunities/1" }.should route_to(:controller => "opportunities", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/opportunities/1/edit" }.should route_to(:controller => "opportunities", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/opportunities/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/opportunities" }.should route_to(:controller => "opportunities", :action => "create")
end
Expand All @@ -27,10 +35,18 @@
{ :put => "/opportunities/1" }.should route_to(:controller => "opportunities", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/opportunities/1" }.should route_to(:controller => "opportunities", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #search" do
{ :get => "/opportunities/search" }.should route_to( :controller => "opportunities", :action => "search" )
end
Expand Down
21 changes: 20 additions & 1 deletion spec/routing/tasks_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
{ :get => "/tasks/1" }.should route_to(:controller => "tasks", :action => "show", :id => "1")
end

it "doesn't recognize #show with non-numeric id" do
{ :get => "/tasks/aaron" }.should_not be_routable
end

it "recognizes and generates #edit" do
{ :get => "/tasks/1/edit" }.should route_to(:controller => "tasks", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/opportunities/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/tasks" }.should route_to(:controller => "tasks", :action => "create")
end
Expand All @@ -27,17 +35,28 @@
{ :put => "/tasks/1" }.should route_to(:controller => "tasks", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/tasks/1" }.should route_to(:controller => "tasks", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #filter" do
{ :post => "/tasks/filter" }.should route_to( :controller => "tasks", :action => "filter" )
end

it "should generate params for #complete" do
{ :put => "/tasks/1/complete" }.should route_to( :controller => "tasks", :action => "complete", :id => "1" )
end

it "doesn't recognize #complete with non-numeric id" do
{ :put => "/opportunities/aaron/complete" }.should_not be_routable
end
end
end

28 changes: 28 additions & 0 deletions spec/routing/users_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{ :get => "/users/1/edit" }.should route_to(:controller => "users", :action => "edit", :id => "1")
end

it "doesn't recognize #edit with non-numeric id" do
{ :get => "/opportunities/aaron/edit" }.should_not be_routable
end

it "recognizes and generates #create" do
{ :post => "/users" }.should route_to(:controller => "users", :action => "create")
end
Expand All @@ -35,25 +39,49 @@
{ :put => "/users/1" }.should route_to(:controller => "users", :action => "update", :id => "1")
end

it "doesn't recognize #update with non-numeric id" do
{ :put => "/opportunities/aaron" }.should_not be_routable
end

it "recognizes and generates #destroy" do
{ :delete => "/users/1" }.should route_to(:controller => "users", :action => "destroy", :id => "1")
end

it "doesn't recognize #destroy with non-numeric id" do
{ :delete => "/opportunities/aaron" }.should_not be_routable
end

it "should generate params for #avatar" do
{ :get => "/users/1/avatar" }.should route_to( :controller => "users", :action => "avatar", :id => "1" )
end

it "doesn't recognize #avatar with non-numeric id" do
{ :get => "/opportunities/aaron/avatar" }.should_not be_routable
end

it "should generate params for #upload_avatar" do
{ :put => "/users/1/upload_avatar" }.should route_to( :controller => "users", :action => "upload_avatar", :id => "1" )
end

it "doesn't recognize #upload_avatar with non-numeric id" do
{ :put => "/opportunities/aaron/upload_avatar" }.should_not be_routable
end

it "should generate params for #password" do
{ :get => "/users/1/password" }.should route_to( :controller => "users", :action => "password", :id => "1" )
end

it "doesn't recognize #password with non-numeric id" do
{ :get => "/opportunities/aaron/password" }.should_not be_routable
end

it "should generate params for #change_password" do
{ :put => "/users/1/change_password" }.should route_to( :controller => "users", :action => "change_password", :id => "1" )
end

it "doesn't recognize #change_password with non-numeric id" do
{ :put => "/opportunities/aaron/change_password" }.should_not be_routable
end
end
end

0 comments on commit 51fd182

Please sign in to comment.