I'm not completely following the action class thing, but the way that
seems most logical to me is to write a plugin C::P::EmailTestable that
subclasses C::P::Email

sub email {

if (my $location = $c->config->{test_email}) {
  # write a temporary file into $location, and put the filename on the stash
  # so the view can link to it
  .
  .
   } else {
      # just defer to C::P::Email
      $self->super(@_);
  }
}

... but I'm thinking, how can one plugin inherit from another? $self
isn't passed ...

not that it's a problem. There are bunch of other ways to do it. Maybe
just a simple helper method somewhere that does the same.

D


On 12/16/06, Jonathan Rockway <[EMAIL PROTECTED]> wrote:
On Saturday 16 December 2006 03:08, Sébastien Wagener wrote:
> On Sat, 2006-12-16 at 07:45 +0100, Daniel McBrearty wrote:
> > if you have an action that sends an email, how do you write tests for it?
> >
> > perhaps print the email to a temp file in test mode? what do you guys do?
>
> I am currently considering writing tests for my e-mails too.
> You could set __PACKAGE__->config->{email} to "Test" if some env
> variable is set, and dump Email::Send::Test->emails to a file in an end
> action. Or you could provide a testing action to display (and clear) the
> sent e-mails.
> I have a similar problem with the values of my captchas.
> Btw.: Are there any best practices to hide an action unless in testing
> mode? Protect it by an ACL rule if an environment variable is set?

I'm not aware of anything that does this now (but I don't look at the ACL
stuff very often), but you could implement this as an ActionClass:

    package MyApp::Action::Testing;
    use base 'Catalyst::Action';
    sub execute {
        my $self = shift;
        die "You can't use this action!" unless $ENV{MYAPP_TESTING};
        return $self->NEXT::execute( @_ );
    }
    1;

then

    package MyApp::Controller::Whatever;
    # ...
    sub foo : Local : ActionClass('Testing') {
       $c->response->body('All tests successful.');
   }

Completely untested, but it should work.  Assuming this is useful, I'll CPAN
it.

--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;


_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/






--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to