[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1199] trunk



Revision: 1199
          http://svn.sourceforge.net/ledger-smb/?rev=1199&view=rev
Author:   tetragon
Date:     2007-05-15 16:15:14 -0700 (Tue, 15 May 2007)

Log Message:
-----------
Fixes for merge and more tests

Modified Paths:
--------------
    trunk/LedgerSMB.pm
    trunk/t/11-ledgersmb.t

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2007-05-15 21:41:26 UTC (rev 1198)
+++ trunk/LedgerSMB.pm	2007-05-15 23:15:14 UTC (rev 1199)
@@ -581,7 +581,8 @@
     if ( !scalar @keys ) {
         @keys = keys %{$src};
     }
-    for my $arg ( keys %$src ) {
+    #for my $arg ( keys %$src ) {
+    for my $arg ( @keys ) {
         my $dst_arg;
         if ($index) {
             $dst_arg = $arg . "_$index";

Modified: trunk/t/11-ledgersmb.t
===================================================================
--- trunk/t/11-ledgersmb.t	2007-05-15 21:41:26 UTC (rev 1198)
+++ trunk/t/11-ledgersmb.t	2007-05-15 23:15:14 UTC (rev 1199)
@@ -10,6 +10,7 @@
 use Test::Trap qw(trap $trap);
 use Math::BigFloat;
 
+use LedgerSMB::Sysconfig;
 use LedgerSMB;
 
 sub redirect {
@@ -197,3 +198,54 @@
 is($trap->stdout, "redirected\n", 'redirect: callback, no message redirect');
 @r = trap{$lsmb->redirect('msg' => "hello world\n")};
 is($trap->stdout, "redirected\n", 'redirect: callback and message redirect');
+
+# $lsmb->call_procedure checks
+$lsmb = new LedgerSMB;
+$lsmb->{dbh} = ${LedgerSMB::Sysconfig::GLOBALDBH};
..hidden.. = $lsmb->call_procedure('procname' => 'character_length', 
+	'args' => ['month']);
+is($#r, 0, 'call_procedure: correct return length (one row)');
+is($r[0]->{'character_length'}, 5, 
+	'call_procedure: single arg, non-numeric return');
+
..hidden.. = $lsmb->call_procedure('procname' => 'trunc', 'args' => [57.1, 0]);
+is($r[0]->{'trunc'}, Math::BigFloat->new('57'), 
+	'call_procedure: two args, numeric return');
+
..hidden.. = $lsmb->call_procedure('procname' => 'pi', 'args' => []);
+like($r[0]->{'pi'}, qr/^3.14/, 
+	'call_procedure: empty arg list, non-numeric return');
+
+# These tests are ugly and shouldn't work
..hidden.. = $lsmb->call_procedure(
+	'procname' => 'power(2, 2) UNION ALL SELECT * FROM pi', 
+	'args' => [], 'order_by' => 'power DESC');
+is($#r, 1, 'call_procedure: correct return length (two rows)');
+is($r[0]->{'power'}, 4, 'call_procedure: DESC ordering');
..hidden.. = $lsmb->call_procedure(
+	'procname' => 'power(2, 2) UNION ALL SELECT * FROM pi', 
+	'args' => [], 'order_by' => 'power ASC');
+is($r[1]->{'power'}, 4, 'call_procedure: ASC ordering');
+
+##
+##TODO: {
+##	local $TODO = 'Breaks when no arglist given';
+##	@r = $lsmb->call_procedure('procname' => 'pi');
+##	like($r[0]->{'pi'}, qr/^3.14/, 
+##		'call_procedure: no args, non-numeric return');
+##}
+
+# $lsmb->merge checks
+$lsmb = new LedgerSMB;
+$lsmb->merge({'apple' => 1, 'pear' => 2, 'peach' => 3}, 'keys' => ['apple', 'pear']);
+ok(!defined $lsmb->{peach}, 'merge: Did not add unselected key');
+is($lsmb->{apple}, 1, 'merge: Added unselected key apple');
+is($lsmb->{pear}, 2, 'merge: Added unselected key pear');
+like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: left existing key');
+
+$lsmb = new LedgerSMB;
+$lsmb->merge({'apple' => 1, 'pear' => 2, 'peach' => 3});
+is($lsmb->{apple}, 1, 'merge: No key, added apple');
+is($lsmb->{pear}, 2, 'merge: No key, added pear');
+is($lsmb->{peach}, 3, 'merge: No key, added peach');
+like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: No key, left existing key');


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.