diff --git a/app/models/error_report.rb b/app/models/error_report.rb index 68c3aa5..97b435b 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -2,7 +2,7 @@ require 'digest/md5' require 'hoptoad_notifier' class ErrorReport - attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes + attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes, :current_user def initialize(xml_or_attributes) @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access @@ -41,7 +41,9 @@ class ErrorReport :request => request, :server_environment => server_environment, :notifier => notifier, - :user_attributes => user_attributes) + :user_attributes => user_attributes, + :current_user => current_user + ) err = app.find_or_create_err!( :error_class => error_class, diff --git a/app/models/notice.rb b/app/models/notice.rb index 1e5fa92..9afd13c 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -11,6 +11,7 @@ class Notice field :request, :type => Hash field :notifier, :type => Hash field :user_attributes, :type => Hash + field :current_user, :type => Hash field :error_class belongs_to :err diff --git a/lib/hoptoad.rb b/lib/hoptoad.rb index 7e84723..2c7912a 100644 --- a/lib/hoptoad.rb +++ b/lib/hoptoad.rb @@ -3,7 +3,7 @@ require 'hoptoad/v2' module Hoptoad class ApiVersionError < StandardError def initialize - super "Wrong API Version: Expecting 2.0, 2.1, or 2.2" + super "Wrong API Version: Expecting 2.0, 2.1, 2.2 or 2.3" end end @@ -16,7 +16,7 @@ module Hoptoad private def self.get_version_processor(version) case version - when /2\.[012]/; Hoptoad::V2 + when /2\.[0123]/; Hoptoad::V2 else; raise ApiVersionError end end diff --git a/lib/hoptoad/v2.rb b/lib/hoptoad/v2.rb index ea9ed6f..89aa006 100644 --- a/lib/hoptoad/v2.rb +++ b/lib/hoptoad/v2.rb @@ -59,7 +59,8 @@ module Hoptoad :api_key => notice['api-key'], :notifier => notice['notifier'], - :user_attributes => notice['user-attributes'] || {} + :user_attributes => notice['user-attributes'] || {}, + :current_user => notice['current-user'] || {} } end end diff --git a/spec/fixtures/hoptoad_test_notice.xml b/spec/fixtures/hoptoad_test_notice.xml index f1c863e..3b4591d 100644 --- a/spec/fixtures/hoptoad_test_notice.xml +++ b/spec/fixtures/hoptoad_test_notice.xml @@ -1,5 +1,5 @@ - + APIKEY Hoptoad Notifier @@ -144,4 +144,10 @@ /path/to/sample/project development + + 123 + Mr. Bean + mr.bean@example.com + mrbean + diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 1e4dcc3..c13cde1 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -230,6 +230,15 @@ describe App do lambda { @notice = App.report_error!(xml) }.should_not raise_error @notice.backtrace.length.should == 1 end + + it 'captures the current_user' do + @notice = App.report_error!(@xml) + @notice.current_user['id'].should == '123' + @notice.current_user['name'].should == 'Mr. Bean' + @notice.current_user['email'].should == 'mr.bean@example.com' + @notice.current_user['username'].should == 'mrbean' + end + end -- libgit2 0.21.2