From 0fa0b7e950c569f469552aca50ccb9363909c8f0 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Thu, 27 Jan 2011 11:30:15 -0800 Subject: [PATCH 1/2] fixed syntax error in mobile layout. removed ipad from mobile_fu --- app/controllers/application_controller.rb | 11 ----------- app/views/layouts/application.mobile.haml | 2 +- vendor/plugins/mobile-fu/lib/mobile_fu.rb | 3 ++- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b81d118f5..cd93e0b43 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,6 @@ class ApplicationController < ActionController::Base has_mobile_fu protect_from_forgery :except => :receive - #before_filter :mobile_except_ipad before_filter :set_contacts_notifications_and_status, :except => [:create, :update] before_filter :count_requests before_filter :set_invites @@ -21,16 +20,6 @@ class ApplicationController < ActionController::Base end end - def mobile_except_ipad - if is_mobile_device? - if request.env["HTTP_USER_AGENT"].include? "iPad" - session[:mobile_view] = false - else - session[:mobile_view] = true - end - end - end - def count_requests @request_count = Request.where(:recipient_id => current_user.person.id).count if current_user end diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index e301d75b9..0d0fa3f0b 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -90,7 +90,7 @@ #footer - = link_to t('.logged_in_as' :name => current_user.name), current_user.person + = link_to t('.logged_in_as', :name => current_user.name), current_user.person %br %br diff --git a/vendor/plugins/mobile-fu/lib/mobile_fu.rb b/vendor/plugins/mobile-fu/lib/mobile_fu.rb index fbe49f28a..593ad7660 100644 --- a/vendor/plugins/mobile-fu/lib/mobile_fu.rb +++ b/vendor/plugins/mobile-fu/lib/mobile_fu.rb @@ -2,11 +2,12 @@ module ActionController module MobileFu # These are various strings that can be found in mobile devices. Please feel free # to add on to this list. + # removed ipad because ipad isn't a mobile device MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' + 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' + 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' + 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' + - 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' + + 'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|' + 'mobile' def self.included(base) From a6f8b2c14ed7ec13f2ecd113ae809a072814ab50 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 27 Jan 2011 11:44:17 -0800 Subject: [PATCH 2/2] Add splunk logging for errors --- lib/log_overrider.rb | 17 +++++++++++++ spec/controllers/aspects_controller_spec.rb | 13 ++++++++++ spec/shared_behaviors/log_override.rb | 27 +++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/lib/log_overrider.rb b/lib/log_overrider.rb index 47df57b97..6ef3dcf72 100644 --- a/lib/log_overrider.rb +++ b/lib/log_overrider.rb @@ -11,6 +11,23 @@ class ActionView::LogSubscriber alias :render_collection :render_template end +module ActionDispatch + class ShowExceptions + private + def log_error(exception) + return unless logger + + ActiveSupport::Deprecation.silence do + message = "event=error error_class=#{exception.class} error_message='#{exception.message}' " + message << "orig_error_message='#{exception.original_exception.message}'" if exception.respond_to?(:original_exception) + message << "annotated_source='#{exception.annoted_source_code.to_s}' " if exception.respond_to?(:annoted_source_code) + message << "app_backtrace='#{application_trace(exception).join(";")}'" + logger.fatal("\n\n#{message}\n\n") + end + end + end +end + class ActionController::LogSubscriber def start_processing(event) #noop diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 57ec10329..11fe163a3 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -31,6 +31,19 @@ describe AspectsController do it_should_behave_like "it overrides the logs on success" end + describe "custom logging on error" do + class FakeError < RuntimeError; attr_accessor :original_exception; end + before do + @action = :index + @desired_error_message = "I love errors" + @error = FakeError.new(@desired_error_message) + @orig_error_message = "I loooooove nested errors!" + @error.original_exception = NoMethodError.new(@orig_error_message) + @controller.stub(:index).and_raise(@error) + end + it_should_behave_like "it overrides the logs on error" + end + describe "custom logging on redirect" do before do @action = :show diff --git a/spec/shared_behaviors/log_override.rb b/spec/shared_behaviors/log_override.rb index 8a604ec08..f91538215 100644 --- a/spec/shared_behaviors/log_override.rb +++ b/spec/shared_behaviors/log_override.rb @@ -1,12 +1,18 @@ class FakeLogger attr_accessor :infos + attr_accessor :lines def initialize self.infos = [] + self.lines = [] end def info line self.infos << line + self.lines << line + end + def fatal line + self.lines << line end end @@ -51,6 +57,27 @@ shared_examples_for 'it overrides the logs on success' do end end +shared_examples_for 'it overrides the logs on error' do + before do + Rails.stub(:logger).and_return(FakeLogger.new) + begin + get @action, @action_params + rescue Exception => e + ActionDispatch::ShowExceptions.new(nil).send(:log_error,e) + end + @line = Rails.logger.lines.last + end + it 'logs the backtrace' do + @line.should =~ /app_backtrace=/ + end + it 'logs the error message' do + @line.should =~ /error_message='#{@desired_error_message}'/ + end + it 'logs the original error message, if it exists' do + @line.should =~ /orig_error_message='#{@orig_error_message}'/ if @orig_error_message + end +end + shared_examples_for 'it overrides the logs on redirect' do before do Rails.stub(:logger).and_return(FakeLogger.new)