Permalink
Browse files

Fixed issue with __super__. Covered with specs.

  • Loading branch information...
1 parent 9ee7217 commit e2b6b13478f7c5a09724762229459c69df3ac0e8 @umate committed Mar 21, 2013
Showing with 36 additions and 1 deletion.
  1. +1 −1 src/spine.coffee
  2. +35 −0 test/specs/controller.js
View
@@ -417,7 +417,7 @@ class Controller extends Module
@events = @constructor.events unless @events
@elements = @constructor.elements unless @elements
- if parent_prototype = @constructor.prototype.__proto__
+ if parent_prototype = @constructor.__super__
@events = $.extend({}, parent_prototype.events, @events) if parent_prototype.events
@elements = $.extend({}, parent_prototype.elements, @elements) if parent_prototype.elements
View
@@ -90,4 +90,39 @@ describe("Controller", function(){
var users = new Users();
expect(users.el.attr("style")).toEqual("width: 100%");
});
+
+ describe("inheritance", function() {
+ beforeEach(function() {
+ element = $('<div/>').html('<div class="parent"></div><div class="child"></div>');
+ Users.include({
+ events: {"click .parent": "parentEventHandler"},
+ elements: {".parent": "el1"},
+ parentEventHandler: function() {}
+ });
+
+ ChildUser = Users.sub({
+ el: element,
+ events: {"click .child": "childEventHandler"},
+ elements: {".child": "el2"},
+ childEventHandler: function() {}
+ });
+
+ childUser = new ChildUser();
+ });
+
+ it("should inherit elements from parent controller", function(){
+ expect(childUser.el1).toBeDefined();
+ expect(childUser.el2).toBeDefined();
+ });
+
+ it("should inherit events from parent controller", function(){
+ spyOn(childUser, 'parentEventHandler');
+ spyOn(childUser, 'childEventHandler');
+ childUser.el.find('.parent').click();
+ childUser.el.find('.child').click();
+
+ expect(childUser.parentEventHandler).toHaveBeenCalled();
+ expect(childUser.childEventHandler).toHaveBeenCalled();
+ });
+ });
});

0 comments on commit e2b6b13

Please sign in to comment.