Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/1082' into v1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
samccone committed Apr 1, 2014
2 parents 0eb816f + ac05712 commit a20d296
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
32 changes: 21 additions & 11 deletions spec/javascripts/behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ describe("Behaviors", function(){
});

describe("behavior events", function() {
var V, Obj, spy, spy2;
var V, Obj, spy, spy2, viewSpy;

beforeEach(function() {
spy = sinon.spy();
spy2 = sinon.spy();
spy3 = sinon.spy();
viewSpy = sinon.spy();

Obj = {
ToolTip: Marionette.Behavior.extend({
Expand All @@ -149,6 +150,9 @@ describe("Behaviors", function(){

V = Marionette.ItemView.extend({
template: _.template(""),
events: {
"click": viewSpy
},
behaviors: {
ToolTip: {},
DropDown: {},
Expand All @@ -157,23 +161,29 @@ describe("Behaviors", function(){
});

Marionette.Behaviors.behaviorsLookup = Obj;
});

it("should call the behaviors event", function() {
v = new V();
v.render();
v.$el.click();
});

expect(spy).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior));
expect(spy2).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior));
it("should call first behaviors event", function() {
expect(spy).toHaveBeenCalledOnce();
expect(spy).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior))
});

it("should call the behaviors event when event handler is a string", function() {
v = new V();
v.render();
v.$el.click();
it("should call second behaviors event", function() {
expect(spy2).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior))
expect(spy2).toHaveBeenCalledOnce();
});

it("should call third behaviors event", function() {
expect(spy3).toHaveBeenCalledOnce();
expect(spy3).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.Behavior))
});

expect(spy3).toHaveBeenCalled(sinon.match.instanceOf(Marionette.Behavior));
it("should call the view click handler", function() {
expect(viewSpy).toHaveBeenCalledOnce();
expect(viewSpy).toHaveBeenCalledOn(sinon.match.instanceOf(Marionette.View))
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/marionette.behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Marionette.Behaviors = (function(Marionette, _) {
_.each(_.keys(behaviorEvents), function(key) {
// append white-space at the end of each key to prevent behavior key collisions
// this is relying on the fact backbone events considers "click .foo" the same "click .foo "
var whitespace = (new Array(i+1)).join(" ");
// starts with an array of two so the first behavior has one space
var whitespace = (new Array(i+2)).join(" ");
var eventKey = key + whitespace;
var handler = _.isFunction(behaviorEvents[key]) ? behaviorEvents[key] : b[behaviorEvents[key]];

Expand Down

0 comments on commit a20d296

Please sign in to comment.