不要怂,就是干,撸起袖子干!

language.spec.js 1.56 KB
if(typeof require === 'function') {
  const buster    = require("buster")
      , Sequelize = require("../index")
      , Helpers   = require('./buster-helpers')
      , dialect   = Helpers.getTestDialect()
}

buster.spec.expose()
buster.testRunner.timeout = 1000

describe(Helpers.getTestDialectTeaser("Language Util"), function() {
  describe("Plural", function(){
    before(function(done) {
      Helpers.initTests({
        dialect: dialect,
        onComplete: function(sequelize) {
          this.sequelize = sequelize
          this.sequelize.options.language = 'es'
          done()
        }.bind(this)
      })
    })

    it("should rename tables to their plural form...", function(done){
      var table = this.sequelize.define('arbol', {name: Sequelize.STRING})
      var table2 = this.sequelize.define('androide', {name: Sequelize.STRING})
      expect(table.tableName).toEqual('arboles')
      expect(table2.tableName).toEqual('androides')
      done()
    })

    it("should be able to pluralize/singularize associations...", function(done){
      var table = this.sequelize.define('arbol', {name: Sequelize.STRING})
      var table2 = this.sequelize.define('androide', {name: Sequelize.STRING})
      var table3 = this.sequelize.define('hombre', {name: Sequelize.STRING})

      table.hasOne(table2)
      table2.belongsTo(table)
      table3.hasMany(table2)

      expect(table.associations.androides.identifier).toEqual('arbolId')
      expect(table2.associations.arboles).toBeDefined()
      expect(table3.associations.androideshombres).toBeDefined()
      done()
    })
  })
})