[Rt-commit] rt branch, 4.2/lock-config-options-in-tests, created. rt-4.1.6-346-gc75abc7

Ruslan Zakirov ruz at bestpractical.com
Thu Mar 14 13:52:47 EDT 2013


The branch, 4.2/lock-config-options-in-tests has been created
        at  c75abc7fd740f8c31e45462edbb87e35d73a96bd (commit)

- Log -----------------------------------------------------------------
commit a35c33de0dc25da6e81c39db5d1f4608d19cde11
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Tue Jan 17 19:08:16 2012 +0400

    use Hash::Util::lock_keys to make sure we don't have typos
    
    Lock most hashes related to config during testing
    to avoid typos when we access config.
    
    Primary config defines all defaults and thus sets all possible
    hash keys, so we can lock hashes and all typos should result
    in exceptions.

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 6675137..7d4cd33 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -996,6 +996,35 @@ sub PostLoadCheck {
     }
 }
 
+=head2 LockSetOfOptions
+
+Locks option names and sub options in HASH options, so accessing
+or setting option that was defined before this call is fatal error.
+This is only enabled in RT's core tests, but not in production
+environment. This may change in future.
+
+=cut
+
+sub LockSetOfOptions {
+    my $self = shift;
+    my $ref = shift;
+
+    my $nest = 0;
+    unless ($ref) {
+        $ref = \%OPTIONS;
+        $OPTIONS{$_} = undef foreach grep !exists $OPTIONS{$_}, keys %META;
+        $nest = 1;
+    }
+
+    require Hash::Util;
+    Hash::Util::lock_ref_keys( $ref );
+    # don't nest more then two levels, so we lock OptionName and if it's a hash
+    # option then we lock first level
+    if ( $nest ) {
+        $self->LockSetOfOptions( $_ ) foreach grep ref($_) eq 'HASH', values %$ref;
+    }
+}
+
 =head2 Configs
 
 Returns list of config files found in local etc, plugins' etc
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 99b996b..d749d11 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -181,6 +181,8 @@ sub import {
     mkpath [ $RT::MasonSessionDir ]
         if RT->Config->Get('DatabaseType');
 
+    RT->Config->LockSetOfOptions;
+
     my $level = 1;
     while ( my ($package) = caller($level-1) ) {
         last unless $package =~ /Test/;

commit c75abc7fd740f8c31e45462edbb87e35d73a96bd
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Mar 14 21:49:13 2013 +0400

    add default value for option to avoid test failures
    
    in tests we lock options so every option we use should
    be in %META or have a default set from RT's core config

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index d3fd15a..90d85e6 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -336,6 +336,7 @@ setting enabled.
 =cut
 
 # Set($EmailSubjectTagRegex, qr/\Q$rtname\E/i );
+Set($EmailSubjectTagRegex, undef );
 
 =item C<$OwnerEmail>
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list