Skip to content

Support model reference in validate statement to validate all columns #172

@axit-joost

Description

@axit-joost

As mentioned in #171

Given the following contents of draft.yaml:

models:
  Certificate:
    name: string
    reference: string
    document: string
    expiry_date: date
    remarks: nullable text

controllers:
  Certificate:
    resource: api

Where we use a resource: api to generate an REST API Controller.

Running blueprint:build will yield:

- database/migrations/2020_05_02_092122_create_certificates_table.php
- app/Certificate.php
- database/factories/CertificateFactory.php
- app/Http/Controllers/CertificateController.php
- app/Http/Requests/CertificateStoreRequest.php
- app/Http/Requests/CertificateUpdateRequest.php
- app/Http/Resources/CertificateCollection.php
- app/Http/Resources/Certificate.php
- tests/Feature/Http/Controllers/CertificateControllerTest.php

If we inspect the StoreRequest and UpdateRequest, and particularly the rules() within, we will find the following bogus rule:

    public function rules()
    {
        return [
            'certificate' => 'required',
        ];
    }

The expectation here is that the rules should match/correspond with the model's definition.

The generated tests also fail because of this:

❯ phpunit                                                                                                                                                                                                                         28%
PHPUnit 8.5.4 by Sebastian Bergmann and contributors.

..R.FR.R.                                                           9 / 9 (100%)

Time: 326 ms, Memory: 30.00 MB

There was 1 failure:

1) Tests\Feature\Http\Controllers\CertificateControllerTest::store_saves
Failed asserting that actual size 0 matches expected size 1.

/Users/joostjacobs/Code/blueprint/tests/Feature/Http/Controllers/CertificateControllerTest.php:55

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions