Commit a8af7b22ca29ff534a2f7a01d33c10135d14b4a1

Authored by Stephen Crosby
1 parent 2b589530
Exists in master

generate notice_fingerprinter on access

Showing 2 changed files with 19 additions and 0 deletions   Show diff stats
app/models/app.rb
... ... @@ -31,6 +31,7 @@ class App
31 31 before_validation :generate_api_key, on: :create
32 32 before_save :normalize_github_repo
33 33 before_create :build_notice_fingerprinter
  34 + after_find :build_notice_fingerprinter
34 35 after_update :store_cached_attributes_on_problems
35 36  
36 37 validates :name, :api_key, presence: true, uniqueness: { allow_blank: true }
... ... @@ -54,6 +55,9 @@ class App
54 55 }
55 56  
56 57 def build_notice_fingerprinter
  58 + # no need to build a notice_fingerprinter if we already have one
  59 + return if notice_fingerprinter.present?
  60 +
57 61 attrs = SiteConfig.document.notice_fingerprinter_attributes
58 62 self.notice_fingerprinter = attrs
59 63 end
... ...
spec/models/app_spec.rb
... ... @@ -220,4 +220,19 @@ describe App, type: 'model' do
220 220 end.to raise_error(Mongoid::Errors::DocumentNotFound)
221 221 end
222 222 end
  223 +
  224 + describe '#notice_fingerprinter' do
  225 + it 'app acquires a notice_fingerprinter when it doesn\'t have one' do
  226 + app = Fabricate(:app, name: 'Errbit')
  227 + app.notice_fingerprinter.delete
  228 +
  229 + # has a notice_fingerprinter because it's been accessed when blank
  230 + expect(app.reload.notice_fingerprinter).to be_a(NoticeFingerprinter)
  231 + end
  232 +
  233 + it 'brand new app has a notice_fingerprinter' do
  234 + app = Fabricate(:app, name: 'Errbit')
  235 + expect(app.notice_fingerprinter).to be_a(NoticeFingerprinter)
  236 + end
  237 + end
223 238 end
... ...