Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Created October 27, 2010 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedelchop/649430 to your computer and use it in GitHub Desktop.
Save thedelchop/649430 to your computer and use it in GitHub Desktop.
Here are my routes for this app.
require "spec_helper"
describe PagesController do
describe "routing" do
it "recognizes and generates #home" do
{ :get => "/pages/home" }.should route_to(:controller => "pages", :action => "home")
end
context "when no user is signed in" do
it "routes the root route to pages#home" do
RootConstraints.stub!(:matches?).and_return(false)
{ :get => '/' }.should route_to(:controller => "pages", :action => "home")
end
end
context "when a user is already signed in" do
it "routes the root route to 'lists#show/master" do
RootConstraints.stub!(:matches?).and_return(true)
{ :get => '/' }.should route_to(:controller => "lists", :action => "show", :id => "master")
end
end
end
end
class RootConstraints
def self.matches?(request)
if request.env['warden'].authenticated?(:user)
return true
else
return false
end
end
end
require 'lib/root_constraints'
Tuhmayta::Application.routes.draw do
get "pages/home"
constraints(RootConstraints) do
root :controller => "lists", :action => "show", :id => "master"
end
root :to => "pages#home"
devise_for :users do
resources :tasks
resources :lists do
member do
post :sort
post :add
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment