<commit_before>var expect = require("chai").expect,
	proxyquire = require("proxyquire"),
	sinon = require("sinon");

var pgStub = {},
	clientStub = {},
	done = sinon.spy();

var votes = [ { score: 12, country: "Narnia" },
              { score: 10, country: "Archenland" } ];

var index = proxyquire("../routes/index", {
	'pg' : pgStub
});

pgStub.connect = function(url, callback) {
	callback(null, clientStub, done);
};

clientStub.query = function(sql, callback) {
	var results = { rows: votes };
	callback(null, results);
};


describe("routes/index", function() {
	var req = {}, res = {};
	var spy = res.render = sinon.spy();

	beforeEach(function() {
		spy.reset();
		done.reset();
	});

	it("should render home page", function() {
		index.index(req, res);

		expect(spy.calledOnce).to.equal(true);
		expect(spy.args[0][0]).to.equal("index");
	});

	it("should set page title and navbarActive properties", function() {
		index.index(req, res);

		var locals = spy.args[0][1];
		expect(locals).to.have.property("title").that.equals("Eurovision 2015");
		expect(locals).to.have.property("navbarActive").that.equals("Home");
	});

	it("should include votes in the response", function() {
		index.index(req, res);<commit_msg>Refactored index.test.js to use sinon stubs for pg<commit_after>var expect = require("chai").expect,
	proxyquire = require("proxyquire"),
	sinon = require("sinon");

var pgStub = {},
	clientStub = {},
	done = sinon.spy();

var votes = [ { score: 12, country: "Narnia" },
              { score: 10, country: "Archenland" } ];

var index = proxyquire("../routes/index", {
	'pg' : pgStub
});

pgStub.connect = sinon.stub();
clientStub.query = sinon.stub();

describe("routes/index", function() {
	var req = {}, res = {};
	var spy = res.render = sinon.spy();

	beforeEach(function() {
		pgStub.connect.callsArgWith(1, null, clientStub, done);
		clientStub.query.callsArgWith(1, null, { rows: votes });
		spy.reset();
		done.reset();
	});

	it("should render home page", function() {
		index.index(req, res);

		expect(spy.calledOnce).to.equal(true);
		expect(spy.args[0][0]).to.equal("index");
	});

	it("should set page title and navbarActive properties", function() {
		index.index(req, res);

		var locals = spy.args[0][1];
		expect(locals).to.have.property("title").that.equals("Eurovision 2015");
		expect(locals).to.have.property("navbarActive").that.equals("Home");
	});

	it("should include votes in the response", function() {
		index.index(req, res);
{'fraction_non_alphanumeric': 0.19492549335481274, 'fraction_numerical': 0.010471204188481676, 'mean_word_length': 4.388286334056399, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837210', 'n_tokens_mistral': 899, 'n_tokens_neox': 863, 'n_words': 179}