Rename validate to check
Validate is an ActiveModel method, overriding it could have unintended side-effects so I opted to rename it
This commit is contained in:
@@ -4,8 +4,8 @@ class ImportAccountDataJob < ApplicationJob
|
||||
queue_as :backend
|
||||
|
||||
def perform(import)
|
||||
step :validate do
|
||||
import.validate \
|
||||
step :check do
|
||||
import.check \
|
||||
start: step.cursor,
|
||||
callback: proc do |record_set:, file:|
|
||||
step.set!([ record_set.model.name, file ])
|
||||
|
||||
@@ -36,7 +36,7 @@ class Account::DataTransfer::AccountRecordSet < Account::DataTransfer::RecordSet
|
||||
account.join_code.update(code: join_code_data.fetch("code"))
|
||||
end
|
||||
|
||||
def validate_record(file_path)
|
||||
def check_record(file_path)
|
||||
data = load(file_path)
|
||||
|
||||
unless (ACCOUNT_ATTRIBUTES - data.keys).empty?
|
||||
|
||||
@@ -38,7 +38,7 @@ class Account::DataTransfer::ActionTextRichTextRecordSet < Account::DataTransfer
|
||||
ActionText::RichText.insert_all!(batch_data)
|
||||
end
|
||||
|
||||
def validate_record(file_path)
|
||||
def check_record(file_path)
|
||||
data = load(file_path)
|
||||
expected_id = File.basename(file_path, ".json")
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class Account::DataTransfer::BlobFileRecordSet < Account::DataTransfer::RecordSe
|
||||
end
|
||||
end
|
||||
|
||||
def validate_record(file_path)
|
||||
def check_record(file_path)
|
||||
key = File.basename(file_path)
|
||||
|
||||
unless zip.exists?("data/active_storage_blobs/#{key}.json") || ActiveStorage::Blob.exists?(key: key, account: account)
|
||||
|
||||
@@ -33,13 +33,13 @@ class Account::DataTransfer::RecordSet
|
||||
end
|
||||
end
|
||||
|
||||
def validate(from:, start: nil, callback: nil)
|
||||
def check(from:, start: nil, callback: nil)
|
||||
with_zip(from) do
|
||||
file_list = files
|
||||
file_list = skip_to(file_list, start) if start
|
||||
|
||||
file_list.each do |file_path|
|
||||
validate_record(file_path)
|
||||
check_record(file_path)
|
||||
callback&.call(record_set: self, file: file_path)
|
||||
end
|
||||
end
|
||||
@@ -77,7 +77,7 @@ class Account::DataTransfer::RecordSet
|
||||
model.insert_all!(batch_data)
|
||||
end
|
||||
|
||||
def validate_record(file_path)
|
||||
def check_record(file_path)
|
||||
data = load(file_path)
|
||||
expected_id = File.basename(file_path, ".json")
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class Account::DataTransfer::UserRecordSet < Account::DataTransfer::RecordSet
|
||||
User.insert_all!(batch_data)
|
||||
end
|
||||
|
||||
def validate_record(file_path)
|
||||
def check_record(file_path)
|
||||
data = load(file_path)
|
||||
expected_id = File.basename(file_path, ".json")
|
||||
|
||||
|
||||
@@ -28,12 +28,12 @@ class Account::Import < ApplicationRecord
|
||||
raise e
|
||||
end
|
||||
|
||||
def validate(start: nil, callback: nil)
|
||||
def check(start: nil, callback: nil)
|
||||
processing!
|
||||
|
||||
ZipFile.read_from(file.blob) do |zip|
|
||||
Account::DataTransfer::Manifest.new(account).each_record_set(start: start) do |record_set, last_id|
|
||||
record_set.validate(from: zip, start: last_id, callback: callback)
|
||||
record_set.check(from: zip, start: last_id, callback: callback)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,9 +24,12 @@ class Account::ImportTest < ActiveSupport::TestCase
|
||||
import.file.attach(io: File.open(export_tempfile.path), filename: "export.zip", content_type: "application/zip")
|
||||
end
|
||||
|
||||
import.process
|
||||
import.check
|
||||
assert_not import.failed?
|
||||
|
||||
import.process
|
||||
assert import.completed?
|
||||
|
||||
assert_equal source_account_digest, account_digest(target_account)
|
||||
ensure
|
||||
export_tempfile&.close
|
||||
|
||||
Reference in New Issue
Block a user