Commit ddd5ea9b93bf565880c43b4a72e650e8078d71c2

Authored by Arthur Nogueira Neves
2 parents 728da5f0 bd728b45
Exists in master and in 1 other branch production

Merge pull request #676 from csaunders/fingerprint_strategies

Allow fingerprint generation to be configured
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 {
... ...