Permalink
Browse files

Fixing issues where ModelBehavior::detach() would not detach behavior…

…s when a plugin.name was provided. This change makes detach() work like attach(). Tests added. Fixes #711
  • Loading branch information...
1 parent 0648c66 commit 79839c07d2e9689dbcaaf12a979690c3f1824361 @markstory markstory committed May 12, 2010
Showing with 23 additions and 0 deletions.
  1. +1 −0 cake/libs/model/model_behavior.php
  2. +22 −0 cake/tests/cases/libs/model/model_behavior.test.php
View
1 cake/libs/model/model_behavior.php
@@ -372,6 +372,7 @@ function attach($behavior, $config = array()) {
* @access public
*/
function detach($name) {
+ list($plugin, $name) = pluginSplit($name);
if (isset($this->{$name})) {
$this->{$name}->cleanup(ClassRegistry::getObject($this->modelName));
unset($this->{$name});
View
22 cake/tests/cases/libs/model/model_behavior.test.php
@@ -505,6 +505,28 @@ function testBehaviorBinding() {
}
/**
+ * test that attach()/detach() works with plugin.banana
+ *
+ * @return void
+ */
+ function testDetachWithPluginNames() {
+ $Apple = new Apple();
+ $Apple->Behaviors->attach('Plugin.Test');
+ $this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
+ $this->assertEqual($Apple->Behaviors->attached(), array('Test'));
+
+ $Apple->Behaviors->detach('Plugin.Test');
+ $this->assertEqual($Apple->Behaviors->attached(), array());
+
+ $Apple->Behaviors->attach('Plugin.Test');
+ $this->assertTrue(isset($Apple->Behaviors->Test), 'Missing behavior');
+ $this->assertEqual($Apple->Behaviors->attached(), array('Test'));
+
+ $Apple->Behaviors->detach('Test');
+ $this->assertEqual($Apple->Behaviors->attached(), array());
+ }
+
+/**
* test that attaching a non existant Behavior triggers a cake error.
*
* @return void

0 comments on commit 79839c0

Please sign in to comment.