Skip to content

Commit

Permalink
Merge 0d09781 into a9d4a47
Browse files Browse the repository at this point in the history
  • Loading branch information
SaravShah committed Jul 30, 2018
2 parents a9d4a47 + 0d09781 commit e890080
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 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: proc { |cm| cm.saved_change_to_status? && cm.validity_unknown? }

belongs_to :preserved_object, inverse_of: :complete_moabs
belongs_to :moab_storage_root, inverse_of: :complete_moabs
Expand Down
14 changes: 14 additions & 0 deletions spec/models/complete_moab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,18 @@
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
expect(cm).to receive(:validate_checksums!)
cm.validity_unknown!
end
end
end

0 comments on commit e890080

Please sign in to comment.