Skip to content

Commit

Permalink
Merge pull request #518 from Fisiu/allow_empty_tags
Browse files Browse the repository at this point in the history
Set tags only if passed any.
  • Loading branch information
nWidart authored Apr 20, 2018
2 parents 22ccee9 + 52d278a commit 4c30c45
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 4c30c45

Please sign in to comment.