a7963f51 by Michael Richards

Merge branch 'issue-85'

2 parents e0a4fdc8 6c26680c
......@@ -29,6 +29,17 @@ describe('Rivets.Binding', function() {
expect(rivets.config.adapter.subscribe).toHaveBeenCalledWith(model, 'name', binding.sync);
});
it("calls the binder's bind method if one exists", function() {
expect(function(){
binding.bind();
}).not.toThrow(new Error());
binding.binder.bind = function(){};
spyOn(binding.binder, 'bind');
binding.bind();
expect(binding.binder.bind).toHaveBeenCalled();
});
describe('with preloadData set to true', function() {
beforeEach(function() {
rivets.config.preloadData = true;
......@@ -54,6 +65,17 @@ describe('Rivets.Binding', function() {
binding.bind();
expect(binding.set).toHaveBeenCalledWith('espresso');
});
it("calls the binder's bind method if one exists", function() {
expect(function(){
binding.bind();
}).not.toThrow(new Error());
binding.binder.bind = function(){};
spyOn(binding.binder, 'bind');
binding.bind();
expect(binding.binder.bind).toHaveBeenCalled();
});
});
describe('with dependencies', function() {
......@@ -70,6 +92,36 @@ describe('Rivets.Binding', function() {
});
});
describe('unbind()', function() {
it("calls the binder's unbind method if one exists", function() {
expect(function(){
binding.unbind();
}).not.toThrow(new Error());
binding.binder.unbind = function(){};
spyOn(binding.binder, 'unbind');
binding.unbind();
expect(binding.binder.unbind).toHaveBeenCalled();
});
describe('with the bypass option set to true', function() {
beforeEach(function() {
binding.options.bypass = true;
});
it("calls the binder's unbind method if one exists", function() {
expect(function(){
binding.unbind();
}).not.toThrow(new Error());
binding.binder.unbind = function(){};
spyOn(binding.binder, 'unbind');
binding.unbind();
expect(binding.binder.unbind).toHaveBeenCalled();
});
});
});
describe('set()', function() {
it('performs the binding routine with the supplied value', function() {
spyOn(binding.binder, 'routine');
......
......@@ -69,10 +69,11 @@ class Rivets.Binding
# routines will also listen for changes on the element to propagate them back
# to the model.
bind: =>
@binder.bind?.call @, @el
if @options.bypass
@sync()
else
@binder.bind?.call @, @el
Rivets.config.adapter.subscribe @model, @keypath, @sync
@sync() if Rivets.config.preloadData
......@@ -90,8 +91,9 @@ class Rivets.Binding
# Unsubscribes from the model and the element.
unbind: =>
@binder.unbind?.call @, @el
unless @options.bypass
@binder.unbind?.call @, @el
Rivets.config.adapter.unsubscribe @model, @keypath, @sync
if @options.dependencies?.length
......