Skip to content

Commit

Permalink
Set tags only if passed any.
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Fik <mariusz@fidano.pl>
  • Loading branch information
Fisiu committed Apr 19, 2018
1 parent 5de1146 commit 52d278a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Modules/Tag/Tests/Integration/TaggableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ public function it_gets_pages_with_non_latin_tags()
$this->assertCount(1, Page::whereTag(['한글-태그'])->get());
}

/** @test */
public function it_creates_page_without_tags()
{
$this->createPage(['original tag']);

$page = $this->page->find(1);
$page->setTags(null);

$this->assertEmpty(Page::first()->tags->count());
}

private function createPage(array $tags = [])
{
return $this->page->create([
Expand Down
4 changes: 4 additions & 0 deletions Modules/Tag/Traits/TaggableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public static function allTags()
*/
public function setTags($tags, $type = 'slug')
{
if (empty($tags)) {
$tags = [];
}

// Get the current entity tags
$entityTags = $this->tags->pluck($type)->all();

Expand Down

0 comments on commit 52d278a

Please sign in to comment.