tests a little broken, added some nullchecks

This commit is contained in:
spencerrlongg 2024-07-30 21:44:22 -05:00
parent 8684a3efc3
commit 9b80843c77
2 changed files with 3 additions and 1 deletions

View file

@ -24,7 +24,7 @@ trait MayContainCustomFields
}); });
// if there are custom fields, find the one's that don't exist on the model's fieldset and add an error to the validator's error bag // if there are custom fields, find the one's that don't exist on the model's fieldset and add an error to the validator's error bag
if (count($request_fields) > 0) { if (count($request_fields) > 0) {
$request_fields->diff($asset_model->fieldset->fields->pluck('db_column')) $request_fields->diff($asset_model?->fieldset?->fields?->pluck('db_column'))
->each(function ($request_field_name) use ($request_fields, $validator) { ->each(function ($request_field_name) use ($request_fields, $validator) {
if (CustomField::where('db_column', $request_field_name)->exists()) { if (CustomField::where('db_column', $request_field_name)->exists()) {
$validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found_on_model')); $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found_on_model'));

View file

@ -269,6 +269,8 @@ class UpdateAssetTest extends TestCase
{ {
$this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL');
// hmm, for some reason this customfield isn't attached to a fieldset
// need to check out these factory methods...
$field = CustomField::factory()->testEncrypted()->create(); $field = CustomField::factory()->testEncrypted()->create();
$asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create();
$superuser = User::factory()->superuser()->create(); $superuser = User::factory()->superuser()->create();