[Jifty-commit] jifty branch, master, updated. 1.10518-57-g9054271

Jifty commits jifty-commit at lists.jifty.org
Thu Nov 3 18:22:23 EDT 2011


The branch, master has been updated
       via  9054271fd7ffe410569d976659d986366727c0d3 (commit)
       via  059a3eb07fe70e3cd46de381024070415b3264b0 (commit)
       via  7623ee9f7b4520b8ff9e25614e96ffae55c2e259 (commit)
       via  0879ff604ca2a035e7d0e7d4276eea7a6c773337 (commit)
      from  cbfa4c0247ae33795fbbf8da8cbe0a5980d96aa8 (commit)

Summary of changes:
 lib/Jifty/Action.pm                      |   14 ++++++++++++++
 lib/Jifty/Request.pm                     |    9 +++++++++
 lib/Jifty/Web/Form/Element.pm            |    2 +-
 t/Mapper/t/01-raw-api.t                  |   29 ++++++++++++++++++++++++++++-
 t/TestApp-JiftyJS/t/1-jifty-update.t     |    2 +-
 t/TestApp-JiftyJS/t/2-behaviour.t        |    4 ++--
 t/TestApp-JiftyJS/t/3-continuation.t     |    2 +-
 t/TestApp-JiftyJS/t/4-tangent.t          |    2 +-
 t/TestApp-JiftyJS/t/5-action.t           |    2 +-
 t/TestApp-JiftyJS/t/6-offer-actions.t    |    2 +-
 t/TestApp-JiftyJS/t/7-redirect.t         |    2 +-
 t/TestApp-JiftyJS/t/8-placeholder.t      |    2 +-
 t/TestApp-Plugin-OnClick/t/onclick.t     |    2 +-
 t/TestApp-Plugin-SinglePage/t/history.t  |    2 +-
 t/TestApp-Plugin-SinglePage/t/statevar.t |    2 +-
 t/TestApp-Uploads/t/uploads-js.t         |    2 +-
 16 files changed, 65 insertions(+), 15 deletions(-)

- Log -----------------------------------------------------------------
commit 0879ff604ca2a035e7d0e7d4276eea7a6c773337
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Nov 3 16:37:40 2011 -0400

    Test request mapping inside webservices action arguments

diff --git a/t/Mapper/t/01-raw-api.t b/t/Mapper/t/01-raw-api.t
index 1458479..51cae8d 100644
--- a/t/Mapper/t/01-raw-api.t
+++ b/t/Mapper/t/01-raw-api.t
@@ -9,8 +9,9 @@ Tests for request mapper
 
 =cut
 
-use Jifty::Test::Dist tests => 32;
+use Jifty::Test::Dist tests => 35;
 use_ok('Jifty::Test::WWW::Mechanize');
+use_ok('Jifty::JSON');
 
 # Set up server
 my $server = Jifty::Test->make_server;
