diff --git a/app/models/app.rb b/app/models/app.rb index e7be608..6f9640e 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -31,6 +31,7 @@ class App before_validation :generate_api_key, on: :create before_save :normalize_github_repo before_create :build_notice_fingerprinter + after_find :build_notice_fingerprinter after_update :store_cached_attributes_on_problems validates :name, :api_key, presence: true, uniqueness: { allow_blank: true } @@ -54,6 +55,9 @@ class App } def build_notice_fingerprinter + # no need to build a notice_fingerprinter if we already have one + return if notice_fingerprinter.present? + attrs = SiteConfig.document.notice_fingerprinter_attributes self.notice_fingerprinter = attrs end diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index c48a9e0..c8407af 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -220,4 +220,19 @@ describe App, type: 'model' do end.to raise_error(Mongoid::Errors::DocumentNotFound) end end + + describe '#notice_fingerprinter' do + it 'app acquires a notice_fingerprinter when it doesn\'t have one' do + app = Fabricate(:app, name: 'Errbit') + app.notice_fingerprinter.delete + + # has a notice_fingerprinter because it's been accessed when blank + expect(app.reload.notice_fingerprinter).to be_a(NoticeFingerprinter) + end + + it 'brand new app has a notice_fingerprinter' do + app = Fabricate(:app, name: 'Errbit') + expect(app.notice_fingerprinter).to be_a(NoticeFingerprinter) + end + end end -- libgit2 0.21.2