Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Dev
subdomain hook for Catalyst::Test
 

Index | Next | Previous | View Flat


jgottshall at capwiz

Sep 17, 2008, 3:12 PM


Views: 2482
Permalink
subdomain hook for Catalyst::Test

Our app allows for virtual subdomains that (among other things) enable
specific behaviors in the app.

For example,
http://www.myapp.com/foo/bar
and
http://magic.myapp.com/foo/bar
both point to same app, but the latter has "magic" behaviors associated
with it.

The problem is that we're having trouble writing tests against specific
behaviors in our controller tests, particularly when we want to test
several different subdomains within the same script.

My current solution is to set an environment variable in the test script
specifing the desired subdomain. I've added hooks to the app that will
use this value if available, so that controller tests using a "local"
instance of the app instantiated with Catalyst::Test and a faked request
will Just Work. But we run into trouble when we try to run the tests
against a "remote" server by setting CATALYST_SERVER. The env var
setting embedded in the script obviously is not visible to the server
instance that's running remotely.

In order to remedy this problem, I've patched Catalyst::Test to look for
my new env var and prepend it to the CATALYST_SERVER host component. It
works great! But I'm wondering whether this patch is worthy of adding to
the core, or if there's a different way I should be approaching the
problem. Here's a diff against 5.70/trunk:

Index: lib/Catalyst/Test.pm
===================================================================
--- lib/Catalyst/Test.pm (revision 8432)
+++ lib/Catalyst/Test.pm (working copy)
@@ -148,6 +148,10 @@
my $request = Catalyst::Utils::request( shift(@_) );
my $server = URI->new( $ENV{CATALYST_SERVER} );

+ if ( $ENV{CATALYST_SUBDOMAIN} ) {
+ $server->host("$ENV{CATALYST_SUBDOMAIN}." . $server->host);
+ }
+
if ( $server->path =~ m|^(.+)?/$| ) {
my $path = $1;
$server->path("$path") if $path; # need to be quoted

If this approach makes sense, I'll add documentation to the patch, of
course. I may need a little help coming up with a working test, though.

Thoughts, anyone? Thanks,
Jason



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev[at]lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev

Subject User Time
subdomain hook for Catalyst::Test jgottshall at capwiz Sep 17, 2008, 3:12 PM
    Re: subdomain hook for Catalyst::Test pm at flodhest Sep 26, 2008, 4:24 PM
    Re: subdomain hook for Catalyst::Test dbix-class at trout Sep 28, 2008, 6:17 AM
        Re: subdomain hook for Catalyst::Test jgottshall at capwiz Sep 30, 2008, 8:25 AM
            Re: subdomain hook for Catalyst::Test jgottshall at capwiz Sep 30, 2008, 12:00 PM
                Re: subdomain hook for Catalyst::Test dbix-class at trout Sep 30, 2008, 6:08 PM
                    Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 1, 2008, 2:02 PM
                        Re: subdomain hook for Catalyst::Test dbix-class at trout Oct 1, 2008, 5:37 PM
            Re: subdomain hook for Catalyst::Test dbix-class at trout Sep 30, 2008, 6:12 PM
                Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 3, 2008, 10:33 AM
                    Re: subdomain hook for Catalyst::Test dbix-class at trout Oct 5, 2008, 3:20 AM
                        Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 7, 2008, 6:47 AM
                Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 7, 2008, 7:07 AM
                    Re: subdomain hook for Catalyst::Test dbix-class at trout Oct 8, 2008, 4:18 AM
                        Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 8, 2008, 9:03 AM
                            Re: subdomain hook for Catalyst::Test apv at sedition Oct 8, 2008, 9:40 AM
                                Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 8, 2008, 10:06 AM
                                    Re: subdomain hook for Catalyst::Test apv at sedition Oct 8, 2008, 10:22 AM
                                        Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 8, 2008, 10:38 AM
                                            Re: subdomain hook for Catalyst::Test apv at sedition Oct 8, 2008, 11:40 AM
                                                Re: subdomain hook for Catalyst::Test jgottshall at capwiz Oct 9, 2008, 9:23 AM
                                                    Re: subdomain hook for Catalyst::Test bobtfish at bobtfish Oct 9, 2008, 4:04 PM
    Re: subdomain hook for Catalyst::Test jgottshall at capwiz Sep 29, 2008, 1:32 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.