From 1d463d22a1336e592f92f6e3b7f54bcbd717e37e Mon Sep 17 00:00:00 2001
From: Raphael <raphael@joindiaspora.com>
Date: Thu, 7 Oct 2010 16:50:19 -0700
Subject: [PATCH] Person show for a nonexistent person now redirects to people
 index page, rather than giving a 500

---
 app/controllers/people_controller.rb       | 14 +++++++++++++-
 spec/controllers/people_controller_spec.rb |  8 ++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb
index 6ada5bfe19..1e5ef5c235 100644
--- a/app/controllers/people_controller.rb
+++ b/app/controllers/people_controller.rb
@@ -17,7 +17,19 @@ class PeopleController < ApplicationController
   end
 
   def show
-    @person = current_user.visible_person_by_id(params[:id])
+    begin
+      @person = current_user.visible_person_by_id(params[:id])
+    rescue BSON::InvalidObjectId
+      flash[:error] = "Person not found."
+      redirect_to people_path
+      return
+    end
+    unless @person
+      flash[:error] = "Person not found."
+      redirect_to people_path
+      return
+    end
+
     @profile = @person.profile
     @aspects_with_person = current_user.aspects_with_person(@person)
     @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]}
diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb
index c2af4cc933..ab15625d03 100644
--- a/spec/controllers/people_controller_spec.rb
+++ b/spec/controllers/people_controller_spec.rb
@@ -22,4 +22,12 @@ describe PeopleController do
   it 'should go to the current_user show page' do
     get :show, :id => @user.person.id
   end
+
+  it "doesn't error out on an invalid id" do
+    get :show, :id => 'delicious'
+  end
+
+  it "doesn't error out on a nonexistent person" do
+    get :show, :id => @user.id
+  end
 end
-- 
GitLab