Story#119627029 - save checksum of legal doc to DB

This commit is contained in:
Vladimir Krylov 2016-08-01 16:01:52 +03:00
parent 2f1b255fc1
commit dd3f19c5e1

View file

@ -33,6 +33,7 @@ class LegalDocument < ActiveRecord::Base
def save_to_filesystem def save_to_filesystem
binary = Base64.decode64(body) binary = Base64.decode64(body)
digest = Digest::SHA1.new.update(binary).to_s
loop do loop do
rand = SecureRandom.random_number.to_s.last(4) rand = SecureRandom.random_number.to_s.last(4)
@ -45,7 +46,7 @@ class LegalDocument < ActiveRecord::Base
File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test? File.open(path, 'wb') { |f| f.write(binary) } unless Rails.env.test?
self.path = path self.path = path
self.checksum = digest
end end
def calc_checksum def calc_checksum