@@ -28,4 +28,66 @@ $(document).ready(function() {
2828 equal ( _ . keys ( view . model . _callbacks ) . length , 0 ) ;
2929 } ) ;
3030
31+ test ( 'unstickModel (multiple models across multiple views)' , function ( ) {
32+
33+ var model1 , model2 , view , view2 , model3 ;
34+
35+ model1 = new ( Backbone . Model ) ( { one :'' , two :'' } ) ;
36+ model2 = new ( Backbone . Model ) ( { three :'' , four :'' } ) ;
37+ model3 = new ( Backbone . Model ) ( { five :'' , six :'' } ) ;
38+
39+ view = new ( Backbone . View . extend ( {
40+ initialize : function ( ) {
41+ this . model = model1 ;
42+ } ,
43+ bindings : {
44+ '.test12-1' : 'one' ,
45+ '.test12-2' : 'two'
46+ } ,
47+ otherBindings : {
48+ '.test12-3' : 'three' ,
49+ '.test12-4' : 'four'
50+ } ,
51+ render : function ( ) {
52+ var html = document . getElementById ( 'jst12' ) . innerHTML ;
53+ this . $el . html ( _ . template ( html ) ( ) ) ;
54+ this . stickit ( ) ;
55+ this . stickit ( model2 , this . otherBindings ) ;
56+ return this ;
57+ }
58+ } ) ) ( ) . render ( ) ;
59+
60+ view2 = new ( Backbone . View . extend ( {
61+ bindings : {
62+ '.test13-5' : 'five' ,
63+ '.test13-6' : 'six'
64+ } ,
65+ render : function ( ) {
66+ var html = document . getElementById ( 'jst13' ) . innerHTML ;
67+ this . $el . html ( _ . template ( html ) ( ) ) ;
68+ this . stickit ( model3 ) ;
69+ return this ;
70+ }
71+ } ) ) ( ) . render ( ) ;
72+
73+
74+ equal ( _ . keys ( model1 . _callbacks ) . length , 2 ) ;
75+ equal ( _ . keys ( model2 . _callbacks ) . length , 2 ) ;
76+ equal ( _ . keys ( model3 . _callbacks ) . length , 2 ) ;
77+ equal ( view . _modelBindings . length , 4 ) ;
78+ equal ( view2 . _modelBindings . length , 2 ) ;
79+
80+ view . unstickModel ( ) ;
81+
82+ equal ( _ . keys ( model1 . _callbacks ) . length , 0 ) ;
83+ equal ( _ . keys ( model2 . _callbacks ) . length , 0 ) ;
84+ equal ( view . _modelBindings . length , 0 ) ;
85+ equal ( _ . keys ( model3 . _callbacks ) . length , 2 ) ;
86+
87+ view2 . unstickModel ( ) ;
88+
89+ equal ( _ . keys ( model3 . _callbacks ) . length , 0 ) ;
90+ equal ( view2 . _modelBindings . length , 0 ) ;
91+ } ) ;
92+
3193} ) ;
0 commit comments