Skip to content

Commit

Permalink
Merge pull request #1973 from matthew-andrews/updated-time
Browse files Browse the repository at this point in the history
Add tests for og:updated_time in open_graph helper, and add ability to turn it off
  • Loading branch information
Xuanwo committed May 23, 2016
2 parents 569856e + 54404d5 commit a293755
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function openGraphHelper(options) {
var url = options.url || this.url;
var siteName = options.site_name || config.title;
var twitterCard = options.twitter_card || 'summary';
var updated = options.updated || page.updated;
var updated = options.updated !== false ? (options.updated || page.updated) : false;
var result = '';

if (!Array.isArray(images)) images = [images];
Expand Down
32 changes: 32 additions & 0 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var moment = require('moment');
var should = require('chai').should(); // eslint-disable-line

describe('open_graph', function() {
Expand Down Expand Up @@ -371,4 +372,35 @@ describe('open_graph', function() {

result.should.contain(meta({property: 'fb:app_id', content: '123456789'}));
});

it('updated - options', function() {
var result = openGraph.call({
page: { updated: moment('2016-05-23T21:20:21.372Z') },
config: {},
is_post: isPost
}, { });

result.should.contain(meta({property: 'og:updated_time', content: '2016-05-23T21:20:21.372Z'}));
});

it('updated - options - allow overriding og:updated_time', function() {
var result = openGraph.call({
page: { updated: moment('2016-05-23T21:20:21.372Z') },
config: {},
is_post: isPost
}, { updated: moment('2015-04-22T20:19:20.371Z') });

result.should.contain(meta({property: 'og:updated_time', content: '2015-04-22T20:19:20.371Z'}));
});

it('updated - options - allow disabling og:updated_time', function() {
var result = openGraph.call({
page: { updated: moment('2016-05-23T21:20:21.372Z') },
config: {},
is_post: isPost
}, { updated: false });

result.should.not.contain(meta({property: 'og:updated_time', content: '2016-05-23T21:20:21.372Z'}));
});

});

0 comments on commit a293755

Please sign in to comment.