Skip to content

Instantly share code, notes, and snippets.

@bellaire
Created February 3, 2011 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellaire/809518 to your computer and use it in GitHub Desktop.
Save bellaire/809518 to your computer and use it in GitHub Desktop.
trying to determine correct url_for behavior
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More 'no_plan';
use Test::Mojo;
# Load Mojolicious::Lite via ojo
use ojo;
# Set a base URL. All generated URLs should be
# relative to this path.
app->hook( before_dispatch => sub {
shift->req->url->base(Mojo::URL->new(q{http://kraih.com/sandbox}));
});
# Test helpers
# "Bender, damage report.
# The auxiliary power's out, and they spilled my cocktail."
# Get /
get '/' => 'root';
get '/another-place' => 'another-place';
get '/to-myself' => 'to-myself';
my $t = Test::Mojo->new;
$t->get_ok('/another-place')->content_is(join q{},
"http://kraih.com/sandbox/to-myself\n",
"/sandbox/to-myself\n",
"/sandbox/to-myself\n",
);
$t->get_ok('/to-myself')->content_is(join q{},
"http://kraih.com/sandbox/to-myself\n",
"/sandbox/to-myself\n",
"/sandbox/to-myself\n",
);
# GET /
# use to_string, just changing the arguments.
## Note: This is the current behavior of 28b90c
$t->get_ok('/')->content_is(join q{},
"/sandbox/\n",
"\n",
"/sandbox/\n",
"/sandbox/\n",
);
__DATA__
@@ another-place.html.ep
<% my $string_url = $self->url_for('to-myself'); =%>
<%= $string_url->to_abs() %>
<%= $string_url->to_rel() %>
<%= $string_url->to_string() %>
@@ to-myself.html.ep
<% my $string_url = $self->url_for('to-myself'); =%>
<%= $string_url->to_abs() %>
<%= $string_url->to_rel() %>
<%= $string_url->to_string() %>
@@ root.html.ep
<%= url_for() %>
<%= url_for '/' %>
<%= url_for '' %>
<%= url_for 'root' %>
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment