<commit_before>require('./support/helper');

var path = require("path")
  , expect = require("expect.js")
  , fs = require("fs")
  , generateTemplate = require("./support/generate_template")
  , Backbone = require('Backbone')
  , modelReaction = require('../lib/reactions/model')

delete require.cache[require.resolve('Backbone')]
var BackboneClone = require('Backbone') // To Test Bug. EndDash module might have a different Backbone then a client's
                                        // main application. Internally we use !(model instanceof Backbone.Model || ... instanceof Backbone.Collection)
                                        // this test is intended to check that our code now handles this case

describe("With a backbone model from a different backbone object", function(){
  it("Should still work properly", function(){
    var model = new BackboneClone.Model({persisted: "<NAME>"})
      , template = generateTemplate({user: model}, "<div class='user-'><div class='persisted-'></div></div>")

    expect($('.persisted-').html()).to.be('Chelsa Piers')
    model.set('persisted', 'Changed')
    expect($('.persisted-').html()).to.be('Changed')
  })
})

describe("With a backbone model", function(){
  beforeEach(function(){
    var backModel = new Backbone.Model()
  })
  it("Should work as normal", function(){
    var model = new Backbone.Model({persisted: "<NAME>"})
      , template = generateTemplate({user: model}, "<div class='user-'><div class='persisted-'></div></div>")

    expect($('.persisted-').html()).to.be('C<NAME>')
    model.set('persisted', 'Changed')
    expect($('.persisted-').html()).to.be('Changed')
  })
})

describe("With a backbone collection from a different backbone object", function(){
  beforeEach(function(){
    this.collection = new BackboneClone.Collection()
    this.templateString = "<div class='users-'><div class ='user-'><div class=' #{hook} persisted-'></div></div></div>"
  })

  describe("With models from a different backbone object", function(){
    it("Should still work properly", function(){
      var model1 = new BackboneClone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = new BackboneClone.Model({persisted: "<NAME>", hook: '2'})
        , model3 = new BackboneClone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
      model1.set('persisted', 'Changed1')
      model2.set('persisted', 'Changed2')
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
    })
  })

  describe("With anonymous models", function(){
    it("Should still interpolate values but changes will not be updated", function(){
      var model1 = {persisted: "<NAME>", hook: '1'}
        , model2 = {persisted: "<NAME>", hook: '2'}
        , model3 = {persisted: "Soho", hook: '3'}
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.persisted)
      expect($('.2').html()).to.be(model2.persisted)
      expect($('.3').html()).to.be(model3.persisted)
      model1.persisted = 'Changed1'
      model2.persisted = 'Changed2'
      model3.persisted = 'Changed3'
      expect($('.1').html()).to.be("<NAME>")
      expect($('.2').html()).to.be("Columbus circle")
      expect($('.3').html()).to.be("Soho")
    })
  })

})<commit_msg>Collections with mixed model type specs added<commit_after>require('./support/helper');

var path = require("path")
  , expect = require("expect.js")
  , fs = require("fs")
  , generateTemplate = require("./support/generate_template")
  , Backbone = require('Backbone')

delete require.cache[require.resolve('Backbone')]
var BackboneClone = require('Backbone') // Internally we use !(model instanceof Backbone.Model || ... instanceof Backbone.Collection)
                                        // If the Backbone for EndDash is different then the clients, we want to handle this case.
                                        // See lib/reactions/model.js for fix.

describe("With a backbone model from a different backbone object", function(){
  it("Should still work properly", function(){
    var model = new BackboneClone.Model({persisted: "<NAME>"})
      , template = generateTemplate({user: model}, "<div class='user-'><div class='persisted-'></div></div>")

    expect($('.persisted-').html()).to.be('<NAME>')
    model.set('persisted', 'Changed')
    expect($('.persisted-').html()).to.be('Changed')
  })
})

describe("With a backbone model", function(){
  beforeEach(function(){
    var backModel = new Backbone.Model()
  })
  it("Should work as normal", function(){
    var model = new Backbone.Model({persisted: "<NAME>"})
      , template = generateTemplate({user: model}, "<div class='user-'><div class='persisted-'></div></div>")

    expect($('.persisted-').html()).to.be('<NAME>')
    model.set('persisted', 'Changed')
    expect($('.persisted-').html()).to.be('Changed')
  })
})

