<commit_before>var Sequelize = require(__dirname + "/../lib/sequelize/Sequelize").Sequelize
var s = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
var Day = s.define('Day', { name: Sequelize.TEXT })

module.exports = {
  'constructor': function(assert) {
    assert.eql(Day.associations, [])
    assert.eql(Day.attributes, {"name": {type: "TEXT"},"createdAt": {type: "DATETIME", allowNull: false},"updatedAt": {type: "DATETIME", allowNull: false}})
    assert.eql(Day.tableName, 'Days')
  },
  'new': function(assert) {
    var day = new Day({name: 'asd'})
    assert.isNull(day.id)
    assert.eql(day.table, Day)
    assert.eql(day.name, 'asd')
    assert.isUndefined(new Day({name: 'asd', bla: 'foo'}).bla)
  },
  'prepareAssociations belongsTo': function(assert) {
    var s = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
    var Me = s.define('Me', {})
    var You = s.define('You', {})
    var assoc = Me.hasOne('you', You)
    You.belongsTo('me', Me, assoc)
    
    Me.prepareAssociations()
    You.prepareAssociations()

    assert.includes(Sequelize.Helper.Hash.keys(You.attributes), 'meId')
    assert.isDefined(You.attributes.meId)
    assert.isNotNull(You.attributes.meId)
  },
  'prepareAssociations hasMany': function(assert) {
    var House = s.define('House', {})
    var Person = s.define('Person', {})

    House.hasMany('members', Person, 'households')
    House.prepareAssociations()
    Person.prepareAssociations()

    assert.isUndefined(House.attributes.personId)
    assert.isUndefined(House.attributes.membersId)
    assert.isUndefined(Person.attributes.houseId)

    assert.isDefined(s.tables.HouseholdsMembers)
  },
  'sync should return the table class': function(assert, beforeExit) {
    var toBeTested = null
    Day.sync(function(_Day) { toBeTested = _Day })
    beforeExit(function() { assert.eql(toBeTested, Day) })
  },
  'drop should return the table class': function(assert, beforeExit) {
    var toBeTested = null
    Day.drop(function(_Day) { toBeTested = _Day })
    beforeExit(function() { assert.eql(toBeTested, Day) })
  },
  'findAll should return all items as class objects': function(assert, beforeExit) {
    var allFindAllTestItems = null
    var FindAllTest = s.define('FindAllTest', {})

    Sequelize.chainQueries([
      {drop: FindAllTest}, {sync: FindAllTest}, {save: new FindAllTest({})}, {save: new FindAllTest({})}
    ], function() {
      FindAllTest.findAll(function(findAlls) {
        allFindAllTestItems = findAlls
      })
    })
    
    beforeExit(function(){
      assert.equal(allFindAllTestItems.length, 2)
      allFindAllTestItems.forEach(function(item) {
        assert.equal(item instanceof FindAllTest, true)
      })
    })
  },
  'find returns the correct item': function(assert, beforeExit) {
    var item = null
    var itemToMatch = null
    var FindTest = s.define('FindTest', { name: Sequelize.STRING })
    FindTest.drop(function() {
      FindTest.sync(function() {
        itemToMatch = new FindTest({name: 'foo'})
        itemToMatch.save(function() {
          new FindTest({name: 'bar'}).save(function() {
            FindTest.find({name: 'foo'}, function(result) {
              item = result
            })
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.equal(itemToMatch.id, item.id)
      assert.equal(itemToMatch.name, item.name)
    })
  },
  'find returns data in correct attributes': function(assert, beforeExit) {
    var assertMe = null
    var FindMeNow = s.define('FindMeNow', { title: Sequelize.STRING, content: Sequelize.TEXT })
    FindMeNow.drop(function() {
      FindMeNow.sync(function() {
        new FindMeNow({title: 'a title', content: 'a content'}).save(function(blubb) {
          assertMe = blubb
        })
      })
    })
    beforeExit(function() {
      assert.isNotNull(assertMe)
      assert.equal(assertMe.title, 'a title')
      assert.equal(assertMe.content, 'a content')
    })
  },
  'sqlResultToObject returns the correct object': function(assert) {
    var SqlResultToObjectTest = s.define('SqlResultToObject', {name: Sequelize.STRING})
    var toBeTested = SqlResultToObjectTest.sqlResultToObject({
      id: 1,
      name: 'foo'
    })
    assert.equal(toBeTested instanceof SqlResultToObjectTest, true)
    assert.equal(toBeTested.id, 1)
    assert.equal(toBeTested.name, 'foo')
  },
  'hasMany': function(assert) {
    var HasManyBlubb = s.define('HasManyBlubb', {})
    Day.hasMany('HasManyBlubbs', HasManyBlubb)
    assert.isDefined(new Day({name:''}).getHasManyBlubbs)
  },
  'hasMany: set association': function(assert, beforeExit) {
    var assoc = null
    var Character = s.define('Character', {})
    var Word = s.define('Word', {})
    Character.hasMany('Words', Word, 'Characters')

    Sequelize.chainQueries([
      {drop: Character}, {drop: Word}, {prepareAssociations: Word}, {prepareAssociations: Character}, {sync: Word}, {sync: Character}
    ],
    function() {
      var Association = s.tables.CharactersWords.klass
      Association.sync(function() {
        var w = new Word()
        var c1 = new Character()
        var c2 = new Character()
        Sequelize.chainQueries([{save: w}, {save: c1}, {save: c2}], function() {
          w.setCharacters([c1, c2], function(associations) {
            assoc = associations
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.isNotNull(assoc)
      assert.equal(assoc.length, 2)
    })
  },
  'hasOne': function(assert) {
    var s = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
    var Day = s.define('Day2', { name: Sequelize.TEXT })
    var HasOneBlubb = s.define('HasOneBlubb', {})
    Day.hasOne('HasOneBlubb', HasOneBlubb)
    assert.isDefined(new Day({name:''}).getHasOneBlubb)
  },
  'hasOne set association': function(assert, beforeExit) {
    var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
    var Task = s2.define('Task', {title: Sequelize.STRING})
    var Deadline = s2.define('Deadline', {date: Sequelize.DATE})
    
    var taskAssoc = Task.hasOne('deadline', Deadline)
    Deadline.belongsTo('task', Task, taskAssoc)

    var task = new Task({ title:'do smth' })
    var deadline = new Deadline({date: new Date()})
    var assertMe = null
    
    Sequelize.chainQueries([{sync: s2}, {drop: s2}, {sync: s2}, {save: task}, {save: deadline}], function() {
      task.setDeadline(deadline, function(_deadline) {
        assertMe = _deadline
      })
    })
    
    beforeExit(function() {
      assert.isNotNull(assertMe)
      assert.eql(assertMe, deadline)
    })
  },
  'belongsTo': function(assert) {
    var BelongsToBlubb = s.define('BelongsToBlubb', {})
    var Day = s.define('Day2', { name: Sequelize.TEXT })
    var assoc = Day.hasOne('asd', BelongsToBlubb)
    Day.belongsTo('BelongsToBlubb', BelongsToBlubb, assoc)
    assert.isDefined(new Day({name:''}).getBelongsToBlubb)
  },
  'belongsTo: set association': function(assert, beforeExit) {
    var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
    var Task = s2.define('Task', {title: Sequelize.STRING})
    var Deadline = s2.define('Deadline', {date: Sequelize.DATE})
    var allowExit = false
    
    var assoc = Task.hasOne('deadline', Deadline)
    Deadline.belongsTo('task', Task, assoc)

    var task = new Task({ title:'do smth' })
    var deadline = new Deadline({date: new Date()})
    
    Sequelize.chainQueries([{drop: s2}, {sync: s2}], function() {
      task.save(function() {
        deadline.save(function() {
          assert.isDefined(deadline.id)
          assert.isNotNull(deadline.id)
          deadline.setTask(task, function(_task) {
            assert.isNotNull(_task)
            assert.eql(_task.id, task.id)
            allowExit = true
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.equal(allowExit, true)
    })<commit_msg>fixed specs to use root with no password<commit_after>var Sequelize = require(__dirname + "/../lib/sequelize/Sequelize").Sequelize
var s = new Sequelize('sequelize_test', 'root', null, {disableLogging: true})
var Day = s.define('Day', { name: Sequelize.TEXT })

module.exports = {
  'constructor': function(assert) {
    assert.eql(Day.associations, [])
    assert.eql(Day.attributes, {"name": {type: "TEXT"},"createdAt": {type: "DATETIME", allowNull: false},"updatedAt": {type: "DATETIME", allowNull: false}})
    assert.eql(Day.tableName, 'Days')
  },
  'new': function(assert) {
    var day = new Day({name: 'asd'})
    assert.isNull(day.id)
    assert.eql(day.table, Day)
    assert.eql(day.name, 'asd')
    assert.isUndefined(new Day({name: 'asd', bla: 'foo'}).bla)
  },
  'prepareAssociations belongsTo': function(assert) {
    var s = new Sequelize('sequelize_test', 'root', null, {disableLogging: true})
    var Me = s.define('Me', {})
    var You = s.define('You', {})
    var assoc = Me.hasOne('you', You)
    You.belongsTo('me', Me, assoc)
    
    Me.prepareAssociations()
    You.prepareAssociations()

    assert.includes(Sequelize.Helper.Hash.keys(You.attributes), 'meId')
    assert.isDefined(You.attributes.meId)
    assert.isNotNull(You.attributes.meId)
  },
  'prepareAssociations hasMany': function(assert) {
    var House = s.define('House', {})
    var Person = s.define('Person', {})

    House.hasMany('members', Person, 'households')
    House.prepareAssociations()
    Person.prepareAssociations()

    assert.isUndefined(House.attributes.personId)
    assert.isUndefined(House.attributes.membersId)
    assert.isUndefined(Person.attributes.houseId)

    assert.isDefined(s.tables.HouseholdsMembers)
  },
  'sync should return the table class': function(assert, beforeExit) {
    var toBeTested = null
    Day.sync(function(_Day) { toBeTested = _Day })
    beforeExit(function() { assert.eql(toBeTested, Day) })
  },
  'drop should return the table class': function(assert, beforeExit) {
    var toBeTested = null
    Day.drop(function(_Day) { toBeTested = _Day })
    beforeExit(function() { assert.eql(toBeTested, Day) })
  },
  'findAll should return all items as class objects': function(assert, beforeExit) {
    var allFindAllTestItems = null
    var FindAllTest = s.define('FindAllTest', {})

    Sequelize.chainQueries([
      {drop: FindAllTest}, {sync: FindAllTest}, {save: new FindAllTest({})}, {save: new FindAllTest({})}
    ], function() {
      FindAllTest.findAll(function(findAlls) {
        allFindAllTestItems = findAlls
      })
    })
    
    beforeExit(function(){
      assert.equal(allFindAllTestItems.length, 2)
      allFindAllTestItems.forEach(function(item) {
        assert.equal(item instanceof FindAllTest, true)
      })
    })
  },
  'find returns the correct item': function(assert, beforeExit) {
    var item = null
    var itemToMatch = null
    var FindTest = s.define('FindTest', { name: Sequelize.STRING })
    FindTest.drop(function() {
      FindTest.sync(function() {
        itemToMatch = new FindTest({name: 'foo'})
        itemToMatch.save(function() {
          new FindTest({name: 'bar'}).save(function() {
            FindTest.find({name: 'foo'}, function(result) {
              item = result
            })
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.equal(itemToMatch.id, item.id)
      assert.equal(itemToMatch.name, item.name)
    })
  },
  'find returns data in correct attributes': function(assert, beforeExit) {
    var assertMe = null
    var FindMeNow = s.define('FindMeNow', { title: Sequelize.STRING, content: Sequelize.TEXT })
    FindMeNow.drop(function() {
      FindMeNow.sync(function() {
        new FindMeNow({title: 'a title', content: 'a content'}).save(function(blubb) {
          assertMe = blubb
        })
      })
    })
    beforeExit(function() {
      assert.isNotNull(assertMe)
      assert.equal(assertMe.title, 'a title')
      assert.equal(assertMe.content, 'a content')
    })
  },
  'sqlResultToObject returns the correct object': function(assert) {
    var SqlResultToObjectTest = s.define('SqlResultToObject', {name: Sequelize.STRING})
    var toBeTested = SqlResultToObjectTest.sqlResultToObject({
      id: 1,
      name: 'foo'
    })
    assert.equal(toBeTested instanceof SqlResultToObjectTest, true)
    assert.equal(toBeTested.id, 1)
    assert.equal(toBeTested.name, 'foo')
  },
  'hasMany': function(assert) {
    var HasManyBlubb = s.define('HasManyBlubb', {})
    Day.hasMany('HasManyBlubbs', HasManyBlubb)
    assert.isDefined(new Day({name:''}).getHasManyBlubbs)
  },
  'hasMany: set association': function(assert, beforeExit) {
    var assoc = null
    var Character = s.define('Character', {})
    var Word = s.define('Word', {})
    Character.hasMany('Words', Word, 'Characters')

    Sequelize.chainQueries([
      {drop: Character}, {drop: Word}, {prepareAssociations: Word}, {prepareAssociations: Character}, {sync: Word}, {sync: Character}
    ],
    function() {
      var Association = s.tables.CharactersWords.klass
      Association.sync(function() {
        var w = new Word()
        var c1 = new Character()
        var c2 = new Character()
        Sequelize.chainQueries([{save: w}, {save: c1}, {save: c2}], function() {
          w.setCharacters([c1, c2], function(associations) {
            assoc = associations
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.isNotNull(assoc)
      assert.equal(assoc.length, 2)
    })
  },
  'hasOne': function(assert) {
    var s = new Sequelize('sequelize_test', 'root', null, {disableLogging: true})
    var Day = s.define('Day2', { name: Sequelize.TEXT })
    var HasOneBlubb = s.define('HasOneBlubb', {})
    Day.hasOne('HasOneBlubb', HasOneBlubb)
    assert.isDefined(new Day({name:''}).getHasOneBlubb)
  },
  'hasOne set association': function(assert, beforeExit) {
    var s2 = new Sequelize('sequelize_test', 'root', null, {disableLogging: true})
    var Task = s2.define('Task', {title: Sequelize.STRING})
    var Deadline = s2.define('Deadline', {date: Sequelize.DATE})
    
    var taskAssoc = Task.hasOne('deadline', Deadline)
    Deadline.belongsTo('task', Task, taskAssoc)

    var task = new Task({ title:'do smth' })
    var deadline = new Deadline({date: new Date()})
    var assertMe = null
    
    Sequelize.chainQueries([{sync: s2}, {drop: s2}, {sync: s2}, {save: task}, {save: deadline}], function() {
      task.setDeadline(deadline, function(_deadline) {
        assertMe = _deadline
      })
    })
    
    beforeExit(function() {
      assert.isNotNull(assertMe)
      assert.eql(assertMe, deadline)
    })
  },
  'belongsTo': function(assert) {
    var BelongsToBlubb = s.define('BelongsToBlubb', {})
    var Day = s.define('Day2', { name: Sequelize.TEXT })
    var assoc = Day.hasOne('asd', BelongsToBlubb)
    Day.belongsTo('BelongsToBlubb', BelongsToBlubb, assoc)
    assert.isDefined(new Day({name:''}).getBelongsToBlubb)
  },
  'belongsTo: set association': function(assert, beforeExit) {
    var s2 = new Sequelize('sequelize_test', 'root', null, {disableLogging: true})
    var Task = s2.define('Task', {title: Sequelize.STRING})
    var Deadline = s2.define('Deadline', {date: Sequelize.DATE})
    var allowExit = false
    
    var assoc = Task.hasOne('deadline', Deadline)
    Deadline.belongsTo('task', Task, assoc)

    var task = new Task({ title:'do smth' })
    var deadline = new Deadline({date: new Date()})
    
    Sequelize.chainQueries([{drop: s2}, {sync: s2}], function() {
      task.save(function() {
        deadline.save(function() {
          assert.isDefined(deadline.id)
          assert.isNotNull(deadline.id)
          deadline.setTask(task, function(_task) {
            assert.isNotNull(_task)
            assert.eql(_task.id, task.id)
            allowExit = true
          })
        })
      })
    })
    
    beforeExit(function() {
      assert.equal(allowExit, true)
    })
{'fraction_non_alphanumeric': 0.15105437707277392, 'fraction_numerical': 0.0028784181215193044, 'mean_word_length': 3.2550585729499466, 'pattern_counts': {'":': 6, '<': 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': '4009170', 'n_tokens_mistral': 5272, 'n_tokens_neox': 5256, 'n_words': 1037}