@@ -86,5 +87,31 @@ $mech->get("$URL/index.html?J:M-foo=A`bridge`quest;J:A-bridge=CrossBridge;J:A:F-
 $mech->content_like(qr/foo: grail/, "Argument is valid, sets to submitted value");
 $mech->content_unlike(qr/J:M-foo/, "Doesn't have mapping parameter");
 
+#### Webservices action results
+my $json = Jifty::JSON::encode_json({
+    path    => "/__jifty/webservices/json",
+    actions => {
+        grail  => {
+            moniker => 'grail',
+            class   => 'GetGrail',
+            order   => 1,
+            fields  => {},
+        },
+        bridge => {
+            moniker => "bridge",
+            class   => "CrossBridge",
+            order   => 2,
+            fields  => {
+                quest   => { value => { name => 'castle', result_of => 'grail' } },
+                castle  => { value => { result_of => 'grail' } },
+                colour  => { value => 'Green' },
+            },
+        },
+    },
+});
+$mech->post($URL, 'Content-Type' => 'text/x-json', Content => $json);
+$mech->content_like(qr/got the grail/i, "Got the grail");
+$mech->content_like(qr/crossed the bridge/i, "And crossed the bridge");
+
 1;
 

commit 7623ee9f7b4520b8ff9e25614e96ffae55c2e259
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Oct 25 17:09:19 2011 -0400

    Request map action arguments submitted via YAML or JSON
    
    Webservices requests (aka ajax) fill out the Jifty::Request from a JSON
    or YAML data structure in the POST body instead of query parameters.
    Actions submitted via ajax can now take advantage of Jifty's request
    mapper for their arguments, i.e.
    
        my_action_arg => { result_of => 'moniker', name => 'result-field' }
    
    The hashref value is left as-is over the wire instead of encoded to a
    magical J:M-* parameter like non-ajax requests, and
    Jifty::Request::Mapper->map already has logic for dealing appropriately
    when 'source' is a hashref.  Values which are hashrefs but don't look
    like a request mapper spec are passed through untouched.  Specifically,
    Jifty::Request::Mapper->query_parameters is called by ->map and looks
    for one of the following hash keys to determine if the value should be
    mapped: request_argument, result, result_of, argument, argument_to.

diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index 0bc2a51..0008214 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -1056,6 +1056,15 @@ sub do_mapping {
         delete $self->arguments->{$_};
         $self->argument($key => $value);
     }
+    for my $request_action ($self->actions) {
+        while (my ($arg, $map) = each %{$request_action->arguments || {}}) {
+            my ($key, $value) = Jifty::Request::Mapper->map(destination => $arg, source => $map, %args);
+            next unless $key ne $arg or not defined $value or $value ne $map;
+            $request_action->delete($arg);
+            $request_action->argument($key => $value);
+            $request_action->modified(1);
+        }
+    }
     for ($self->state_variables) {
         my ($key, $value) = Jifty::Request::Mapper->map(destination => $_->key, source => $_->value, %args);
         next unless $key ne $_->key or not defined $value or $value ne $_->value;

commit 059a3eb07fe70e3cd46de381024070415b3264b0
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Nov 3 15:41:03 2011 -0400

    Serialize actions to their moniker for JSON
    
    This is mostly to catch places where Jifty::Action objects are used
    instead of the moniker in a webservices request.  Without a method of
    serialization, blessed objects cause JSON to throw a fatal error.

diff --git a/lib/Jifty/Action.pm b/lib/Jifty/Action.pm
index df250a5..aeddb7a 100644
--- a/lib/Jifty/Action.pm
+++ b/lib/Jifty/Action.pm
@@ -1300,6 +1300,20 @@ sub deny {
     return;
 }
 
+=head2 TO_JSON
+
+Returns this action's moniker for JSON serialization.  This is mostly to catch
+places where Jifty::Action objects are used instead of the moniker in a
+webservices request.
+
+Currently only L<Jifty::Web::Form::Element/javascript_attrs> enables the
+C<convert_blessed> option of L<JSON> (through L<Jifty::JSON>) which uses this
+method.  Objects without a TO_JSON method cause fatal JSON errors.
+
+=cut
+
+sub TO_JSON { shift->moniker }
+
 =head1 CUSTOMIZATION
 
 =head2 Canonicalization
diff --git a/lib/Jifty/Web/Form/Element.pm b/lib/Jifty/Web/Form/Element.pm
index 165441e..ccb97c0 100644
--- a/lib/Jifty/Web/Form/Element.pm
+++ b/lib/Jifty/Web/Form/Element.pm
@@ -579,7 +579,7 @@ sub javascript_attrs {
                     fragments    => $fragments,
                     continuation => $self->continuation,
                     preload_key  => $trigger_structure->{preload_key},
-                });
+                }, { convert_blessed => 1 });
 
             my $update = $trigger eq "onclick" ? "Jifty.c(event,$update_json,this)"
                                                : "Jifty.update($update_json,this);";

commit 9054271fd7ffe410569d976659d986366727c0d3
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Nov 3 18:21:44 2011 -0400

    Selenium tests require an actual server
    
    Otherwise they hang pretty badly.

