keithwhor/nodal

Support of test database and seeding test db

nsipplswezey opened this issue · 1 comments

When I run a test generated by nodal g:test todos_controller_test I get the following error:

Nicolass-MacBook-Air:todo-pgjson nsipplsw$ npm test

> todo-pgjson@0.0.0 test /Users/nsipplsw/todo-pgjson
> mocha ./test/runner.js



  My Application
    ExampleTest
      ✓ Should compare 1 and 1
      ✓ Should add 1 and 1, asynchronously
    IndexControllerTest
      ✓ Should return an HTTP 200
    TodosControllerTest
Database Error: database "todo_pgjson_test" does not exist
      1) Should return an HTTP 200


  3 passing (2s)
  1 failing

  1) My Application TodosControllerTest Should return an HTTP 200:
     Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.




npm ERR! Test failed.  See above for more details.

The current workaround is to create "todo_pgjson_test" manually.
But it would be great to have the test db created when we run npm test...
Or have the option to say: nodal db:create test and have it create the test db

Additionally, adding seed data to the test property in db.config doesn't seem to do anything.

nodal db:bootstrap only indicates seeding of the development db.

Nicolass-MacBook-Air:todo-pgjson nsipplsw$ nodal db:bootstrap
Database Info: Transaction started...

DROP SCHEMA public CASCADE
[]
44ms


CREATE SCHEMA public
[]
72ms


CREATE TABLE "schema_migrations"("id" BIGINT NOT NULL,"schema" VARCHAR,CONSTRAINT "schema_migrations_id_pk" PRIMARY KEY("id"))
[]
78ms

Database Info: Commit started...
Database Info: Commit complete!
Database Info: Transaction complete!

SELECT ("schema_migrations"."id") AS "id" FROM schema_migrations AS "schema_migrations"
[]
16ms


SELECT "schema_migrations"."schema" FROM "schema_migrations" ORDER BY "id" DESC LIMIT 1
[]
48ms

Database Info: Transaction started...

CREATE TABLE "todos"("id" BIGINT NOT NULL,"user_id" BIGINT,"tasks" JSONB,"done" BOOLEAN,"created_at" TIMESTAMP,"updated_at" TIMESTAMP,CONSTRAINT "todos_id_pk" PRIMARY KEY("id"))
[]
1ms


CREATE SEQUENCE "todos_id_seq" START 1 OWNED BY "todos"."id"
[]
6ms


SELECT setval('"todos_id_seq"', GREATEST(COALESCE(MAX("id"), 0), 0) + 1, false) FROM "todos"
[]
8ms


ALTER TABLE "todos" ALTER COLUMN "id" SET DEFAULT nextval('"todos_id_seq"')
[]
15ms


INSERT INTO "schema_migrations"("id", "schema") VALUES(2016060501414800, '{

  "migration_id": 2016060501414800,

  "models": {

    "Todo": {

      "table": "todos",

      "columns": [
        {"name": "id", "type": "serial", "properties": {"nullable":false,"primary_key":true,"auto_increment":true}},
        {"name": "user_id", "type": "int", "properties": {}},
        {"name": "tasks", "type": "json", "properties": {}},
        {"name": "done", "type": "boolean", "properties": {}},
        {"name": "created_at", "type": "datetime", "properties": {}},
        {"name": "updated_at", "type": "datetime", "properties": {}}
      ]

    }

  }

}
')
[]
20ms

Database Info: Commit started...
Database Info: Commit complete!
Database Info: Transaction complete!
Database Info: Transaction started...

INSERT INTO "todos"("user_id","tasks","done","created_at","updated_at") VALUES($1,$2,$3,$4,$5) RETURNING *
[1,"{\"grapes\":\"7\",\"bananas\":\"4\",\"apples\":\"3\"}","f","2016-06-05T02:21:39.730Z","2016-06-05T02:21:39.730Z"]
33ms

Database Info: Commit started...
Database Info: Commit complete!
Database Info: Transaction complete!
{

  "development": {
    "Todo": [
      {
        "user_id" : "1",
        "done" : "false",
        "tasks" : {"grapes":"7","bananas":"4","apples":"3"}
      }
    ]
  },

  "test": {
    "Todo": [
      {
        "user_id" : "1",
        "done" : "false",
        "tasks" : {"grapes":"7","bananas":"4","apples":"3"}
      }
    ]
  },

  "production": {}

}

This is fixed. nodal db:create --env test should do what you want.