Commit ddd5ea9b93bf565880c43b4a72e650e8078d71c2
Exists in
master
and in
1 other branch
Merge pull request #676 from csaunders/fingerprint_strategies
Allow fingerprint generation to be configured
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
app/models/error_report.rb
| @@ -17,6 +17,10 @@ require 'hoptoad_notifier' | @@ -17,6 +17,10 @@ require 'hoptoad_notifier' | ||
| 17 | class ErrorReport | 17 | class ErrorReport |
| 18 | attr_reader :error_class, :message, :request, :server_environment, :api_key, :notifier, :user_attributes, :framework | 18 | attr_reader :error_class, :message, :request, :server_environment, :api_key, :notifier, :user_attributes, :framework |
| 19 | 19 | ||
| 20 | + cattr_accessor :fingerprint_strategy do | ||
| 21 | + Fingerprint | ||
| 22 | + end | ||
| 23 | + | ||
| 20 | def initialize(xml_or_attributes) | 24 | def initialize(xml_or_attributes) |
| 21 | @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access | 25 | @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access |
| 22 | @attributes.each{|k, v| instance_variable_set(:"@#{k}", v) } | 26 | @attributes.each{|k, v| instance_variable_set(:"@#{k}", v) } |
| @@ -84,7 +88,7 @@ class ErrorReport | @@ -84,7 +88,7 @@ class ErrorReport | ||
| 84 | private | 88 | private |
| 85 | 89 | ||
| 86 | def fingerprint | 90 | def fingerprint |
| 87 | - @fingerprint ||= Fingerprint.generate(notice, api_key) | 91 | + @fingerprint ||= fingerprint_strategy.generate(notice, api_key) |
| 88 | end | 92 | end |
| 89 | 93 | ||
| 90 | end | 94 | end |
spec/models/error_report_spec.rb
| @@ -47,6 +47,19 @@ describe ErrorReport do | @@ -47,6 +47,19 @@ describe ErrorReport do | ||
| 47 | end | 47 | end |
| 48 | end | 48 | end |
| 49 | 49 | ||
| 50 | + describe "#fingerprint_strategy" do | ||
| 51 | + after(:all) { | ||
| 52 | + error_report.fingerprint_strategy = Fingerprint | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + it "should be possible to change how fingerprints are generated" do | ||
| 56 | + strategy = double() | ||
| 57 | + strategy.should_receive(:generate){ 'fingerprints' } | ||
| 58 | + error_report.fingerprint_strategy = strategy | ||
| 59 | + error_report.generate_notice! | ||
| 60 | + end | ||
| 61 | + end | ||
| 62 | + | ||
| 50 | describe "#generate_notice!" do | 63 | describe "#generate_notice!" do |
| 51 | it "save a notice" do | 64 | it "save a notice" do |
| 52 | expect { | 65 | expect { |