diff --git a/t/TestApp-JiftyJS/t/1-jifty-update.t b/t/TestApp-JiftyJS/t/1-jifty-update.t
index e265390..48fe48a 100644
--- a/t/TestApp-JiftyJS/t/1-jifty-update.t
+++ b/t/TestApp-JiftyJS/t/1-jifty-update.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 29;
+use Jifty::Test::Dist tests => 29, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/2-behaviour.t b/t/TestApp-JiftyJS/t/2-behaviour.t
index df05a2f..35a06d3 100644
--- a/t/TestApp-JiftyJS/t/2-behaviour.t
+++ b/t/TestApp-JiftyJS/t/2-behaviour.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist qw(no_plan);
+use Jifty::Test::Dist actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
@@ -23,4 +23,4 @@ for my $test_file (qw(01.behaviour.html 02.action.html)) {
 }
 
 $sel->stop;
-
+done_testing();
diff --git a/t/TestApp-JiftyJS/t/3-continuation.t b/t/TestApp-JiftyJS/t/3-continuation.t
index a27f278..0d9096b 100644
--- a/t/TestApp-JiftyJS/t/3-continuation.t
+++ b/t/TestApp-JiftyJS/t/3-continuation.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 24;
+use Jifty::Test::Dist tests => 24, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/4-tangent.t b/t/TestApp-JiftyJS/t/4-tangent.t
index 5c03e50..4af8646 100644
--- a/t/TestApp-JiftyJS/t/4-tangent.t
+++ b/t/TestApp-JiftyJS/t/4-tangent.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 17;
+use Jifty::Test::Dist tests => 17, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/5-action.t b/t/TestApp-JiftyJS/t/5-action.t
index a40687d..a66cb4b 100644
--- a/t/TestApp-JiftyJS/t/5-action.t
+++ b/t/TestApp-JiftyJS/t/5-action.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist;
+use Jifty::Test::Dist actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/6-offer-actions.t b/t/TestApp-JiftyJS/t/6-offer-actions.t
index aebba63..4c80fa1 100644
--- a/t/TestApp-JiftyJS/t/6-offer-actions.t
+++ b/t/TestApp-JiftyJS/t/6-offer-actions.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist;
+use Jifty::Test::Dist actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/7-redirect.t b/t/TestApp-JiftyJS/t/7-redirect.t
index dccf976..b461938 100644
--- a/t/TestApp-JiftyJS/t/7-redirect.t
+++ b/t/TestApp-JiftyJS/t/7-redirect.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist;
+use Jifty::Test::Dist actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-JiftyJS/t/8-placeholder.t b/t/TestApp-JiftyJS/t/8-placeholder.t
index 20de8dd..1d7eb6f 100644
--- a/t/TestApp-JiftyJS/t/8-placeholder.t
+++ b/t/TestApp-JiftyJS/t/8-placeholder.t
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Jifty::Test::Dist;
+use Jifty::Test::Dist actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-Plugin-OnClick/t/onclick.t b/t/TestApp-Plugin-OnClick/t/onclick.t
index a0f7ed5..210db6e 100644
--- a/t/TestApp-Plugin-OnClick/t/onclick.t
+++ b/t/TestApp-Plugin-OnClick/t/onclick.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 10;
+use Jifty::Test::Dist tests => 10, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-Plugin-SinglePage/t/history.t b/t/TestApp-Plugin-SinglePage/t/history.t
index dd71f42..21e0ca3 100644
--- a/t/TestApp-Plugin-SinglePage/t/history.t
+++ b/t/TestApp-Plugin-SinglePage/t/history.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 10;
+use Jifty::Test::Dist tests => 10, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-Plugin-SinglePage/t/statevar.t b/t/TestApp-Plugin-SinglePage/t/statevar.t
index 0996fc0..358d5d3 100644
--- a/t/TestApp-Plugin-SinglePage/t/statevar.t
+++ b/t/TestApp-Plugin-SinglePage/t/statevar.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Jifty::Test::Dist tests => 6;
+use Jifty::Test::Dist tests => 6, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 use utf8;
 
diff --git a/t/TestApp-Uploads/t/uploads-js.t b/t/TestApp-Uploads/t/uploads-js.t
index a500962..f8332f0 100644
--- a/t/TestApp-Uploads/t/uploads-js.t
+++ b/t/TestApp-Uploads/t/uploads-js.t
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use warnings;
 use strict;
-use Jifty::Test::Dist tests => 8;
+use Jifty::Test::Dist tests => 8, actual_server => 1;
 use Jifty::Test::WWW::Selenium;
 
 my $server = Jifty::Test->make_server;

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list