71bab2f6 by Michael Richards

Add initial spec for binding with dependent attributes.

1 parent 29c04023
...@@ -26,7 +26,7 @@ describe('Rivets.Binding', function() { ...@@ -26,7 +26,7 @@ describe('Rivets.Binding', function() {
26 it('subscribes to the model for changes via the adapter', function() { 26 it('subscribes to the model for changes via the adapter', function() {
27 spyOn(rivets.config.adapter, 'subscribe'); 27 spyOn(rivets.config.adapter, 'subscribe');
28 binding.bind(); 28 binding.bind();
29 expect(rivets.config.adapter.subscribe).toHaveBeenCalled(); 29 expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.set);
30 }); 30 });
31 31
32 describe('with preloadData set to true', function() { 32 describe('with preloadData set to true', function() {
...@@ -38,8 +38,8 @@ describe('Rivets.Binding', function() { ...@@ -38,8 +38,8 @@ describe('Rivets.Binding', function() {
38 spyOn(binding, 'set'); 38 spyOn(binding, 'set');
39 spyOn(rivets.config.adapter, 'read'); 39 spyOn(rivets.config.adapter, 'read');
40 binding.bind(); 40 binding.bind();
41 expect(rivets.config.adapter.read).toHaveBeenCalledWith(model, 'name');
41 expect(binding.set).toHaveBeenCalled(); 42 expect(binding.set).toHaveBeenCalled();
42 expect(rivets.config.adapter.read).toHaveBeenCalled();
43 }); 43 });
44 }); 44 });
45 45
...@@ -55,6 +55,19 @@ describe('Rivets.Binding', function() { ...@@ -55,6 +55,19 @@ describe('Rivets.Binding', function() {
55 expect(binding.set).toHaveBeenCalledWith('espresso'); 55 expect(binding.set).toHaveBeenCalledWith('espresso');
56 }); 56 });
57 }); 57 });
58
59 describe('with dependencies', function() {
60 beforeEach(function() {
61 binding.options.dependencies = ['fname', 'lname'];
62 });
63
64 it('sets up observers on the dependant attributes', function() {
65 spyOn(rivets.config.adapter, 'subscribe');
66 binding.bind();
67 expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'fname', binding.dependencyCallbacks['fname']);
68 expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'lname', binding.dependencyCallbacks['lname']);
69 });
70 });
58 }); 71 });
59 72
60 describe('set()', function() { 73 describe('set()', function() {
......