var andro = require('../andro').andro;

var eventer = null;
var bound = {};
beforeEach(function () {
  var obj = {};

  eventer = andro.eventer(obj);

  bound = {};
});

describe('eventer', function(){

  it('should trigger a bound callback when event emitted', function(){
    var called = false;
    eventer.bind(bound, "event", function() {
      called = true;
    });

    eventer.emit("event");
    expect(called).toEqual(true);
  });

  it('should call callback with bound obj as context', function(){
    var contextData = null;
    bound.woo = "yeah";
    eventer.bind(bound, "event", function() {
      contextData = this.woo;
    });

    eventer.emit("event");
    expect(contextData).toEqual("yeah");
  });


  it('should send on emitted data to callback', function(){
    var collectedData = null;
    eventer.bind(bound, "event", function(data) {
      collectedData = data;
    });

    eventer.emit("event", "data");
    expect(collectedData).toEqual("data");
  });

  it('should not call callback bound to different event from one emitted', function(){
    var called = false;
    eventer.bind(bound, "event", function() {
      called = true;
    });

    eventer.emit("otherevent");
    expect(called).toEqual(false);
  });

  it('should not call callback previously bound to emitted event', function(){
    var called = 0;
    eventer.bind(bound, "event", function() {
      called++;
    });

    // callback fired the first time
    eventer.emit("event");
    expect(called).toEqual(1);

    // but should not be after unbind
    eventer.unbind(bound, "event");
    eventer.emit("event");
    expect(called).toEqual(1);
  });
});

@@ -1641,13 +1641,842 @@
 );%0A  %7D);
+%0A%0A  describe('regressions', function() %7B%0A    it('should unbind callback for passed event, not all events obj bound to', function()%7B%0A      var event1Called = 0;%0A      eventer.bind(bound, %22event1%22, function() %7B%0A        event1Called++;%0A      %7D);%0A%0A      var event2Called = 0;%0A      eventer.bind(bound, %22event2%22, function() %7B%0A        event2Called++;%0A      %7D);%0A%0A      // callbacks fired the first time%0A      eventer.emit(%22event1%22);%0A      expect(event1Called).toEqual(1);%0A      eventer.emit(%22event2%22);%0A      expect(event2Called).toEqual(1);%0A%0A      // event1 should not be after unbind%0A      eventer.unbind(bound, %22event1%22);%0A      eventer.emit(%22event1%22);%0A      expect(event1Called).toEqual(1);%0A%0A      // event2 should still be called after event1 unbound%0A      eventer.emit(%22event2%22);%0A      expect(event2Called).toEqual(2);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

Add regression test for accidental unbind all bug