Commit 08ab4f5f authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Convert our ad-hoc comments test into Jasmine spec.

Include jasmine-node into our comments backend dependencies.

Write comments.spec.js to test all methods in Comments class.
For now we're using the actual full database - must replace with a test
database.

Add :jasmine task to Rakefile.
parent c2d5573c
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -14,6 +14,11 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
  spec.pattern = "spec/**/*_spec.rb"
end

desc "Run Jasmine specs for comments backend"
task :jasmine do
  system("node comments/node_modules/jasmine-node/lib/jasmine-node/cli.js comments/")
end

def load_sdk_vars
  if File.exists?("sdk-vars.rb")
    require "./sdk-vars.rb"
+4 −4
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ module.exports = (function(){
         * Excludes deleted comments.
         *
         * @param {Object} opts Options for the query:
         * @param {Number} opts.limit Number of rows to return.
         * @param {Number} opts.offset The starting index.
         * @param {Number} [opts.limit=100] Number of rows to return.
         * @param {Number} [opts.offset=0] The starting index.
         *
         * @param {Function} callback Called with the result.
         * @param {Object[]} callback.comments An array of comment rows.
@@ -61,7 +61,7 @@ module.exports = (function(){
                'LIMIT ? OFFSET ?'
            ];

            this.query(sql, [this.domain, opts.limit, opts.offset], callback);
            this.query(sql, [this.domain, opts.limit||100, opts.offset||0], callback);
        },

        /**
@@ -81,7 +81,7 @@ module.exports = (function(){
            ];

            this.query(sql, [this.domain], function(rows) {
                callback(rows[0].count);
                callback(+rows[0].count);
            });
        },

+57 −0
Original line number Diff line number Diff line
describe("Comments", function() {
    var Comments = require("./comments");
    var mysql = require('mysql');
    var connection;
    var comments;

    beforeEach(function() {
        connection = mysql.createConnection({
            host: 'localhost',
            user: '',
            password: '',
            database: 'comments'
        });

        comments = new Comments(connection, "ext-js-4");
    });

    afterEach(function() {
        connection.end();
    });

    it("#find returns comments for a target", function(done) {
        comments.find({type: "class", cls: "Ext", member: "method-define"}, function(rows) {
            expect(rows.length).toEqual(4);
            done();
        });
    });

    it("#findRecent returns n recent comments", function(done) {
        comments.findRecent({limit: 10, offset: 0}, function(rows) {
            expect(rows.length).toEqual(10);
            done();
        });
    });

    it("#findRecent without offset option default to offset:0", function(done) {
        comments.findRecent({limit: 10}, function(rows) {
            expect(rows.length).toEqual(10);
            done();
        });
    });

    it("#findRecent without limit option default to limit:100", function(done) {
        comments.findRecent({}, function(rows) {
            expect(rows.length).toEqual(100);
            done();
        });
    });

    it("#count gets total number of comments", function(done) {
        comments.count({}, function(cnt) {
            expect(cnt).toEqual(1705);
            done();
        });
    });

});

comments/comments_test.js

deleted100644 → 0
+0 −16
Original line number Diff line number Diff line
var Comments = require("./comments");
var mysql = require('mysql');

var connection = mysql.createConnection({
    host: 'localhost',
    user: '',
    password: '',
    database: 'comments'
});

var comments = new Comments(connection, "touch-2");

comments.count({}, function(cnt) {
    console.log(cnt + " comments");
    process.exit();
});