Skip to content

Commit

Permalink
[WIP] Committing a bunch of code I wrote a while ago but never committed
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Aug 13, 2016
1 parent b32e7eb commit 72964cf
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
9 changes: 3 additions & 6 deletions lib/Galileo.pm
Expand Up @@ -146,13 +146,11 @@ sub startup {

$app->helper( schema => sub { shift->app->db } );

$app->helper( 'home_page' => sub{ '/page/home' } );

$app->helper( 'auth_fail' => sub {
my $self = shift;
my $message = shift || "Not Authorized";
$self->humane_flash( $message );
$self->redirect_to( $self->home_page );
$self->redirect_to( show_page => name => '' );
return 0;
});

Expand Down Expand Up @@ -186,8 +184,6 @@ sub startup {

my $r = $app->routes;

$r->any( '/' => sub { my $self = shift; $self->redirect_to( $self->home_page ) });
$r->any( '/page/:name' )->to('page#show')->name('show_page');
$r->post( '/login' )->to('user#login');
$r->any( '/logout' )->to('user#logout');

Expand All @@ -197,7 +193,6 @@ sub startup {
});

$if_author->any( '/admin/menu' )->to('menu#edit');
$if_author->any( '/page/:name/_edit' )->to('page#edit')->name('edit_page');
$if_author->websocket( '/store/page' )->to('page#store');
$if_author->websocket( '/store/menu' )->to('menu#store');
$if_author->websocket( '/files/list' )->to('file#list');
Expand All @@ -213,6 +208,8 @@ sub startup {
$if_admin->websocket( '/store/user' )->to('admin#store_user');
$if_admin->websocket( '/remove/page' )->to('admin#remove_page');

$if_author->any( '/*name/_edit' )->to('page#edit', name => 'home')->name('edit_page');
$r->any( '/*name' )->to('page#show', name => 'home')->name('show_page');
}

1;
Expand Down
1 change: 1 addition & 0 deletions lib/Galileo/Command/setup.pm
Expand Up @@ -92,6 +92,7 @@ sub run {
eval {
$dh->do_install;
$dh->inject_sample_data($user, $pw1, $full);
warn "got past inject";
};

if ($@) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Galileo/DB/Deploy.pm
Expand Up @@ -114,7 +114,7 @@ sub inject_sample_data {
<p>When he first turned the telescope to face Jupiter, he used modern technology to improve the world around him.</p>
<p>Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the <a href="/page/about">about</a> page.</p>
<p>Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the <a href="/about">about</a> page.</p>
<p><img src="/portrait.jpg" alt="Portrait of Galileo Galilei" title="" /></p>
HTML
Expand All @@ -125,7 +125,7 @@ HTML
When he first turned the telescope to face Jupiter, he used modern technology to improve the world around him.
Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the [about](/page/about) page.
Like the great scientist it is named for, Galileo CMS is not afraid to be very modern. Learn more about it on the [about](/about) page.
![Portrait of Galileo Galilei](/portrait.jpg)
MARKDOWN
Expand Down
2 changes: 1 addition & 1 deletion lib/Galileo/User.pm
Expand Up @@ -24,7 +24,7 @@ sub logout {
my $self = shift;
$self->session( expires => 1 );
$self->humane_flash( 'Goodbye' );
$self->redirect_to( $self->home_page );
$self->redirect_to( show_page => name => '' );
}

1;
Expand Down
2 changes: 1 addition & 1 deletion lib/Galileo/files/templates/nav_menu.html.ep
Expand Up @@ -10,7 +10,7 @@
% my $page = $rs->single({page_id => $id});
% next unless $page;
<li>
%= tag a => href => "/page/" . $page->name => begin
%= tag a => href => "/" . $page->name => begin
%= $page->title
% end
</li>
Expand Down
4 changes: 2 additions & 2 deletions lib/Galileo/files/templates/user_menu.html.ep
Expand Up @@ -20,7 +20,7 @@
%= modal 'page-modal' => begin
Create a page with link
<div class="input-prepend">
<span class="add-on">/page/</span>
<span class="add-on">/</span>
<input type="text" id="new-page-link" placeholder="new page link">
</div>
% end
Expand Down Expand Up @@ -48,7 +48,7 @@
show_modal( '#page-modal', function () {
var link = $('#new-page-link').val();
if (link.length > 0) {
window.location.href = '/page/' + link + '/_edit';
window.location.href = '/' + link + '/_edit';
} else {
humane.log('New link name cannot be empty');
}
Expand Down
18 changes: 9 additions & 9 deletions t/basic.t
Expand Up @@ -23,11 +23,11 @@ subtest 'Anonymous User' => sub {
->element_exists_not( '#user-menu' );

# attempt to get non-existant page
$t->get_ok('/page/doesntexist')
$t->get_ok('/doesntexist')
->status_is(404);

# attempt to edit page
$t->get_ok('/page/home/_edit')
$t->get_ok('/home/_edit')
->status_is(200)
->content_like( qr/Not Authorized/ );

Expand All @@ -46,21 +46,21 @@ subtest 'Anonymous User' => sub {
subtest 'Do Login' => sub {

# fail username
$t->post_ok( '/login' => form => {from => '/page/home', username => 'wronguser', password => 'pass' } )
$t->post_ok( '/login' => form => {from => '/home', username => 'wronguser', password => 'pass' } )
->status_is(200)
->content_like( qr/Sorry try again/ )
->element_exists( 'form#login' )
->element_exists_not( '#user-menu' );

# fail password
$t->post_ok( '/login' => form => {from => '/page/home', username => 'admin', password => 'wrongpass' } )
$t->post_ok( '/login' => form => {from => '/home', username => 'admin', password => 'wrongpass' } )
->status_is(200)
->content_like( qr/Sorry try again/ )
->element_exists( 'form#login' )
->element_exists_not( '#user-menu' );

# successfully login
$t->post_ok( '/login' => form => {from => '/page/home', username => 'admin', password => 'pass' } )
$t->post_ok( '/login' => form => {from => '/home', username => 'admin', password => 'pass' } )
->status_is(200)
->content_like( qr/Welcome Back/ )
->element_exists_not( 'form#login' )
Expand All @@ -73,7 +73,7 @@ subtest 'Do Login' => sub {
subtest 'Edit Page' => sub {

# page editor
$t->get_ok('/page/home/_edit')
$t->get_ok('/home/_edit')
->status_is(200)
->text_like( '#wmd-input' => qr/Welcome to your Galileo CMS site!/ )
->element_exists( '#wmd-preview' );
Expand All @@ -93,7 +93,7 @@ subtest 'Edit Page' => sub {
->finish_ok;

# see that the changes are reflected
$t->get_ok('/page/home')
$t->get_ok('/home')
->status_is(200)
->text_is( h1 => 'New Home' )
->text_like( '#content p' => qr/$text/ );
Expand All @@ -116,7 +116,7 @@ subtest 'Edit Page' => sub {
subtest 'New Page' => sub {

# author request non-existant page => create new page
$t->get_ok('/page/doesntexist')
$t->get_ok('/doesntexist')
->status_is(200)
->text_like( '#wmd-input' => qr/Hello World/ )
->element_exists( '#wmd-preview' );
Expand All @@ -136,7 +136,7 @@ subtest 'New Page' => sub {
->finish_ok;

# see that the changes are reflected
$t->get_ok('/page/snow❄flake')
$t->get_ok('/snow❄flake')
->status_is(200)
->text_is( h1 => 'New Home for ☃' )
->text_like( '#content p' => qr/$text/ );
Expand Down
8 changes: 4 additions & 4 deletions t/commands.t
Expand Up @@ -53,11 +53,11 @@ subtest 'Dump' => sub {
{
$t->ua->max_redirects(2);

$t->get_ok('/page/doesntexist')
$t->get_ok('/doesntexist')
->status_is(404);

# successfully login
$t->post_ok( '/login' => form => {from => '/page/home', username => 'admin', password => 'pass' } )
$t->post_ok( '/login' => form => {from => '/home', username => 'admin', password => 'pass' } )
->status_is(200)
->content_like( qr/Welcome Back/ )
->element_exists_not( 'form#login' )
Expand All @@ -66,7 +66,7 @@ subtest 'Dump' => sub {
->element_exists( '#user-modal #new-username' );

# author request non-existant page => create new page
$t->get_ok('/page/doesntexist')
$t->get_ok('/doesntexist')
->status_is(200)
->text_like( '#wmd-input' => qr/Hello World/ )
->element_exists( '#wmd-preview' );
Expand All @@ -86,7 +86,7 @@ subtest 'Dump' => sub {
->finish_ok;

# see that the changes are reflected
$t->get_ok('/page/snow❄flake')
$t->get_ok('/snow❄flake')
->status_is(200)
->text_is( h1 => 'New Home for ☃' )
->text_like( '#content p' => qr/$text/ );
Expand Down
2 changes: 1 addition & 1 deletion t/locations.t
Expand Up @@ -21,7 +21,7 @@ $t->get_ok('/test.html')
->or( sub { diag "'static' should be in @{ $app->static->paths }" } );

# login
$t->post_ok( '/login' => form => {from => '/page/home', username => 'admin', password => 'pass' } )
$t->post_ok( '/login' => form => {from => '/home', username => 'admin', password => 'pass' } )
->status_is(200);

# this hack fixes windows tests, but not the underlying problem that I don't want these found files reslashed!
Expand Down

0 comments on commit 72964cf

Please sign in to comment.