Skip to content

Commit

Permalink
Merge 76a7c11 into 07c30ac
Browse files Browse the repository at this point in the history
  • Loading branch information
SaravShah committed Jul 27, 2018
2 parents 07c30ac + 76a7c11 commit 5ab4868
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/complete_moab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CompleteMoab < ApplicationRecord

after_create :create_zipped_moab_versions!
after_update :create_zipped_moab_versions!, if: :saved_change_to_version? # an ActiveRecord dynamic method
after_save :validate_checksums!, if: :status_change?

belongs_to :preserved_object, inverse_of: :complete_moabs
belongs_to :moab_storage_root, inverse_of: :complete_moabs
Expand Down Expand Up @@ -79,6 +80,10 @@ def validate_checksums!
ChecksumValidationJob.perform_later(self)
end

def status_change?
saved_change_to_status? && validity_unknown?
end

def druid_version_zip
@druid_version_zip ||= DruidVersionZip.new(preserved_object.druid, version)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/models/complete_moab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,19 @@
cm.save!
end
end

describe '.after_save callback' do
it 'does not call validate_checksums when status is unchanged' do
cm.size = 234
expect(cm).not_to receive(:validate_checksums!)
cm.save!
end

it 'does calls validate_checksums when status is validity_unknown' do
cm.ok! # object starts out with validity_unknown status
cm.status = 'validity_unknown'
expect(cm).to receive(:validate_checksums!)
cm.save!
end
end
end

0 comments on commit 5ab4868

Please sign in to comment.