Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Use warn instead of error, when no profile set

 * Added message bundle test

git-svn-id: http://svn.unknownplace.org/public/library/perl/trunk/Catalyst-Plugin-FormValidator-Simple-Auto@406 325430d6-99fa-0310-bb67-a757393f56df
  • Loading branch information...
commit f33a210b0fec54efd50b75331c0c9440c5e92e3e 1 parent 33cfc9a
typester authored
18 META.yml
View
@@ -1,18 +0,0 @@
-abstract: Smart validation with FormValidator::Simple
-author: Daisuke Murase <typester@cpan.org>
-build_requires:
- Test::More: 0
-distribution_type: module
-generated_by: Module::Install version 0.64
-license: perl
-name: Catalyst-Plugin-FormValidator-Simple-Auto
-no_index:
- directory:
- - inc
- - t
-requires:
- Catalyst: 5.30
- Catalyst::Plugin::FormValidator::Simple: 0
- UNIVERSAL::isa: 0
- YAML: 0
-version: 0.09_01
5 lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
View
@@ -104,11 +104,10 @@ sub setup {
__PACKAGE__ . qq/: You need to load "Catalyst::Plugin::FormValidator::Simple"/ )
unless $c->isa('Catalyst::Plugin::FormValidator::Simple');
- Catalyst::Exception->throw(
- message => __PACKAGE__ . qq/: You must set validator profiles/ )
+ $c->log->warn( __PACKAGE__ . qq/: You must set validator profiles/ )
unless $config->{profiles};
- if ( ref $config->{profiles} ne 'HASH' ) {
+ if ( $config->{profiles} and ref $config->{profiles} ne 'HASH' ) {
my $profiles = eval {
YAML::LoadFile( $config->{profiles} );
};
94 t/04_bundle_message.t
View
@@ -0,0 +1,94 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+{
+ package TestApp;
+
+ use Catalyst qw/
+ FormValidator::Simple
+ FormValidator::Simple::Auto
+ /;
+
+ __PACKAGE__->config(
+ name => 'TestApp',
+ validator => {
+ profiles => {
+ action1 => {
+ param1 => [
+ { rule => 'NOT_BLANK', message => 'NOT_BLANK!!!' },
+ { rule => 'ASCII', message => 'ASCII!!!' },
+ ],
+ },
+ action2_submit => { param1 => [ 'NOT_BLANK', 'ASCII' ], },
+ },
+ },
+ );
+ __PACKAGE__->setup;
+
+ sub action1 : Global {
+ my ( $self, $c ) = @_;
+
+ if ($c->form->has_error) {
+ $c->res->body( $c->form->message->get( $c->validator_profile, 'param1', $c->form->error('param1') ) );
+ }
+ else {
+ $c->res->body('no errors');
+ }
+ }
+
+ sub action2 : Global {
+ my ( $self, $c ) = @_;
+
+ if ($c->req->method eq 'POST') {
+ $c->forward('action2_submit');
+ }
+ else {
+ $c->res->body('no $c->form executed');
+ }
+ }
+
+ sub action2_submit : Private {
+ my ( $self, $c ) = @_;
+
+ if ($c->form->has_error) {
+ $c->res->body( $c->form->error('param1') );
+ }
+ else {
+ $c->res->body('no errors');
+ }
+ }
+}
+
+use Catalyst::Test 'TestApp';
+use Test::Base;
+
+plan tests => 14;
+
+use HTTP::Request::Common;
+
+# action driven validation
+ok( my $res = request('/action1'), 'request ok' );
+is( $res->content, 'NOT_BLANK!!!', 'is NOT_BLANK error');
+
+ok( $res = request('/action1?param1=aaa bbb'), 'request ok' );
+is( $res->content, 'ASCII!!!', 'is ASCII error');
+
+ok( $res = request('/action1?param1=aaa'), 'request ok' );
+is( $res->content, 'no errors', 'is no errors');
+
+
+# forward driven validation
+ok( $res = request(POST '/action2', [ param1 => '' ]), 'request ok' );
+is( $res->content, 'NOT_BLANK', 'is NOT_BLANK error');
+
+ok( $res = request(POST '/action2', [ param1 => 'aaa bbb' ]), 'request ok' );
+is( $res->content, 'ASCII', 'is ASCII error');
+
+ok( $res = request(POST '/action2', [ param1 => 'ab' ]), 'request ok' );
+is( $res->content, 'no errors', 'is no errors');
+
+ok( $res = request('/action2'), 'request ok' );
+is( $res->content, 'no $c->form executed', 'is no $c->form executed');
+
Please sign in to comment.
Something went wrong with that request. Please try again.