From bca10e164b797e82d2d6ca114d7eae06090968c1 Mon Sep 17 00:00:00 2001 From: Johan Brook Date: Mon, 2 Nov 2015 08:20:53 +0100 Subject: [PATCH] Persist options object on route groups --- client/group.js | 1 + package.js | 1 + server/group.js | 2 +- test/client/group.spec.js | 24 ++++++++++++++++++++++++ test/common/group.spec.js | 16 ++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/common/group.spec.js diff --git a/client/group.js b/client/group.js index 78a7bf8..b93296b 100644 --- a/client/group.js +++ b/client/group.js @@ -9,6 +9,7 @@ Group = function(router, options, parent) { this._router = router; this.prefix = options.prefix || ''; this.name = options.name; + this.options = options; this._triggersEnter = options.triggersEnter || []; this._triggersExit = options.triggersExit || []; diff --git a/package.js b/package.js index 7c914f6..e9b9a3a 100644 --- a/package.js +++ b/package.js @@ -48,6 +48,7 @@ Package.onTest(function(api) { api.addFiles('test/common/router.path.spec.js', ['client', 'server']); api.addFiles('test/common/router.addons.spec.js', ['client', 'server']); api.addFiles('test/common/route.spec.js', ['client', 'server']); + api.addFiles('test/common/group.spec.js', ['client', 'server']); }); function configure(api) { diff --git a/server/group.js b/server/group.js index 52b6afd..89a6d02 100644 --- a/server/group.js +++ b/server/group.js @@ -1,7 +1,7 @@ Group = function(router, options) { options = options || {}; this.prefix = options.prefix || ''; - + this.options = options; this._router = router; }; diff --git a/test/client/group.spec.js b/test/client/group.spec.js index 73e870b..06e793b 100644 --- a/test/client/group.spec.js +++ b/test/client/group.spec.js @@ -87,3 +87,27 @@ Tinytest.addAsync('Client - Group - set and retrieve group name', function (test next(); }, 100); }); + +Tinytest.add('Client - Group - expose group options on a route', function (test) { + var pathDef = "/" + Random.id(); + var name = Random.id(); + var groupName = Random.id(); + var data = {aa: 10}; + var layout = 'blah'; + + var group = FlowRouter.group({ + name: groupName, + prefix: '/admin', + layout: layout, + someData: data + }); + + group.route(pathDef, { + name: name + }); + + var route = FlowRouter._routesMap[name]; + + test.equal(route.group.options.someData, data); + test.equal(route.group.options.layout, layout); +}); diff --git a/test/common/group.spec.js b/test/common/group.spec.js new file mode 100644 index 0000000..e6e799c --- /dev/null +++ b/test/common/group.spec.js @@ -0,0 +1,16 @@ +Tinytest.add('Common - Group - expose group options', function (test) { + var pathDef = "/" + Random.id(); + var name = Random.id(); + var data = {aa: 10}; + var layout = 'blah'; + + var group = FlowRouter.group({ + name: name, + prefix: '/admin', + layout: layout, + someData: data + }); + + test.equal(group.options.someData, data); + test.equal(group.options.layout, layout); +});