Commit b0b5ec26 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Integrate Formater into Comments.

When doing #add or #update the content_html field is generated from
content field.
parent 05ec487e
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
var Targets = require("./targets");
var Formatter = require("./formatter");

/**
 * Represents a Comments table.
@@ -146,7 +147,6 @@ Comments.prototype = {
     * @param {Object} comment A comment object with fields:
     * @param {Number} comment.user_id ID of logged-in user.
     * @param {String} comment.content The text of comment.
     * @param {String} comment.content_html Formatted text of comment.
     * @param {Object} comment.target The target:
     * @param {String} comment.target.type   Type name of target.
     * @param {String} comment.target.cls    Class name of target.
@@ -165,7 +165,7 @@ Comments.prototype = {
                target_id: target_id,
                user_id: comment.user_id,
                content: comment.content,
                content_html: comment.content_html,
                content_html: Formatter.format(comment.content),
                created_at: new Date()
            }, callback);
        }.bind(this));
@@ -178,7 +178,6 @@ Comments.prototype = {
     * @param {Number} comment.id ID of the comment to update.
     * @param {Number} comment.user_id ID of the user doing the update.
     * @param {String} comment.content New text for the comment.
     * @param {String} comment.content_html New formatted text for the comment.
     * @param {Error} callback.err The error object.
     * @param {Function} callback Called when done.
     */
@@ -186,7 +185,7 @@ Comments.prototype = {
        var data = {
            id: comment.id,
            content: comment.content,
            content_html: comment.content_html
            content_html: Formatter.format(comment.content)
        };
        this.db.update("comments", data, function(err) {
            if (err) {
+18 −6
Original line number Diff line number Diff line
@@ -120,10 +120,7 @@ describe("Comments", function() {
    it("#add adds a new comment and returns its ID which we can then use to retrieve the comment", function(done) {
        var com = {
            user_id: 1,

            content: "Blah.",
            content_html: "<p>Blah.</p>",

            target: {
                type: "class",
                cls: "Ext",
@@ -141,10 +138,7 @@ describe("Comments", function() {
    it("#add adds a new target when it doesn't yet exist", function(done) {
        var com = {
            user_id: 1,

            content: "Blah.",
            content_html: "<p>Blah.</p>",

            target: {
                type: "class",
                cls: "Blah",
@@ -159,6 +153,24 @@ describe("Comments", function() {
        });
    });

    it("#add auto-generates content_html field", function(done) {
        var com = {
            user_id: 1,
            content: "Blah.",
            target: {
                type: "class",
                cls: "Ext",
                member: "method-getBody"
            }
        };
        comments.add(com, function(err, id) {
            comments.getById(id, function(err, newCom) {
                expect(newCom.content_html.trim()).toEqual("<p>Blah.</p>");
                done();
            });
        });
    });


    it("#update modifies content of existing comment", function(done) {
        var com = {