Skip to content

Commit

Permalink
tests for issue #8 when there are multiple models stuck in a view
Browse files Browse the repository at this point in the history
  • Loading branch information
delambo committed Sep 25, 2012
1 parent 7ae82e2 commit 6972d6f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ <h2 id="qunit-userAgent"></h2>

<script id="jst11" type="text/jst"><input type="number" id="test11"></script>

<script id="jst12" type="text/jst">
<input type="number" class="test12-1">
<input type="number" class="test12-2">
<input type="number" class="test12-3">
<input type="number" class="test12-4">
</script>

<script id="jst13" type="text/jst">
<input type="number" class="test13-5">
<input type="number" class="test13-6">
</script>

</body>

</html>
62 changes: 62 additions & 0 deletions test/modelBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,66 @@ $(document).ready(function() {
equal(_.keys(view.model._callbacks).length, 0);
});

test('unstickModel (multiple models across multiple views)', function() {

var model1, model2, view, view2, model3;

model1 = new (Backbone.Model)({one:'', two:''});
model2 = new (Backbone.Model)({three:'', four:''});
model3 = new (Backbone.Model)({five:'', six:''});

view = new (Backbone.View.extend({
initialize: function() {
this.model = model1;
},
bindings: {
'.test12-1': 'one',
'.test12-2': 'two'
},
otherBindings: {
'.test12-3': 'three',
'.test12-4': 'four'
},
render: function() {
var html = document.getElementById('jst12').innerHTML;
this.$el.html(_.template(html)());
this.stickit();
this.stickit(model2, this.otherBindings);
return this;
}
}))().render();

view2 = new (Backbone.View.extend({
bindings: {
'.test13-5': 'five',
'.test13-6': 'six'
},
render: function() {
var html = document.getElementById('jst13').innerHTML;
this.$el.html(_.template(html)());
this.stickit(model3);
return this;
}
}))().render();


equal(_.keys(model1._callbacks).length, 2);
equal(_.keys(model2._callbacks).length, 2);
equal(_.keys(model3._callbacks).length, 2);
equal(view._modelBindings.length, 4);
equal(view2._modelBindings.length, 2);

view.unstickModel();

equal(_.keys(model1._callbacks).length, 0);
equal(_.keys(model2._callbacks).length, 0);
equal(view._modelBindings.length, 0);
equal(_.keys(model3._callbacks).length, 2);

view2.unstickModel();

equal(_.keys(model3._callbacks).length, 0);
equal(view2._modelBindings.length, 0);
});

});

0 comments on commit 6972d6f

Please sign in to comment.