summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/rest.php2
-rw-r--r--core/helpers/rest.php2
-rw-r--r--core/tests/REST_Controller_Test.php20
3 files changed, 22 insertions, 2 deletions
diff --git a/core/controllers/rest.php b/core/controllers/rest.php
index f0fb5e5c..c7429f5d 100644
--- a/core/controllers/rest.php
+++ b/core/controllers/rest.php
@@ -84,7 +84,7 @@ abstract class REST_Controller extends Controller {
// @todo this needs security checks
$id = $function;
$resource = ORM::factory($this->resource_type, $id);
- if (!$resource->loaded && !$request_method == "post") {
+ if (!$resource->loaded && $request_method != "post") {
return Kohana::show_404();
}
diff --git a/core/helpers/rest.php b/core/helpers/rest.php
index 1e14b0e2..b1f777cf 100644
--- a/core/helpers/rest.php
+++ b/core/helpers/rest.php
@@ -84,7 +84,7 @@ class REST_Core {
/**
* Set HTTP response code.
- * @param string Use one of status code constants defined in this class.
+ * @param string Use one of the status code constants defined in this class.
*/
public static function http_status($status_code) {
header("HTTP/1.1 " . $status_code);
diff --git a/core/tests/REST_Controller_Test.php b/core/tests/REST_Controller_Test.php
index 72c86bda..20a5269e 100644
--- a/core/tests/REST_Controller_Test.php
+++ b/core/tests/REST_Controller_Test.php
@@ -54,6 +54,26 @@ class REST_Controller_Test extends Unit_Test_Case {
$this->assert_equal("Mock_Model", get_class($this->mock_controller->resource));
}
+ public function dispatch_404_test() {
+ /* The dispatcher should throw a 404 if the resource isn't loaded and the method isn't POST. */
+ $methods = array(
+ array("GET", ""),
+ array("POST", "PUT"),
+ array("POST", "DELETE"));
+
+ foreach ($methods as $method) {
+ $_SERVER["REQUEST_METHOD"] = $method[0];
+ $_POST["_method"] = $method[1];
+ $exception_caught = false;
+ try {
+ $this->mock_not_loaded_controller->__call(rand(), "");
+ } catch (Kohana_404_Exception $e) {
+ $exception_caught = true;
+ }
+ $this->assert_true($exception_caught, "$method[0], $method[1]");
+ }
+ }
+
public function dispatch_create_test() {
$_SERVER["REQUEST_METHOD"] = "POST";
$_POST["_method"] = "";