From 348dc948fffc19ee4f44859eaa93b768620c36f1 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Fri, 26 Apr 2013 15:13:26 +0200 Subject: Builder: fix join of pre_ops and post_ops arrays https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/src/freeipa/_base/Builder.js | 4 +- install/ui/src/freeipa/_base/Construct_registry.js | 4 +- install/ui/test/build_tests.html | 2 + install/ui/test/build_tests.js | 102 ++++++++++++++++++++- 4 files changed, 107 insertions(+), 5 deletions(-) (limited to 'install/ui') diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index cddadb9f1..d14721018 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -220,8 +220,8 @@ define(['dojo/_base/declare', cs.pre_ops = cs.pre_ops || []; cs.post_ops = cs.post_ops || []; - if (pre) cs.pre_ops.push.call(cs.pre_ops, pre); - if (post) cs.post_ops.push.call(cs.post_ops, post); + if (pre) cs.pre_ops.push.apply(cs.pre_ops, pre); + if (post) cs.post_ops.push.apply(cs.post_ops, post); } cs.spec = cs.spec || {}; diff --git a/install/ui/src/freeipa/_base/Construct_registry.js b/install/ui/src/freeipa/_base/Construct_registry.js index bf423d5ab..d9489add3 100644 --- a/install/ui/src/freeipa/_base/Construct_registry.js +++ b/install/ui/src/freeipa/_base/Construct_registry.js @@ -102,8 +102,8 @@ define(['dojo/_base/declare', var cs = construct.clone(old_cs); cs.type = new_type; - if (def_cs.pre_ops) cs.pre_ops.push.call(cs.pre_ops, def_cs.pre_ops); - if (def_cs.post_ops) cs.post_ops.push.call(cs.post_ops, def_cs.post_ops); + if (def_cs.pre_ops) cs.pre_ops.push.apply(cs.pre_ops, def_cs.pre_ops); + if (def_cs.post_ops) cs.post_ops.push.apply(cs.post_ops, def_cs.post_ops); if (def_cs.factory) cs.factory = def_cs.factory; if (def_cs.ctor) cs.ctor = def_cs.ctor; if (def_cs.spec) { diff --git a/install/ui/test/build_tests.html b/install/ui/test/build_tests.html index 7b61a9ce5..d42148cd3 100644 --- a/install/ui/test/build_tests.html +++ b/install/ui/test/build_tests.html @@ -3,6 +3,8 @@ IPA utils test suite + + diff --git a/install/ui/test/build_tests.js b/install/ui/test/build_tests.js index 28af584e3..edd3d3f7e 100644 --- a/install/ui/test/build_tests.js +++ b/install/ui/test/build_tests.js @@ -21,11 +21,12 @@ define([ 'dojo/_base/declare', 'freeipa/_base/Builder', + 'freeipa/_base/Construct_registry', 'freeipa/_base/Spec_mod', 'freeipa/ipa', 'freeipa/spec_util' ], - function(declare, Builder, Spec_mod, IPA, su) { return function() { + function(declare, Builder, C_reg, Spec_mod, IPA, su) { return function() { module('build',{ @@ -159,6 +160,105 @@ test('Testing Spec_mod', function() { deepEqual(spec, { a: ['a1', 'new', 'a2', 'a3'] }, 'Add on position'); }); +test('Testing Construct registry', function() { + + var undefined; + + var cr = new C_reg(); + + // test simple ctor registration + var ctor = declare([], {}); + cr.register('ctor', ctor); + + var ctor_cs = cr.get('ctor'); + equals(ctor_cs.type, 'ctor', 'Ctor: Match type'); + equals(ctor_cs.ctor, ctor, 'Ctor: Match ctor'); + equals(ctor_cs.factory, undefined, 'Ctor: Match factory'); + equals(ctor_cs.pre_ops.length, 0, 'Ctor: No pre_ops'); + equals(ctor_cs.post_ops.length, 0, 'Ctor: No post_ops'); + + // test simple factory registration + var fac = function(){}; + cr.register('fac', fac); + + var fac_cs = cr.get('fac'); + equals(fac_cs.type, 'fac', 'Factory: Match type'); + equals(fac_cs.ctor, undefined, 'Factory: Match ctor'); + equals(fac_cs.factory, fac, 'Factory: Match factory'); + equals(fac_cs.pre_ops.length, 0, 'Factory: No pre_ops'); + equals(fac_cs.post_ops.length, 0, 'Factory: No post_ops'); + + + // test complex registration + + var spec = { name: 'spec' }; + + var cs = { + type: 'complex', + ctor: ctor, + factory: fac, // for next test + spec: spec + }; + cr.register(cs); + var complex_cs = cr.get('complex'); + equals(complex_cs.type, 'complex', 'Complex: Match type'); + equals(complex_cs.ctor, ctor, 'Complex: Match ctor'); + equals(complex_cs.factory, fac, 'Complex: Match factory'); + equals(complex_cs.pre_ops.length, 0, 'Complex: No pre_ops'); + equals(complex_cs.post_ops.length, 0, 'Complex: No post_ops'); + deepEqual(complex_cs.spec, spec, 'Complex: Match spec'); + + // copy: new cs based on existing + cr.copy('complex', 'copy', {}); // pure copy + var copy_cs = cr.get('copy'); + equals(copy_cs.type, 'copy', 'Copy: Match type'); + equals(copy_cs.ctor, ctor, 'Copy: Match ctor'); + equals(copy_cs.factory, fac, 'Copy: Match factory'); + equals(copy_cs.pre_ops.length, 0, 'Copy: No pre_ops'); + equals(copy_cs.post_ops.length, 0, 'Copy: No post_ops'); + deepEqual(copy_cs.spec, spec, 'Copy: Match spec'); + + // add post op and pre op to complex + var op1 = function() {}; + var op2 = function() {}; + var op3 = function() {}; + var op4 = function() {}; + + cr.register_pre_op('complex', op1); + cr.register_pre_op('complex', op2, true /* first*/); + deepEqual(complex_cs.pre_ops, [op2, op1], 'Adding pre_ops'); + + cr.register_post_op('complex', op3); + cr.register_post_op('complex', op4, true); + deepEqual(complex_cs.post_ops, [op4, op3], 'Adding post_ops'); + + + // copy: altered + var ctor2 = declare([], {}); + var fac2 = function() {}; + var op5 = function() {}; + var op6 = function() {}; + cr.copy('complex', 'copy2', { + ctor: ctor2, + factory: fac2, + spec: { + foo: 'bar' + }, + pre_ops: [op5], + post_ops: [op6] + }); + var a_copy_cs = cr.get('copy2'); + + equals(a_copy_cs.type, 'copy2', 'Altered copy: Match type'); + equals(a_copy_cs.ctor, ctor2, 'Altered copy: Match ctor'); + equals(a_copy_cs.factory, fac2, 'Altered copy: Match factory'); + deepEqual(a_copy_cs.spec, { + name: 'spec', + foo: 'bar' + }, 'Altered copy: Match spec'); + deepEqual(a_copy_cs.pre_ops, [op2, op1, op5], 'Altered copy: Match pre_ops'); + deepEqual(a_copy_cs.post_ops, [op4, op3, op6], 'Altered copy: Match post_ops'); +}); };}); \ No newline at end of file -- cgit