Commit 33abb5b80251548c9dbefb3edaef2efaa31abfb1
1 parent
1e637035
Exists in
master
and in
1 other branch
airbrake API 2.3 support
Showing
6 changed files
with
25 additions
and
6 deletions
Show diff stats
app/models/error_report.rb
... | ... | @@ -2,7 +2,7 @@ require 'digest/md5' |
2 | 2 | require 'hoptoad_notifier' |
3 | 3 | |
4 | 4 | class ErrorReport |
5 | - attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes | |
5 | + attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes, :current_user | |
6 | 6 | |
7 | 7 | def initialize(xml_or_attributes) |
8 | 8 | @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 |
41 | 41 | :request => request, |
42 | 42 | :server_environment => server_environment, |
43 | 43 | :notifier => notifier, |
44 | - :user_attributes => user_attributes) | |
44 | + :user_attributes => user_attributes, | |
45 | + :current_user => current_user | |
46 | + ) | |
45 | 47 | |
46 | 48 | err = app.find_or_create_err!( |
47 | 49 | :error_class => error_class, | ... | ... |
app/models/notice.rb
lib/hoptoad.rb
... | ... | @@ -3,7 +3,7 @@ require 'hoptoad/v2' |
3 | 3 | module Hoptoad |
4 | 4 | class ApiVersionError < StandardError |
5 | 5 | def initialize |
6 | - super "Wrong API Version: Expecting 2.0, 2.1, or 2.2" | |
6 | + super "Wrong API Version: Expecting 2.0, 2.1, 2.2 or 2.3" | |
7 | 7 | end |
8 | 8 | end |
9 | 9 | |
... | ... | @@ -16,7 +16,7 @@ module Hoptoad |
16 | 16 | private |
17 | 17 | def self.get_version_processor(version) |
18 | 18 | case version |
19 | - when /2\.[012]/; Hoptoad::V2 | |
19 | + when /2\.[0123]/; Hoptoad::V2 | |
20 | 20 | else; raise ApiVersionError |
21 | 21 | end |
22 | 22 | end | ... | ... |
lib/hoptoad/v2.rb
... | ... | @@ -59,7 +59,8 @@ module Hoptoad |
59 | 59 | |
60 | 60 | :api_key => notice['api-key'], |
61 | 61 | :notifier => notice['notifier'], |
62 | - :user_attributes => notice['user-attributes'] || {} | |
62 | + :user_attributes => notice['user-attributes'] || {}, | |
63 | + :current_user => notice['current-user'] || {} | |
63 | 64 | } |
64 | 65 | end |
65 | 66 | end | ... | ... |
spec/fixtures/hoptoad_test_notice.xml
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | -<notice version="2.0"> | |
2 | +<notice version="2.3"> | |
3 | 3 | <api-key>APIKEY</api-key> |
4 | 4 | <notifier> |
5 | 5 | <name>Hoptoad Notifier</name> |
... | ... | @@ -144,4 +144,10 @@ |
144 | 144 | <project-root>/path/to/sample/project</project-root> |
145 | 145 | <environment-name>development</environment-name> |
146 | 146 | </server-environment> |
147 | + <current-user> | |
148 | + <id>123</id> | |
149 | + <name>Mr. Bean</name> | |
150 | + <email>mr.bean@example.com</email> | |
151 | + <username>mrbean</username> | |
152 | + </current-user> | |
147 | 153 | </notice> | ... | ... |
spec/models/app_spec.rb
... | ... | @@ -230,6 +230,15 @@ describe App do |
230 | 230 | lambda { @notice = App.report_error!(xml) }.should_not raise_error |
231 | 231 | @notice.backtrace.length.should == 1 |
232 | 232 | end |
233 | + | |
234 | + it 'captures the current_user' do | |
235 | + @notice = App.report_error!(@xml) | |
236 | + @notice.current_user['id'].should == '123' | |
237 | + @notice.current_user['name'].should == 'Mr. Bean' | |
238 | + @notice.current_user['email'].should == 'mr.bean@example.com' | |
239 | + @notice.current_user['username'].should == 'mrbean' | |
240 | + end | |
241 | + | |
233 | 242 | end |
234 | 243 | |
235 | 244 | ... | ... |