@@ -3,19 +3,19 @@ import Ember from 'ember';
33
44module ( "ember-buffered-proxy/mixin" ) ;
55
6- test ( "exists" , function ( ) {
6+ test ( "exists" , function ( ) {
77 ok ( Mixin ) ;
88} ) ;
99
1010test ( "that it works" , function ( ) {
1111 var BufferedPorxy = Ember . ObjectProxy . extend ( Mixin ) ;
1212
1313 var content = {
14- baz : 1
14+ baz : 1
1515 } ;
1616
1717 var proxy = BufferedPorxy . create ( {
18- content : content
18+ content : content
1919 } ) ;
2020
2121 equal ( proxy . get ( 'baz' ) , 1 ) ;
@@ -60,3 +60,99 @@ test("that it works", function() {
6060 equal ( proxy . get ( 'baz' ) , 1 ) ;
6161 equal ( content . baz , 1 ) ;
6262} ) ;
63+
64+ test ( "that apply only these keys works" , function ( ) {
65+ var BufferedPorxy = Ember . ObjectProxy . extend ( Mixin ) ;
66+
67+ var content = {
68+ baz : 1 ,
69+ world : 'hello'
70+ } ;
71+
72+ var proxy = BufferedPorxy . create ( {
73+ content : content
74+ } ) ;
75+
76+ equal ( proxy . get ( 'baz' ) , 1 ) ;
77+ equal ( content . baz , 1 ) ;
78+ equal ( proxy . get ( 'world' ) , 'hello' ) ;
79+ equal ( content . world , 'hello' ) ;
80+
81+ ok ( ! ( 'foo' in content ) ) ;
82+ equal ( proxy . get ( 'hasBufferedChanges' ) , false ) ;
83+
84+ proxy . set ( 'foo' , 1 ) ;
85+
86+ equal ( proxy . get ( 'foo' ) , 1 ) ;
87+ ok ( ! ( 'foo' in content ) ) ;
88+ equal ( proxy . get ( 'hasBufferedChanges' ) , true ) ;
89+
90+ proxy . set ( 'testing' , '1234' ) ;
91+
92+ equal ( proxy . get ( 'testing' ) , '1234' ) ;
93+ ok ( ! ( 'testing' in content ) ) ;
94+ equal ( proxy . get ( 'hasBufferedChanges' ) , true ) ;
95+
96+ proxy . applyBufferedChanges ( [ 'foo' ] ) ;
97+
98+ equal ( proxy . get ( 'foo' ) , 1 ) ;
99+ ok ( 'foo' in content ) ;
100+ ok ( ! ( 'testing' in content ) ) ;
101+ equal ( proxy . get ( 'hasBufferedChanges' ) , true ) ;
102+ equal ( content . foo , 1 ) ;
103+ equal ( proxy . get ( 'testing' ) , '1234' ) ;
104+
105+ proxy . applyBufferedChanges ( [ 'testing' ] ) ;
106+
107+ equal ( proxy . get ( 'testing' ) , '1234' ) ;
108+ ok ( 'testing' in content ) ;
109+ equal ( proxy . get ( 'hasBufferedChanges' ) , false ) ;
110+ equal ( content . testing , '1234' ) ;
111+
112+ // Testing discardBufferdChanges with onlyTheseKeys
113+
114+ proxy . setProperties ( {
115+ bar : 2 ,
116+ example : 123
117+ } ) ;
118+
119+ equal ( proxy . get ( 'foo' ) , 1 ) ;
120+ equal ( proxy . get ( 'bar' ) , 2 ) ;
121+ equal ( proxy . get ( 'example' ) , 123 ) ;
122+
123+ ok ( 'foo' in content ) ;
124+ ok ( 'testing' in content ) ;
125+ ok ( ! ( 'bar' in content ) ) ;
126+ ok ( ! ( 'example' in content ) ) ;
127+
128+ equal ( proxy . get ( 'hasBufferedChanges' ) , true ) ;
129+
130+ proxy . discardBufferedChanges ( [ 'bar' ] ) ;
131+
132+ equal ( proxy . get ( 'foo' ) , 1 ) ;
133+ equal ( proxy . get ( 'testing' ) , '1234' ) ;
134+ equal ( proxy . get ( 'bar' ) , undefined ) ;
135+ equal ( proxy . get ( 'example' ) , 123 ) ;
136+
137+ ok ( 'foo' in content ) ;
138+ ok ( 'testing' in content ) ;
139+ ok ( ! ( 'bar' in content ) ) ;
140+ ok ( ! ( 'example' in content ) ) ;
141+ equal ( proxy . get ( 'hasBufferedChanges' ) , true ) ;
142+
143+ proxy . discardBufferedChanges ( [ 'example' ] ) ;
144+
145+ equal ( proxy . get ( 'foo' ) , 1 ) ;
146+ equal ( proxy . get ( 'testing' ) , '1234' ) ;
147+ equal ( proxy . get ( 'bar' ) , undefined ) ;
148+ equal ( proxy . get ( 'example' ) , undefined ) ;
149+
150+ ok ( 'foo' in content ) ;
151+ ok ( 'testing' in content ) ;
152+ ok ( ! ( 'bar' in content ) ) ;
153+ ok ( ! ( 'example' in content ) ) ;
154+ equal ( proxy . get ( 'hasBufferedChanges' ) , false ) ;
155+
156+ equal ( proxy . get ( 'baz' ) , 1 ) ;
157+ equal ( content . baz , 1 ) ;
158+ } ) ;
0 commit comments