aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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