Skip to content

Commit

Permalink
Merge pull request #160 from rodrigopedra/patch-1
Browse files Browse the repository at this point in the history
BUGFIX Use current ziggy instance in current method
  • Loading branch information
DanielCoulbourne authored Jun 20, 2018
2 parents 75b47ee + b695e7e commit 32e97f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Router extends String {
let routeNames = Object.keys(this.ziggy.namedRoutes);

let currentRoute = routeNames.filter(name => {
return new Router(name).matchUrl();
return new Router(name, undefined, undefined, this.ziggy).matchUrl();
})[0];

return name ? (name == currentRoute) : currentRoute;
Expand Down
43 changes: 39 additions & 4 deletions tests/js/test.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ let moxios = require('moxios');
import route from '../../src/js/route.js';

global.Ziggy = {
namedRoutes: {
namedRoutes: {
"translateTeam.user.show": {
"uri": "{locale}/users/{id}",
"methods": ["GET", "HEAD"],
"domain": "{team}.myapp.dev"
"domain": "{team}.myapp.dev"
},
"translateEvents.venues.show": {
"uri": "{locale}/events/{event}/venues/{venue}",
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('route()', function() {
);
});


it('Should return URL without domain when passing false into absolute param.', function() {
assert.equal(
"/posts",
Expand Down Expand Up @@ -639,6 +639,41 @@ describe('route()', function() {
assert.equal(
'http://notYourAverage.dev/tightenDev/1/packages',
route('tightenDev.packages.index', { dev: 1 }, true, customZiggy).url()
)
);
});

it('Should allow route().current() when there is no global Ziggy object', function() {
const orgZiggy = global.Ziggy;

global.Ziggy = undefined;

global.window = {
location: {
hostname: "myapp.dev",
pathname: "/events/",
protocol: ""
}
};

const customZiggy = {
namedRoutes: {
"events.index": {
"uri": "events",
"methods": ["GET", "HEAD"],
"domain": null
},
},
baseUrl: 'http://myapp.dev/',
baseProtocol: 'http',
baseDomain: 'myapp.dev',
basePort: false,
};

assert.equal(
'events.index',
route(undefined, undefined, undefined, customZiggy).current()
);

global.Ziggy = orgZiggy;
});
});

0 comments on commit 32e97f8

Please sign in to comment.