Permalink
Browse files

fixed bug in validation toggling feature - github-issue-16

  • Loading branch information...
1 parent 3f421be commit bff9f9bc633628cea98e241a06666548fe97ba80 Al Newkirk committed Jun 7, 2012
Showing with 55 additions and 6 deletions.
  1. +3 −0 CHANGES
  2. +1 −1 Makefile.PL
  3. +1 −1 README
  4. +1 −1 README.mkdn
  5. +1 −1 dist.ini
  6. +6 −2 lib/Validation/Class/Prototype.pm
  7. +42 −0 t/90-rand-bugfixes.t
View
3 CHANGES
@@ -4,6 +4,9 @@ TODO (0000-00-00)
? raise_error flag allows profiles to track class usage and raise errors
? mixin fields across namespaces
+7.40 (2012-06-06)
+ * fixed bug in validation toggling feature - github-issue-16
+
7.39 (2012-06-03)
* fixed major bug in custom validation evaluation
View
2 Makefile.PL
@@ -26,7 +26,7 @@ my %WriteMakefileArgs = (
"Module::Find" => 0,
"utf8" => 0
},
- "VERSION" => "7.39",
+ "VERSION" => "7.40",
"test" => {
"TESTS" => "t/*.t t/regression/*.t t/regression/filters/*.t t/regression/validators/*.t"
}
View
2 README
@@ -3,7 +3,7 @@ NAME
Framework
VERSION
- version 7.39
+ version 7.40
SYNOPSIS
package MyVal::User;
View
2 README.mkdn
@@ -4,7 +4,7 @@ Validation::Class - Self-Validating Object System and Data Validation Framework
# VERSION
-version 7.39
+version 7.40
# SYNOPSIS
View
2 dist.ini
@@ -4,7 +4,7 @@ author = Al Newkirk <anewkirk@ana.io>
license = Perl_5
copyright_holder = Al Newkirk
copyright_year = 2011
-version = 7.39
+version = 7.40
[MetaResources]
homepage = https://github.com/alnewkirk/Validation-Class
View
8 lib/Validation/Class/Prototype.pm
@@ -3593,9 +3593,13 @@ sub validate {
if ($switch) {
- # set fields toggle directive
+ # set field toggle directive
+
$field =~ s/^[\-\+]{1}//;
- $self->fields->{$field}->{':toggle'} = $switch;
+
+ $self->fields->{$field}->{':toggle'} = $switch
+ if $self->fields->has($field);
+
}
}
View
42 t/90-rand-bugfixes.t
@@ -0,0 +1,42 @@
+BEGIN {
+
+ use FindBin;
+ use lib $FindBin::Bin . "/lib";
+
+}
+
+use utf8;
+use Test::More;
+
+{
+
+ # github issue 16
+ # https://github.com/alnewkirk/Validation-Class/issues/16
+
+ package TestClass::GithubIssue16;
+ use Validation::Class;
+
+ fld name => {
+ required => 1
+ };
+
+ package main;
+
+ my $class = "TestClass::GithubIssue16";
+ my $self = $class->new(ignore_unknown => 1, report_unknown => 1);
+
+ ok $class eq ref $self, "$class instantiated";
+
+ ok ! $self->validate('+name'), 'name exists and is invalid';
+ ok ! $self->validate('+abcd'), 'abcd does not exist and is invalid';
+
+ $self->ignore_unknown(0);
+ $self->report_unknown(0);
+
+ eval { $self->validate('+abcd') };
+
+ ok $@, 'abcd does not exist and terminates';
+
+}
+
+done_testing;

0 comments on commit bff9f9b

Please sign in to comment.