ソースを参照

correct setter method

euromark 12 年 前
コミット
f966f36ab9

+ 2 - 2
Model/Behavior/NamedScopeBehavior.php

@@ -102,8 +102,8 @@ class NamedScopeBehavior extends ModelBehavior {
 		if ($name === null) {
 			return $this->settings[$Model->alias]['scope'];
 		}
-		if (in_array($name, $this->settings[$Model->alias]['scope'])) {
-			continue;
+		if ($value === null) {
+			return isset($this->settings[$Model->alias]['scope'][$name]) ? $this->settings[$Model->alias]['scope'][$name] : null;
 		}
 		$this->settings[$Model->alias]['scope'][$name] = $value;
 	}

+ 21 - 0
Test/Case/Model/Behavior/NamedScopeBehaviorTest.php

@@ -29,6 +29,27 @@ class NamedScopeBehaviorTest extends MyCakeTestCase {
 	}
 
 	/**
+	 * NamedScopeBehaviorTest::testScope()
+	 *
+	 * @return void
+	 */
+	public function testScope() {
+		$result = $this->Comment->scope('active');
+		$this->assertNull($result);
+
+		$this->Comment->scope('active', array('published' => 'Y'));
+		$result = $this->Comment->scope('active');
+		$this->assertEquals(array('published' => 'Y'), $result);
+
+		$this->Comment->scope('active', array('published' => 'Y', 'active' => 1));
+		$result = $this->Comment->scope('active');
+		$this->assertEquals(array('published' => 'Y', 'active' => 1), $result);
+
+		$result = $this->Comment->scope();
+		$this->assertEquals(array('active' => array('published' => 'Y', 'active' => 1)), $result);
+	}
+
+	/**
 	 * NamedScopeBehaviorTest::testBasic()
 	 *
 	 * @return void