describe("With a backbone collection from a different backbone object", function(){
  beforeEach(function(){
    this.collection = new BackboneClone.Collection()
    this.templateString = "<div class='users-'><div class ='user-'><div class=' #{hook} persisted-'></div></div></div>"
  })

  describe("With models from a different backbone object", function(){
    it("Should still work properly", function(){
      var model1 = new BackboneClone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = new BackboneClone.Model({persisted: "<NAME>", hook: '2'})
        , model3 = new BackboneClone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
      model1.set('persisted', 'Changed1')
      model2.set('persisted', 'Changed2')
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
    })
  })

  describe("With anonymous models", function(){
    it("Should still interpolate values but changes will not be updated", function(){
      var model1 = {persisted: "<NAME>", hook: '1'}
        , model2 = {persisted: "<NAME>", hook: '2'}
        , model3 = {persisted: "Soho", hook: '3'}
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.persisted)
      expect($('.2').html()).to.be(model2.persisted)
      expect($('.3').html()).to.be(model3.persisted)
      model1.persisted = 'Changed1'
      model2.persisted = 'Changed2'
      model3.persisted = 'Changed3'
      expect($('.1').html()).to.be("<NAME>")
      expect($('.2').html()).to.be("Columbus circle")
      expect($('.3').html()).to.be("Soho")
    })
  })

  describe("With a mix of different model kinds", function(){
    it("Should still work properly", function(){
      var model1 = new BackboneClone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = {persisted: "Columbus circle", hook: '2'}
        , model3 = new Backbone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.persisted)
      expect($('.3').html()).to.be(undefined)
      model1.set('persisted', 'Changed1')
      model2.persisted = 'Changed2'
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be("Columbus circle")
      expect($('.3').html()).to.be(undefined)
    })
  })
})

describe("With a backbone collection from the same backbone object", function(){
  beforeEach(function(){
    this.collection = new Backbone.Collection()
    this.templateString = "<div class='users-'><div class ='user-'><div class=' #{hook} persisted-'></div></div></div>"
  })

  describe("With models from a different backbone object", function(){
    it("Does not work properly", function(){
      var model1 = new BackboneClone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = new BackboneClone.Model({persisted: "<NAME>", hook: '2'})
        , model3 = new BackboneClone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(undefined)
      expect($('.2').html()).to.be(undefined)
      expect($('.3').html()).to.be(undefined)
      model1.set('persisted', 'Changed1')
      model2.set('persisted', 'Changed2')
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(undefined)
      expect($('.2').html()).to.be(undefined)
      expect($('.3').html()).to.be(undefined)
    })
  })

  describe("With models from the same backbone object", function(){
    it("Does not work properly", function(){
      var model1 = new Backbone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = new Backbone.Model({persisted: "<NAME>", hook: '2'})
        , model3 = new Backbone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
      model1.set('persisted', 'Changed1')
      model2.set('persisted', 'Changed2')
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.get('persisted'))
      expect($('.3').html()).to.be(model3.get('persisted'))
    })
  })

  describe("With anonymous models", function(){
    it("Should still interpolate values but changes will not be updated", function(){
      var model1 = {persisted: "<NAME>", hook: '1'}
        , model2 = {persisted: "<NAME>", hook: '2'}
        , model3 = {persisted: "Soho", hook: '3'}
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.persisted)
      expect($('.2').html()).to.be(model2.persisted)
      expect($('.3').html()).to.be(model3.persisted)
      model1.persisted = 'Changed1'
      model2.persisted = 'Changed2'
      model3.persisted = 'Changed3'
      expect($('.1').html()).to.be("<NAME>")
      expect($('.2').html()).to.be("Columbus circle")
      expect($('.3').html()).to.be("Soho")
    })
  })

  describe("With a mix of different model kinds", function(){
    it("Should still work properly", function(){
      var model1 = new Backbone.Model({persisted: "<NAME>", hook: '1'})
        , model2 = {persisted: "Columbus circle", hook: '2'}
        , model3 = new BackboneClone.Model({persisted: "Soho", hook: '3'})
      this.collection.add([model1, model2, model3])
      var template = generateTemplate({users: this.collection}, this.templateString)
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be(model2.persisted)
      expect($('.3').html()).to.be(undefined)
      model1.set('persisted', 'Changed1')
      model2.persisted = 'Changed2'
      model3.set('persisted', 'Changed3')
      expect($('.1').html()).to.be(model1.get('persisted'))
      expect($('.2').html()).to.be("Columbus circle")
      expect($('.3').html()).to.be(undefined)
    })
  })
})
{'fraction_non_alphanumeric': 0.2089188530582406, 'fraction_numerical': 0.018032653724311593, 'mean_word_length': 3.654820415879017, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5695126', 'n_tokens_mistral': 3762, 'n_tokens_neox': 3707, 'n_words': 763}