Repository: miragejs/miragejs (js)

Issue:
Shorthand route fails if it has a trailing slash
In our app we had a shorthand route set up as `this.get('/notifications/');` which broke our tests when upgrading from ember-cli-mirage 1.1.3 to 1.1.4 with the following error:

`"Mirage: The route handler for http://localhost:4200/ghost/api/v3/admin/notifications/ is trying to access the  model, but that model doesn't exist."`

![](https://cdn.discordapp.com/attachments/486704963167191042/638395725964902401/Screenshot_2019-10-28_at_15.15.51.png)

Digging in, it appears that `getModelClassFromPath()` is failing when the path has a trailing slash:

<img width="332" alt="Screenshot 2019-10-28 at 15 35 27" src="https://user-images.githubusercontent.com/415/67693342-7208c280-f999-11e9-90de-ceb446dfb35f.png">


Pull request description:
fix: fix trailing slash regression during url model extraction
fixes #180

Patch:
diff --git a/lib/route-handlers/base.js b/lib/route-handlers/base.js
index 5771191..ed22479 100644
--- a/lib/route-handlers/base.js
+++ b/lib/route-handlers/base.js
@@ -19,7 +19,7 @@ export default class BaseRouteHandler {
 
       for (let i = path.length - 1; i >= 0; i--) {
         const segment = path[i];
-        if (segment[0] !== ":") {
+        if (segment.length && segment[0] !== ":") {
           lastPath = segment;
           break;
         }


Test patch:
diff --git a/__tests__/internal/unit/route-handlers/shorthands/base-test.js b/__tests__/internal/unit/route-handlers/shorthands/base-test.js
index e68c672..a999dea 100644
--- a/__tests__/internal/unit/route-handlers/shorthands/base-test.js
+++ b/__tests__/internal/unit/route-handlers/shorthands/base-test.js
@@ -31,11 +31,15 @@ describe("Unit | Route handlers | Shorthands | BaseShorthandRouteHandler", funct
   test("getModelClassFromPath works with various named route path variable", () => {
     let urlWithSlash = "/api/fancy-users";
     let urlWithIdAndSlash = "/api/fancy-users/:id";
+    let urlWithTrailingSlash = "/api/fancy-users/";
 
     expect(handler.getModelClassFromPath(urlWithSlash)).toEqual("fancy-user");
     expect(handler.getModelClassFromPath(urlWithIdAndSlash, true)).toEqual(
       "fancy-user"
     );
+    expect(handler.getModelClassFromPath(urlWithTrailingSlash)).toEqual(
+      "fancy-user"
+    );
 
     urlWithSlash = "/api/exquisite-users";
     urlWithIdAndSlash = "/api/exquisite-users/:objectId";