diff --git a/bower.json b/bower.json index 690233ef8fc9..3f5e544de1b0 100644 --- a/bower.json +++ b/bower.json @@ -27,7 +27,7 @@ "google-caja": "5669.0.0" }, "devDependencies": { - "ember-mocha": "~0.1.4", + "ember-mocha": "~0.3.0", "ember-cli-test-loader": "dgeb/ember-cli-test-loader#test-agnostic", "ember-cli-shims": "stefanpenner/ember-cli-shims#~0.0.3" } diff --git a/core/client/components/gh-url-preview.js b/core/client/components/gh-url-preview.js index 05754803b6b4..3e71002cffb9 100644 --- a/core/client/components/gh-url-preview.js +++ b/core/client/components/gh-url-preview.js @@ -6,22 +6,21 @@ var urlPreview = Ember.Component.extend({ classNames: 'ghost-url-preview', prefix: null, slug: null, - theUrl: null, - generateUrl: function () { + url: Ember.computed('slug', function () { // Get the blog URL and strip the scheme var blogUrl = this.get('config').blogUrl, noSchemeBlogUrl = blogUrl.substr(blogUrl.indexOf('://') + 3), // Remove `http[s]://` // Get the prefix and slug values prefix = this.get('prefix') ? this.get('prefix') + '/' : '', - slug = this.get('slug') ? this.get('slug') : '', + slug = this.get('slug') ? this.get('slug') + '/' : '', // Join parts of the URL together with slashes - theUrl = noSchemeBlogUrl + '/' + prefix + (slug ? slug + '/' : ''); + theUrl = noSchemeBlogUrl + '/' + prefix + slug; - this.set('the-url', theUrl); - }.on('didInsertElement').observes('slug') + return theUrl; + }) }); export default urlPreview; diff --git a/core/client/templates/components/gh-url-preview.hbs b/core/client/templates/components/gh-url-preview.hbs index f31f6e43f8d6..54c93ee14bf2 100644 --- a/core/client/templates/components/gh-url-preview.hbs +++ b/core/client/templates/components/gh-url-preview.hbs @@ -1 +1 @@ -{{the-url}} \ No newline at end of file +{{url}} diff --git a/core/test/client/.jshintrc b/core/test/client/.jshintrc index 06a23d09290f..e6ac4b8888c6 100644 --- a/core/test/client/.jshintrc +++ b/core/test/client/.jshintrc @@ -1,7 +1,6 @@ { "node": false, "browser": true, - "nomen": false, "bitwise": true, "curly": true, "eqeqeq": true, @@ -16,11 +15,8 @@ "regexp": true, "undef": true, "unused": true, - "trailing": true, "indent": 4, "esnext": true, - "onevar": true, - "white": true, "quotmark": "single", "globals": { "Ember": true, diff --git a/core/test/client/unit/components/gh-url-preview_test.js b/core/test/client/unit/components/gh-url-preview_test.js new file mode 100644 index 000000000000..09b4af7eb5e6 --- /dev/null +++ b/core/test/client/unit/components/gh-url-preview_test.js @@ -0,0 +1,38 @@ +/* jshint expr:true */ +import { + describeComponent, + it +} from 'ember-mocha'; + +describeComponent('gh-url-preview', + function () { + it('generates the correct preview URL with a prefix', function () { + var component = this.subject({ + prefix: 'tag', + slug: 'test-slug', + tagName: 'p', + classNames: 'test-class', + + config: {blogUrl: 'http://my-ghost-blog.com'} + }); + + this.render(); + + expect(component.get('url')).to.equal('my-ghost-blog.com/tag/test-slug/'); + }); + + it('generates the correct preview URL without a prefix', function () { + var component = this.subject({ + slug: 'test-slug', + tagName: 'p', + classNames: 'test-class', + + config: {blogUrl: 'http://my-ghost-blog.com'} + }); + + this.render(); + + expect(component.get('url')).to.equal('my-ghost-blog.com/test-slug/'); + }); + } +);