Browse Source

Fix RouteBuilder::resources() with dasherize.

Refs #7726
Mark Story 10 years ago
parent
commit
a3066fafef
2 changed files with 21 additions and 1 deletions
  1. 1 1
      src/Routing/RouteBuilder.php
  2. 20 0
      tests/TestCase/Routing/RouteBuilderTest.php

+ 1 - 1
src/Routing/RouteBuilder.php

@@ -344,7 +344,7 @@ class RouteBuilder
         }
 
         if (is_callable($callback)) {
-            $idName = Inflector::underscore(Inflector::singularize($name)) . '_id';
+            $idName = Inflector::singularize(str_replace('-', '_', $urlName)) . '_id';
             $path = '/' . $urlName . '/:' . $idName;
             $this->scope($path, [], $callback);
         }

+ 20 - 0
tests/TestCase/Routing/RouteBuilderTest.php

@@ -388,6 +388,26 @@ class RouteBuilderTest extends TestCase
     }
 
     /**
+     * Test connecting nested resources with the inflection option
+     *
+     * @return void
+     */
+    public function testResourcesNestedInflection()
+    {
+        $routes = new RouteBuilder($this->collection, '/api');
+        $routes->resources('NetworkObjects', ['inflect' => 'dasherize'], function($routes) {
+            $routes->resources('Attributes');
+        });
+
+        $all = $this->collection->routes();
+        $this->assertCount(10, $all);
+
+        $this->assertEquals('/api/network-objects', $all[0]->template);
+        $this->assertEquals('/api/network-objects/:id', $all[2]->template);
+        $this->assertEquals('/api/network-objects/:network_object_id/attributes', $all[5]->template);
+    }
+
+    /**
      * Test connecting resources with additional mappings
      *
      * @return void