Skip to content

Commit

Permalink
Merge pull request #558 from pawawat/fix-missing-retrieved-event-in-p…
Browse files Browse the repository at this point in the history
…ost-model

fix missing retrieved event in Post model
  • Loading branch information
jgrossi committed Sep 30, 2021
2 parents cf968e8 + 15f525d commit 55ad395
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Model/Post.php
Expand Up @@ -128,6 +128,8 @@ public function newFromBuilder($attributes = [], $connection = null)
$connection ?: $this->getConnectionName()
);

$model->fireModelEvent('retrieved', false);

return $model;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Model/PostTypeTest.php
Expand Up @@ -3,6 +3,7 @@
namespace Corcel\Tests\Unit\Model;

use Corcel\Model\Post;
use Illuminate\Support\Facades\Event;

/**
* Class PostTypeTest
Expand Down Expand Up @@ -55,6 +56,18 @@ public function test_it_has_custom_instance_using_custom_class_builder()
$this->assertEquals('video', $video->post_type);
}

public function test_it_has_fire_retrieved_event_using_custom_class_builder()
{
Event::fake();
Post::registerPostType('video', Video::class);
factory(Post::class)->create(['post_type' => 'video']);

Video::first();

Event::assertDispatched('eloquent.retrieved: ' . Video::class, 1);
Event::assertNotDispatched('eloquent.retrieved: ' . Post::class);
}

public function test_it_is_configurable_by_the_config_file()
{
factory(Post::class)->create(['post_type' => 'fake_post']);
Expand Down

0 comments on commit 55ad395

Please sign in to comment.