Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Allowing to add existing tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
okinaka committed Apr 16, 2014
1 parent 2bba473 commit dd74851
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Model/Behavior/TaggableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ public function deleteTagged(Model $model) {
*/
public function afterFind(Model $model, $results, $primary = false) {
extract($this->settings[$model->alias]);

if ($model->alias === $tagAlias) {
return $results;
}

foreach ($results as $key => $row) {
$row[$model->alias][$field] = '';
if (isset($row[$tagAlias]) && !empty($row[$tagAlias])) {
Expand Down
7 changes: 7 additions & 0 deletions Test/Case/Controller/TagsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ public function testAdminAdd() {
'tags' => 'tag1, tag2, tag3'));
$this->Tags->admin_add();
$this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));

// adding same tags again.
$this->Tags->data = array(
'Tag' => array(
'tags' => 'tag1, tag2, tag3'));
$this->Tags->admin_add();
$this->assertEquals($this->Tags->redirectUrl, array('action' => 'index'));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Test/Case/Model/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ public function testAdd() {
$this->assertTrue(in_array('tag1', $result));
$this->assertTrue(in_array('tag2', $result));
$this->assertTrue(in_array('tag3', $result));

// adding same tags again.
$result = $this->Tag->add(
array('Tag' => array(
'tags' => 'tag1, tag2, tag3')));
$this->assertTrue($result);
}

/**
Expand Down

0 comments on commit dd74851

Please sign in to comment.