Commit bd728b45026a2a00f79011e47584b328fd98ef54

Authored by Chris Saunders
1 parent 728da5f0
Exists in master and in 1 other branch production

Allow fingerprint generation to be configured

Legacy versions of errbit used different strategy for
generating the method signatures for duplicate duplication.

This allows custom signatures to be easily dropped in via
methods such as an initializer.
app/models/error_report.rb
... ... @@ -17,6 +17,10 @@ require 'hoptoad_notifier'
17 17 class ErrorReport
18 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 24 def initialize(xml_or_attributes)
21 25 @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access
22 26 @attributes.each{|k, v| instance_variable_set(:"@#{k}", v) }
... ... @@ -84,7 +88,7 @@ class ErrorReport
84 88 private
85 89  
86 90 def fingerprint
87   - @fingerprint ||= Fingerprint.generate(notice, api_key)
  91 + @fingerprint ||= fingerprint_strategy.generate(notice, api_key)
88 92 end
89 93  
90 94 end
... ...
spec/models/error_report_spec.rb
... ... @@ -47,6 +47,19 @@ describe ErrorReport do
47 47 end
48 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 63 describe "#generate_notice!" do
51 64 it "save a notice" do
52 65 expect {
... ...