Fixes #85
Showing
2 changed files
with
56 additions
and
2 deletions
... | @@ -29,6 +29,17 @@ describe('Rivets.Binding', function() { | ... | @@ -29,6 +29,17 @@ describe('Rivets.Binding', function() { |
29 | expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.sync); | 29 | expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.sync); |
30 | }); | 30 | }); |
31 | 31 | ||
32 | it("calls the binder's bind method if one exists", function() { | ||
33 | expect(function(){ | ||
34 | binding.bind(); | ||
35 | }).not.toThrow(new Error()); | ||
36 | |||
37 | binding.binder.bind = function(){}; | ||
38 | spyOn(binding.binder, 'bind'); | ||
39 | binding.bind(); | ||
40 | expect(binding.binder.bind).toHaveBeenCalled(); | ||
41 | }); | ||
42 | |||
32 | describe('with preloadData set to true', function() { | 43 | describe('with preloadData set to true', function() { |
33 | beforeEach(function() { | 44 | beforeEach(function() { |
34 | rivets.config.preloadData = true; | 45 | rivets.config.preloadData = true; |
... | @@ -54,6 +65,17 @@ describe('Rivets.Binding', function() { | ... | @@ -54,6 +65,17 @@ describe('Rivets.Binding', function() { |
54 | binding.bind(); | 65 | binding.bind(); |
55 | expect(binding.set).toHaveBeenCalledWith('espresso'); | 66 | expect(binding.set).toHaveBeenCalledWith('espresso'); |
56 | }); | 67 | }); |
68 | |||
69 | it("calls the binder's bind method if one exists", function() { | ||
70 | expect(function(){ | ||
71 | binding.bind(); | ||
72 | }).not.toThrow(new Error()); | ||
73 | |||
74 | binding.binder.bind = function(){}; | ||
75 | spyOn(binding.binder, 'bind'); | ||
76 | binding.bind(); | ||
77 | expect(binding.binder.bind).toHaveBeenCalled(); | ||
78 | }); | ||
57 | }); | 79 | }); |
58 | 80 | ||
59 | describe('with dependencies', function() { | 81 | describe('with dependencies', function() { |
... | @@ -70,6 +92,36 @@ describe('Rivets.Binding', function() { | ... | @@ -70,6 +92,36 @@ describe('Rivets.Binding', function() { |
70 | }); | 92 | }); |
71 | }); | 93 | }); |
72 | 94 | ||
95 | describe('unbind()', function() { | ||
96 | it("calls the binder's unbind method if one exists", function() { | ||
97 | expect(function(){ | ||
98 | binding.unbind(); | ||
99 | }).not.toThrow(new Error()); | ||
100 | |||
101 | binding.binder.unbind = function(){}; | ||
102 | spyOn(binding.binder, 'unbind'); | ||
103 | binding.unbind(); | ||
104 | expect(binding.binder.unbind).toHaveBeenCalled(); | ||
105 | }); | ||
106 | |||
107 | describe('with the bypass option set to true', function() { | ||
108 | beforeEach(function() { | ||
109 | binding.options.bypass = true; | ||
110 | }); | ||
111 | |||
112 | it("calls the binder's unbind method if one exists", function() { | ||
113 | expect(function(){ | ||
114 | binding.unbind(); | ||
115 | }).not.toThrow(new Error()); | ||
116 | |||
117 | binding.binder.unbind = function(){}; | ||
118 | spyOn(binding.binder, 'unbind'); | ||
119 | binding.unbind(); | ||
120 | expect(binding.binder.unbind).toHaveBeenCalled(); | ||
121 | }); | ||
122 | }); | ||
123 | }); | ||
124 | |||
73 | describe('set()', function() { | 125 | describe('set()', function() { |
74 | it('performs the binding routine with the supplied value', function() { | 126 | it('performs the binding routine with the supplied value', function() { |
75 | spyOn(binding.binder, 'routine'); | 127 | spyOn(binding.binder, 'routine'); | ... | ... |
... | @@ -69,10 +69,11 @@ class Rivets.Binding | ... | @@ -69,10 +69,11 @@ class Rivets.Binding |
69 | # routines will also listen for changes on the element to propagate them back | 69 | # routines will also listen for changes on the element to propagate them back |
70 | # to the model. | 70 | # to the model. |
71 | bind: => | 71 | bind: => |
72 | @binder.bind?.call @, @el | ||
73 | |||
72 | if @options.bypass | 74 | if @options.bypass |
73 | @sync() | 75 | @sync() |
74 | else | 76 | else |
75 | @binder.bind?.call @, @el | ||
76 | Rivets.config.adapter.subscribe @model, @keypath, @sync | 77 | Rivets.config.adapter.subscribe @model, @keypath, @sync |
77 | @sync() if Rivets.config.preloadData | 78 | @sync() if Rivets.config.preloadData |
78 | 79 | ||
... | @@ -90,8 +91,9 @@ class Rivets.Binding | ... | @@ -90,8 +91,9 @@ class Rivets.Binding |
90 | 91 | ||
91 | # Unsubscribes from the model and the element. | 92 | # Unsubscribes from the model and the element. |
92 | unbind: => | 93 | unbind: => |
94 | @binder.unbind?.call @, @el | ||
95 | |||
93 | unless @options.bypass | 96 | unless @options.bypass |
94 | @binder.unbind?.call @, @el | ||
95 | Rivets.config.adapter.unsubscribe @model, @keypath, @sync | 97 | Rivets.config.adapter.unsubscribe @model, @keypath, @sync |
96 | 98 | ||
97 | if @options.dependencies?.length | 99 | if @options.dependencies?.length | ... | ... |
-
Please register or sign in to post a comment