From 2d44107b5d54e99d57360fee024b99c873211e65 Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Thu, 9 Oct 2014 23:08:33 +1300 Subject: [PATCH] Allow nil HTTP user agent --- app/controllers/application_controller.rb | 2 +- spec/controllers/application_controller_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f95636f60..327b6068c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,7 +36,7 @@ class ApplicationController < ActionController::Base def after_sign_out_path_for(resource_or_scope) # mobile_fu's is_mobile_device? wasn't working here for some reason... # it may have been just because of the test env. - if request.env['HTTP_USER_AGENT'].match(/mobile/i) + if request.env['HTTP_USER_AGENT'].try(:match, /mobile/i) root_path else new_user_session_path diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 1b2e44ff3..3910e9461 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -91,4 +91,11 @@ describe ApplicationController, :type => :controller do end end end + + describe "#after_sign_out_path_for" do + it "can handle a nil HTTP_USER_AGENT" do + @request.headers["HTTP_USER_AGENT"] = nil + expect(@controller.send(:after_sign_out_path_for, alice)).to eq(new_user_session_path) + end + end end