[Jifty-commit] r4699 - in jifty/branches/jquery: .
t/TestApp-JiftyJS/lib/TestApp/JiftyJS
t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action
t/TestApp-JiftyJS/share/web/static/css t/TestApp-JiftyJS/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sat Dec 15 03:37:33 EST 2007
Author: gugod
Date: Sat Dec 15 03:37:32 2007
New Revision: 4699
Added:
jifty/branches/jquery/lib/Jifty/Plugin/Gladiator.pm
jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/AddTwoNumbers.pm
jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/Play.pm
jifty/branches/jquery/t/TestApp-JiftyJS/share/web/static/css/
jifty/branches/jquery/t/TestApp-JiftyJS/share/web/static/css/app.css
jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-AddTwoNumbers.t
jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-Play.t
jifty/branches/jquery/t/TestApp-JiftyJS/t/3-continuation.t
jifty/branches/jquery/t/TestApp-JiftyJS/t/4-tangent.t
jifty/branches/jquery/t/TestApp-JiftyJS/t/5-action.t
Modified:
jifty/branches/jquery/ (props changed)
jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/View.pm
jifty/branches/jquery/t/TestApp-JiftyJS/t/1-jifty-update.t
Log:
Merge from trunk.
Added: jifty/branches/jquery/lib/Jifty/Plugin/Gladiator.pm
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/lib/Jifty/Plugin/Gladiator.pm Sat Dec 15 03:37:32 2007
@@ -0,0 +1,132 @@
+package Jifty::Plugin::Gladiator;
+use strict;
+use warnings;
+use base qw/Jifty::Plugin Class::Data::Inheritable/;
+__PACKAGE__->mk_accessors(qw/prev_data/);
+
+use Devel::Gladiator;
+use Jifty::Util;
+
+our $VERSION = 0.01;
+
+=head2 init
+
+init installs the trigger needed before each HTTP request. It also establishes
+the baseline for all times and creates the log path.
+
+=cut
+
+sub init {
+ my $self = shift;
+ my %args = (
+ @_,
+ );
+
+ return if $self->_pre_init;
+
+
+ Jifty::Handler->add_trigger(
+ before_request => sub { $self->before_request(@_) }
+ );
+
+ Jifty::Handler->add_trigger(
+ after_request => sub { $self->after_request }
+ );
+}
+
+=head2 before_request
+
+Log as much of the request state as we can.
+
+=cut
+
+sub before_request
+{
+ my $self = shift;
+ my $handler = shift;
+ my $cgi = shift;
+
+
+ Jifty->log->error("Unable to probe for gladiatorg: $@") if $@;
+}
+
+=head2 after_request
+
+Append the current user to the request log. This isn't done in one fell swoop
+because if the server explodes during a request, we would lose the request's
+data for logging.
+
+This, strictly speaking, isn't necessary. But we don't always want to lug the
+sessions table around, so this gets us most of the way there.
+
+C<logged_request> is checked to ensure that we don't append the current
+user if the current request couldn't be logged for whatever reason (perhaps
+a serialization error?).
+
+=cut
+
+sub after_request {
+ my $self = shift;
+
+ my $type_map = {};
+ eval {
+ my $array = Devel::Gladiator::walk_arena();
+ use Devel::Cycle;
+ for my $entry (@$array) {
+ find_cycle($entry);
+ $type_map->{ ref($entry) }++;
+ }
+ };
+
+ my $prev = $self->prev_data || {};
+ for (keys %$type_map) {
+ $type_map->{$_} -= $prev->{$_};
+ delete $type_map->{$_} if $type_map->{$_} == 0;
+ }
+
+ warn "This request";
+ warn Jifty::YAML::Dump($type_map);
+
+ $self->prev_data($type_map);
+
+}
+
+
+=head1 NAME
+
+Jifty::Plugin::Gladiator - find leaks
+
+=head1 DESCRIPTION
+
+This plugin will attempt to output diffs between the current contents of memory after each request.
+
+
+=head1 USAGE
+
+Add the following to your site_config.yml
+
+ framework:
+ Plugins:
+ - Gladiator: {}
+
+=head2 OPTIONS
+
+=over 4
+
+
+=back
+
+=head1 SEE ALSO
+
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 Best Practical Solutions
+
+This is free software and may be modified and distributed under the same terms as Perl itself.
+
+=cut
+
+1;
+
+
Added: jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/AddTwoNumbers.pm
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/AddTwoNumbers.pm Sat Dec 15 03:37:32 2007
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+TestApp::JiftyJS::Action::AddTwoNumbers
+
+=cut
+
+package TestApp::JiftyJS::Action::AddTwoNumbers;
+use base qw/TestApp::JiftyJS::Action Jifty::Action/;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+ param first_number => type is 'text';
+ param second_number => type is 'text';
+};
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+ my $self = shift;
+ my $one = $self->argument_value("first_number");
+ my $two = $self->argument_value("second_number");
+ $self->result->message("Got " . ($one + $two));
+ return 1;
+}
+
+1;
Added: jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/Play.pm
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/Action/Play.pm Sat Dec 15 03:37:32 2007
@@ -0,0 +1,58 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+TestApp::JiftyJS::Action::Play
+
+=cut
+
+package TestApp::JiftyJS::Action::Play;
+use base qw/TestApp::JiftyJS::Action Jifty::Action/;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+ param vanilla => type is 'text';
+
+ param mood =>
+ type is 'text',
+ ajax validates,
+ valid are qw(happy angry normal);
+
+ param tags =>
+ type is 'text',
+ ajax canonicalizes;
+};
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+ my $self = shift;
+ $self->report_success if not $self->result->failure;
+ return 1;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+ my $self = shift;
+ # Your success message here
+ $self->result->message('Success');
+}
+
+sub canonicalize_tags {
+ my ($self, $value) = @_;
+ my $v = lc($value);
+ $v =~ s/\s+/ /g;
+ $v =~ s/^\s*//g;
+ $v =~ s/\s*$//g;
+
+ return $v;
+}
+
+1;
+
Modified: jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/View.pm
==============================================================================
--- jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/View.pm (original)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/lib/TestApp/JiftyJS/View.pm Sat Dec 15 03:37:32 2007
@@ -61,4 +61,88 @@
p { "Region Two" }
};
+template '/region/multiupdate' => page {
+ hyperlink(
+ id => 'update',
+ label => "Update All",
+ onclick => [
+ "alert(42);",
+ { region => 'content1', replace_with => 'region1' },
+ { region => 'content2', replace_with => 'region2' },
+ { region => 'content3', replace_with => 'hello_world', arguments => { name => "Pony" } },
+ ]
+ );
+
+ for (1..3) {
+ with(class=>'column'), div {
+ render_region( name => "content$_" );
+ }
+ }
+ with(style=>"clear:both;"), div {};
+};
+
+# Templtes for testing continuation. Using the example in Jifty::Manual::Continuations
+private template '/c/_first_number_form' => sub {
+ my $action = new_action(class => 'AddTwoNumbers');
+ form {
+ $action->form_field( 'first_number' )->render;
+ $action->form_field( 'second_number',
+ default_value => {
+ request_argument => "number",
+ }
+ )->render;
+ tangent(
+ url => '/c/page2',
+ submit => $action,
+ label => "Enter a second number"
+ );
+ };
+};
+
+template '/c/page1' => page {
+ show('/c/_first_number_form');
+};
+
+template '/c/page_another_one' => page {
+ show('/c/_first_number_form');
+};
+
+template '/c/page2' => page {
+ form {
+ label { "Second Number" };
+ outs_raw('<input type="text" class="text" name="number" />');
+ form_return( label => "Pick", as_button => 1);
+ }
+};
+
+### tangent/reutrn test temapltes
+
+template '/tangent/returner' => page {
+ Jifty->web->return( label => "Go Back", to => "/", id => 'returner' )->render;
+};
+
+template '/tangent/page1' => page {
+ tangent( label => "Go to Returner", url => "/tangent/returner", id => 'to-returner' );
+};
+
+template '/tangent/page2' => page {
+ tangent( label => "Go to Returner", url => "/tangent/returner", id => 'to-returner' );
+};
+
+template '/tangent/page3' => page {
+ hyperlink( label => "Go to Returner", url => "/tangent/returner", id => 'to-returner' );
+};
+
+
+### action field test templates
+
+template '/act/play' => page {
+ my $a = new_action(class => 'Play');
+ form {
+ render_action($a);
+ form_submit( label => "Submit" );
+ };
+};
+
+
1;
Added: jifty/branches/jquery/t/TestApp-JiftyJS/share/web/static/css/app.css
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/share/web/static/css/app.css Sat Dec 15 03:37:32 2007
@@ -0,0 +1,8 @@
+
+div.column {
+ width:200px;
+ padding-left:10px;
+ padding-right:10px;
+ float:left;
+}
+
Added: jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-AddTwoNumbers.t
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-AddTwoNumbers.t Sat Dec 15 03:37:32 2007
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A (very) basic test harness for the AddTwoNumbers action.
+
+=cut
+
+use Jifty::Test tests => 1;
+
+# Make sure we can load the action
+use_ok('TestApp::JiftyJS::Action::AddTwoNumbers');
+
Added: jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-Play.t
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/00-action-Play.t Sat Dec 15 03:37:32 2007
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A (very) basic test harness for the Play action.
+
+=cut
+
+use Jifty::Test tests => 1;
+
+# Make sure we can load the action
+use_ok('TestApp::JiftyJS::Action::Play');
+
Modified: jifty/branches/jquery/t/TestApp-JiftyJS/t/1-jifty-update.t
==============================================================================
--- jifty/branches/jquery/t/TestApp-JiftyJS/t/1-jifty-update.t (original)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/1-jifty-update.t Sat Dec 15 03:37:32 2007
@@ -4,7 +4,7 @@
use warnings;
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 12;
+use Jifty::Test tests => 18;
use Jifty::Test::WWW::Selenium;
use utf8;
@@ -12,33 +12,36 @@
my $sel = Jifty::Test::WWW::Selenium->rc_ok($server);
my $URL = $server->started_ok;
-$sel->open_ok("/1-jifty-update.html");
-
-my $html = $sel->get_html_source;
-
-like $html, qr{<h1>Jifty\.update\(\) tests</h1>}is;
-
-$sel->click_ok("region1");
-sleep 2;
-$html = $sel->get_html_source;
-like $html, qr{<p>Region One</p>}is;
-
-$sel->click_ok("region2");
-sleep 2;
-$html = $sel->get_html_source;
-like $html, qr{<p>Region Two</p>}is;
-
-
-# Update the same region path with different argument
-$sel->click_ok("region3");
-sleep 2;
-$html = $sel->get_html_source;
-like $html, qr{<p>Hello, John</p>}is;
-
-$sel->click_ok("region4");
-sleep 2;
-$html = $sel->get_html_source;
-like $html, qr{<p>Hello, Smith</p>}is;
+{
+ $sel->open_ok("/1-jifty-update.html");
+ $sel->wait_for_text_present_ok("Jifty.update() tests");
+
+ $sel->click_ok("region1");
+ $sel->wait_for_text_present_ok("Region One");
+
+ $sel->click_ok("region2");
+ $sel->wait_for_text_present_ok("Region Two");
+
+ # Update the same region path with different argument
+ $sel->click_ok("region3");
+ $sel->wait_for_text_present_ok("Hello, John");
+
+ $sel->click_ok("region4");
+ $sel->wait_for_text_present_ok("Hello, Smith");
+}
+
+{
+ # One click updates 3 regions, and triggers an alert.
+
+ $sel->open_ok('/region/multiupdate');
+ $sel->click_ok('update');
+ $sel->get_alert_ok();
+
+ $sel->wait_for_text_present_ok("Region One");
+ $sel->wait_for_text_present_ok("Region Two");
+ $sel->wait_for_text_present_ok("Hello, Pony");
+}
$sel->stop;
+
Added: jifty/branches/jquery/t/TestApp-JiftyJS/t/3-continuation.t
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/3-continuation.t Sat Dec 15 03:37:32 2007
@@ -0,0 +1,72 @@
+# Test simple continuation using the example in Jifty::Manual::Continuation
+
+use strict;
+use warnings;
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 24;
+use Jifty::Test::WWW::Selenium;
+use utf8;
+
+my $server = Jifty::Test->make_server;
+my $sel = Jifty::Test::WWW::Selenium->rc_ok($server);
+my $URL = $server->started_ok;
+
+{
+ # /c/page1 -> /c/page2 -> /c/page1
+
+
+ $sel->open_ok("/c/page1");
+ $sel->wait_for_text_present_ok('first_number');
+
+ my $field = '//input[contains(@class, "text")]';
+ my $button = '//input[@type="submit"]';
+
+ $sel->wait_for_element_present_ok($field);
+ $sel->click_ok($field);
+ $sel->type_ok($field, "100");
+
+ $sel->do_command_ok("clickAndWait", $button);
+
+ my $loc = $sel->get_location;
+ like $loc, qr{/c/page2}, "URL looks like /c/page2";;
+
+ $sel->click_ok($field);
+ $sel->type_ok($field, "50");
+ $sel->do_command_ok("clickAndWait", $button);
+
+ $loc = $sel->get_location;
+ like $loc, qr{/c/page1}, "URL looks like /c/page1";
+
+}
+
+
+{
+ # /c/page_another_one -> /c/page2 -> /c/page_another_one
+
+ $sel->open_ok("/c/page_another_one");
+ $sel->wait_for_text_present_ok('first_number');
+
+ my $field = '//input[contains(@class, "text")]';
+ my $button = '//input[@type="submit"]';
+
+ $sel->wait_for_element_present_ok($field);
+ $sel->click_ok($field);
+ $sel->type_ok($field, "100");
+
+ $sel->do_command_ok("clickAndWait", $button);
+
+ my $loc = $sel->get_location;
+ like $loc, qr{/c/page2}, "URL looks like /c/page2";
+
+ $sel->click_ok($field);
+ $sel->type_ok($field, "50");
+ $sel->do_command_ok("clickAndWait", $button);
+
+ $loc = $sel->get_location;
+ like $loc, qr{/c/page_another_one}, "URL looks like /c/page_another_one";
+}
+
+
+
+$sel->stop;
Added: jifty/branches/jquery/t/TestApp-JiftyJS/t/4-tangent.t
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/4-tangent.t Sat Dec 15 03:37:32 2007
@@ -0,0 +1,45 @@
+# Test tangent / return
+
+use strict;
+use warnings;
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 17;
+use Jifty::Test::WWW::Selenium;
+use utf8;
+
+my $server = Jifty::Test->make_server;
+my $sel = Jifty::Test::WWW::Selenium->rc_ok($server);
+my $URL = $server->started_ok;
+
+{
+ # /tangent/page1 -- tangent --> /tangent/returner -- return --> /tangent/page1
+
+ $sel->open_ok("/tangent/page1");
+ $sel->do_command_ok("clickAndWait", "to-returner");
+ like $sel->get_location, qr{/tangent/returner}, "URL looks like /tangent/returner";
+ $sel->do_command_ok("clickAndWait", "returner");
+ like $sel->get_location, qr{/tangent/page1}, "URL looks like /tangent/page1";
+}
+
+{
+ # /tangent/page2 -- tangent --> /tangent/returner -- return --> /tangent/page2
+
+ $sel->open_ok("/tangent/page2");
+ $sel->do_command_ok("clickAndWait", "to-returner");
+ like $sel->get_location, qr{/tangent/returner}, "URL looks like /tangent/returner";
+ $sel->do_command_ok("clickAndWait", "returner");
+ like $sel->get_location, qr{/tangent/page2}, "URL looks like /tangent/page2j";
+}
+
+{
+ # /tangent/page3 -- hyperlink --> /tangent/returner -- return --> /
+
+ $sel->open_ok("/tangent/page3");
+ $sel->do_command_ok("clickAndWait", "to-returner");
+ like $sel->get_location, qr{/tangent/returner}, "URL looks like /tangent/returner";
+ $sel->do_command_ok("clickAndWait", "returner");
+ like $sel->get_location, qr{/}, "URL looks like /";
+}
+
+$sel->stop;
Added: jifty/branches/jquery/t/TestApp-JiftyJS/t/5-action.t
==============================================================================
--- (empty file)
+++ jifty/branches/jquery/t/TestApp-JiftyJS/t/5-action.t Sat Dec 15 03:37:32 2007
@@ -0,0 +1,47 @@
+# Test Action
+
+use strict;
+use warnings;
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 10;
+use Jifty::Test::WWW::Selenium;
+use utf8;
+
+my $server = Jifty::Test->make_server;
+my $sel = Jifty::Test::WWW::Selenium->rc_ok($server);
+my $URL = $server->started_ok;
+
+{
+ # Test "Play" action's parameter.
+
+ $sel->open_ok("/act/play");
+
+ my $tags = '//input[contains(@class, "argument-tags")]';
+ my $mood = '//input[contains(@class, "argument-mood")]';
+
+ # Tag is ajax canonicalized to lowercase.
+
+ $sel->set_speed(1000);
+ $sel->click_ok($tags);
+ $sel->type_ok($tags, "FOO");
+ $sel->fire_event($tags, "blur");
+
+ my $tag_value = $sel->get_value($tags);
+ is $tag_value, 'foo', "Tags are canonicalized to lower-case";
+
+ $sel->type_ok($mood, "FOO");
+ $sel->fire_event($tags, "blur");
+ is($sel->get_text('//span[contains(@class, "error text argument-mood")]'),
+ "That doesn't look like a correct value",
+ "mood validation error");
+
+ $sel->type_ok($mood, "angry");
+ $sel->fire_event($tags, "blur");
+ is($sel->get_text('//span[contains(@class, "error text argument-mood")]'),
+ "",
+ "mood validation ok");
+
+}
+
+$sel->stop;
More information about the Jifty-commit
mailing list