From 560e659bcc2f7957c743e11de5ebe157d723b04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20R=C3=B8en?= Date: Sat, 7 Mar 2015 22:28:57 +0100 Subject: [PATCH 1/2] Add tests for titleToken and title contexts --- tests/acceptance/document-title-test.js | 3 ++- tests/dummy/app/router.js | 2 +- tests/dummy/app/routes/friendship-status.js | 6 +++--- tests/dummy/app/routes/friendship-status/index.js | 9 +++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 tests/dummy/app/routes/friendship-status/index.js diff --git a/tests/acceptance/document-title-test.js b/tests/acceptance/document-title-test.js index 9a703ce..2b92548 100644 --- a/tests/acceptance/document-title-test.js +++ b/tests/acceptance/document-title-test.js @@ -51,6 +51,7 @@ test('dynamic title based on route attributes', function(assert) { visit('/friendship-status'); andThen(function() { - assert.equal(router._title, 'We are friends - My Blog'); + assert.equal(router._title, 'We are best friends', + 'the context is correct for `title` and `titleToken`'); }); }); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 41b5653..a14d63f 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -9,7 +9,7 @@ Router.map(function() { this.resource('posts', function() {}); this.route('about'); this.route('team'); - this.route('friendship-status'); + this.resource('friendship-status', function() {}); }); export default Router; diff --git a/tests/dummy/app/routes/friendship-status.js b/tests/dummy/app/routes/friendship-status.js index 7e345b5..fd2ff42 100644 --- a/tests/dummy/app/routes/friendship-status.js +++ b/tests/dummy/app/routes/friendship-status.js @@ -1,9 +1,9 @@ import Ember from 'ember'; export default Ember.Route.extend({ - status: 'friends', + degree: 'best', - titleToken: function(model) { - return 'We are ' + this.get('status'); + title: function(tokens) { + return 'We are ' + this.get('degree') + ' ' + tokens[0]; } }); diff --git a/tests/dummy/app/routes/friendship-status/index.js b/tests/dummy/app/routes/friendship-status/index.js new file mode 100644 index 0000000..c2a4a63 --- /dev/null +++ b/tests/dummy/app/routes/friendship-status/index.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + status: 'friends', + + titleToken: function(model) { + return this.get('status'); + } +}); From 5b6c6f358495a566b8b62953bba314365780aa3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20R=C3=B8en?= Date: Sat, 7 Mar 2015 22:29:15 +0100 Subject: [PATCH 2/2] Fix context for the the title-function --- vendor/document-title/document-title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/document-title/document-title.js b/vendor/document-title/document-title.js index a649b43..b94143b 100644 --- a/vendor/document-title/document-title.js +++ b/vendor/document-title/document-title.js @@ -36,7 +36,7 @@ Ember.Route.reopen({ if (title) { var finalTitle; if (typeof title === 'function') { - finalTitle = title(tokens); + finalTitle = title.call(this, tokens); } else { // Tokens aren't even considered... a string // title just sledgehammer overwrites any children tokens.