"use strict";
/*global describe:false, it:false, beforeEach: false, afterEach: false */
process.env.NODE_ENV = "test";

var request = require("supertest");
var should = require("should");
var app = require("../app");
var db = require("../db-connector");
var pageFactory = require("./factories/page");
var Page = require("../models/page");
var async = require("async");

describe("Page", function () {
    beforeEach(function () {
        db.connect();
    });

    afterEach(function (done) {
        db.wipe(function (err) {
            if (err) throw err;
            db.close(done);
        });
    });

    it("shuold allow path updates", function (done) {
        var newPage = pageFactory();
        request(app)
            .post("/foobar")
            .expect(200)
            .send(newPage)
            .end(function (err, res) {
            request(app)
                .put("/foobar")
                .send({
                newPath: "/foobaz"
            })
                .end(function (err, res) {
                should.not.exist(err);

                async.parallel([
                    function (cb) {
                        Page.count({path: "/foobar"}, function (err, count) {
                            should.not.exist(err);
                            count.should.eql(0);
                            cb();
                        });
                    },
                    function (cb) {
                        Page.count({path: "/foobaz"}, function (err, count) {
                            should.not.exist(err);
                            count.should.eql(1);
                            cb();
                        });
                    }
                ], done);

            });
        });
    });
});

@@ -1316,32 +1316,35 @@
              cb(
+err
 );%0A             
@@ -1626,16 +1626,19 @@
      cb(
+err
 );%0A     
@@ -1708,17 +1708,16 @@
  done);%0A
-%0A
         
@@ -1743,13 +1743,849 @@
 %0A    %7D);
+%0A%0A    it(%22shuold not allow path update on existing path%22, function (done) %7B%0A        async.parallel(%5Bfunction (cb) %7B%0A            var newPage = pageFactory();%0A            var page = new Page(newPage);%0A            page.path = %22/foobar%22;%0A            page.save(cb);%0A        %7D,%0A        function (cb) %7B%0A            var newPage = pageFactory();%0A            var page = new Page(newPage);%0A            page.path = %22/foobaz%22;%0A            page.save(cb);%0A        %7D%5D, function (err) %7B%0A            request(app)%0A                .put(%22/foobar%22)%0A                .send(%7BnewPath: %22/foobaz%22%7D)%0A                .expect(200)%0A                .end( function (err, res) %7B%0A                    var response = JSON.parse(res.text);%0A                    response.status.should.eql(%22page-exists%22);%0A%0A                    done(err);%0A                %7D);%0A        %7D);%0A%0A    %7D);
 %0A%7D);%0A

add test for moving page on existing target