Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Created Oct 27, 2010
Embed
What would you like to do?
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