Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

add getRouteKey method #17

Merged
merged 5 commits into from
Nov 30, 2017
Merged

add getRouteKey method #17

merged 5 commits into from
Nov 30, 2017

Conversation

faustbrian
Copy link
Contributor

@faustbrian faustbrian commented Nov 30, 2017

Currently passing models to the route method to generate a url will result in a malformed url as the binary uuid will be used.

// call
route('account.announcements.show', App\Announcement::first())

// now
http://app.dev/account/announcements/%11%E7%D5%8A%C41%96%D4%97%8D%FE%00h%82%C2%01

// new
http://app.dev/account/announcements/c43196d4-d58a-11e7-978d-fe006882c201

@brendt
Copy link
Contributor

brendt commented Nov 30, 2017

Could you add a test for this?

@@ -90,4 +90,9 @@ public function newQueryForRestoration($id)
{
return $this->newQueryWithoutScopes()->whereKey(base64_decode($id));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace: https://styleci.io/analyses/zYabxo

app('router')->get('uuid-test/{model}')->name('uuid-test');

$expected = "http://localhost/uuid-test/$uuid";
$actual = route('uuid-test', $model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra line break here, see the style of other tests.


app('router')->get('uuid-test/{model}')->name('uuid-test');

$expected = "http://localhost/uuid-test/$uuid";
Copy link
Contributor

@brendt brendt Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is hard-coding localhost the best idea? Maybe it would be better to assert like so?

$this->assertContains("/uuid-test/{$uuid}", $actual);

public function it_generates_valid_routes()
{
$uuid = Uuid::uuid1();
$model = $this->createModel($uuid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some tests, these two lines are put together because there's a whole list of them. But in this case, I'd add a line break here.

@brendt
Copy link
Contributor

brendt commented Nov 30, 2017

Thanks! @freekmurze care to take a final look?

@freekmurze freekmurze merged commit 6b711ca into spatie:master Nov 30, 2017
@freekmurze
Copy link
Member

Very nice! Thanks!

@faustbrian faustbrian deleted the patch-4 branch November 30, 2017 13:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants