aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-08-03 14:18:22 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-08-03 14:18:22 +0100
commitcd73e401622d31a189d8cf3b38e9cbe46ca73e96 (patch)
treee5efd1f1a4c650ec4333a59d54d015342e24ddbf
parentf5e5b605bac9e80f7556b666643eec25b6987545 (diff)
Fail silently if there's no user matching one referenced in the current session. Fixes #105
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--spec/controllers/general_controller_spec.rb7
2 files changed, 12 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5f18be2e5..ba1cf4900 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -221,7 +221,11 @@ class ApplicationController < ActionController::Base
if session[:user_id].nil?
return nil
else
- return User.find(session[:user_id])
+ begin
+ return User.find(session[:user_id])
+ rescue ActiveRecord::RecordNotFound
+ return nil
+ end
end
end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 7807a5541..619635eea 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -17,6 +17,13 @@ describe GeneralController, "when searching" do
response.should be_success
end
+ it "doesn't raise an error when there's no user matching the one in the session" do
+ session[:user_id] = 999
+ get :frontpage
+ response.should be_success
+ end
+
+
it "should redirect from search query URL to pretty URL" do
post :search_redirect, :query => "mouse" # query hidden in POST parameters
response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query