/* Authors: * Petr Vobornik * * Copyright (C) 2012 Red Hat * see file 'COPYING' for use and warranty information * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ var FOO = {}; //foo app module('framework',{ setup: function() { FOO.facet = function() { //this is a new class: facet var that = IFW.type('facet'); //define method init in facet class that._.method('init', function(spec) { that.foo = spec.foo || 'facet_foo'; that.baz = spec.baz || 'facet_baz'; that.bar = spec.bar || 'facet_bar'; this._.on('pre_with_events', this.preevent_handler, this); this._.on('post_with_events', this.postevent_handler, this); }); that._.method('with_events', function(first, second) { this.with_events_called = true; this.with_events_attrs = [first, second]; }, { pre_event: true, post_event: true }); that._.method('preevent_handler', function(first, second) { that.preevent_handler_called = true; this.preevent_handler_bound = true; this.preevent_handler_attrs = [first, second]; }); that._.method('postevent_handler', function(first, second) { that.postevent_handler_called = true; this.postevent_handler_bound = true; this.postevent_handler_attrs = [first, second]; }); return that; }; IFW.register('facet', FOO.facet); FOO.details_facet = function() { //new class details facet, inherits from FOO.facet var that = IFW.type('details_facet', FOO.facet); //define method init in details_facet class. //this overrides init method form facet class that._.method('init', function(spec) { that._.parent('init', spec); that.baz = spec.baz || 'details_baz'; }); return that; }; IFW.register('details_facet', FOO.details_facet); }, teardown: function() { IFW.register('facet'); IFW.register('details_facet'); } }); test("Build and inheritence" ,function() { var details_facet = IFW.build({ factory: FOO.details_facet, bar: 'custom_bar' }); same(details_facet._.klass, 'details_facet', "Class"); same(details_facet._.ancestor, 'facet', "Ancestor"); same(details_facet.foo, 'facet_foo', "Property - ancestor's default"); same(details_facet.baz, 'details_baz', "Property - child's default"); same(details_facet.bar, 'custom_bar', "Property - custom"); //test method calls and pre/post events var attrs = ["first", "second"]; details_facet.with_events(attrs[0], attrs[1]); ok(details_facet.with_events_called, "With events called."); same(details_facet.with_events_attrs, attrs, "With event called with good attrs"); ok(details_facet.preevent_handler_called, "Pre event called."); ok(details_facet.preevent_handler_bound, "Pre event correctly bounded."); same(details_facet.preevent_handler_attrs, attrs, "Pre event called with good attrs"); ok(details_facet.postevent_handler_called, "Post event called."); ok(details_facet.postevent_handler_bound, "Post event correctly bounded."); same(details_facet.postevent_handler_attrs, attrs, "Post event called with good attrs"); //calls });