Question

Using Tower 0.4.2-20: I've followed the examples and the code all seems to be generated but I get a factory not defined error when I run the tests.

To be more specific:

tower new app
cd app
npm install
tower generate scaffold Post title:string body:text
tower generate scaffold User firstName:string lastName:string email:string
npm test

Yields:

 1) PostsController routes show:

      actual expected

      /posts/undefined



  2) PostsController routes edit:

      actual expected

      /posts/undefined/edit



  3) PostsController #index "before each" hook:
     Error: Factory 'post' doesn't exist.
      at Function.Tower.Factory.options [as get] (/home/jeremy/repos/tower/lib/tower-support/shared/factory.js:84:13)
      at Function.Tower.Factory.factory [as create] (/home/jeremy/repos/tower/lib/tower-support/shared/factory.js:73:17)
      at global.factory (/home/jeremy/test/towapp/test/server.coffee:21:42)
      at Context.get.format (/home/jeremy/test/towapp/test/cases/controllers/server/postsControllerTest.coffee:46:16)
      at Hook.Runnable.run (/home/jeremy/test/towapp/node_modules/mocha/lib/runnable.js:187:15)
      at next (/home/jeremy/test/towapp/node_modules/mocha/lib/runner.js:201:10)
      at Runner.hook (/home/jeremy/test/towapp/node_modules/mocha/lib/runner.js:212:5)
      at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I've tried to debug this myself and have built Tower from Github and linked to that one, and as you can see above it is using my repository's version of the code for Tower but I'm getting stuck there too. I'm not sure the correct way to make debug print/logging statements; I've tried console.log and this.debug.log and in both cases no log messages are ever written to the console or to a logs file - in fact no logs are ever created at all in the logs directory.

Edit to add: Made a little more progress. The Tower.Factory.define method is not being called. The Factory class does exist though:

Tower.Factory.define 'post', ->
  title: Tower.random('words')
Was it helpful?

Solution

This was actually pretty easy to solve once I had the children in bed :). The factories files simply weren't included. I added this line to my test/server.coffee file and it fixed this issue:

app.requireDirectory('./test/factories')

I found something like it in one of the generators (tower-generator/server/generators/tower/app/templates/data/seeds.coffee) , but I don't understand the generators yet so not sure where this is really intended to go.

As far as console.log - I just overlooked it - was right there in the console once I was actually calling the define method :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top