From 315b674efed4b41ae138ebaf76780cd915d3689a Mon Sep 17 00:00:00 2001 From: Paul Cochrane Date: Tue, 10 Apr 2018 01:37:46 +0200 Subject: [PATCH] Set 'selected' attr via Mojo controller ... instead of setting the 'selected' attribute directly. The reason for this commit is because how the 'selected' attribute was handled was changed in Mojolicious version 6.16 (see [the release changes](https://metacpan.org/changes/release/SRI/Mojolicious-7.74#L784) for more info) and the tests for this plugin had begun failing as of this Mojo version. The behaviour of the 'selected' attribute was also changed in Mojolicious version 5.73 (it's necessary to diff the 5.73 <-> 5.72 versions in order to see this; it's not mentioned in the Changes) which meant that setting the `selected` attribute to a true value no longer uses `selected='selected'` but simply the presence of the `selected` attribute is sufficient to set it to a true value. This commit should fix the current failures occurring on CPAN Testers. --- dist.ini | 2 +- .../Plugin/FormFieldsFromJSON/Date.pm | 26 +++++++------------ t/01_date.t | 4 +-- t/02_date_local_param.t | 2 +- t/03_date_today.t | 6 ++--- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/dist.ini b/dist.ini index 311ceb7..7c3697d 100644 --- a/dist.ini +++ b/dist.ini @@ -18,5 +18,5 @@ repository.web = http://github.com/reneeb/Mojolicious-Plugin-FormFieldsFromJSON- repository.type = git [Prereqs] -Mojolicious = 5.67 +Mojolicious = 5.73 Mojolicious::Plugin::FormFieldsFromJSON = 0.19 diff --git a/lib/Mojolicious/Plugin/FormFieldsFromJSON/Date.pm b/lib/Mojolicious/Plugin/FormFieldsFromJSON/Date.pm index 727cd4b..f6e8734 100644 --- a/lib/Mojolicious/Plugin/FormFieldsFromJSON/Date.pm +++ b/lib/Mojolicious/Plugin/FormFieldsFromJSON/Date.pm @@ -70,15 +70,13 @@ sub Mojolicious::Plugin::FormFieldsFromJSON::_date { sub _day_dropdown { my ($c, %params) = @_; + $c->param( $params{name}, '' ); + my @days = map{ - my %opts = ( $_ == $params{day} ) ? - ('selected' => 'selected') : - (); - [ $_ => sprintf("%02d", $_) , %opts ] + $c->param( $params{name} => sprintf("%02d", $_) ) if $_ == $params{day}; + [ $_ => sprintf("%02d", $_) ] }(1 .. 31); - $c->param( $params{name}, '' ); - my $select = $c->select_field( $params{name}, \@days, @@ -90,15 +88,13 @@ sub _day_dropdown { sub _month_dropdown { my ($c, %params) = @_; + $c->param( $params{name}, '' ); + my @months = map{ - my %opts = ( $_ == $params{month} ) ? - ('selected' => 'selected') : - (); - [ $_ => sprintf("%02d", $_), %opts ] + $c->param( $params{name} => sprintf("%02d", $_) ) if $_ == $params{month}; + [ $_ => sprintf("%02d", $_) ] }(1 .. 12); - $c->param( $params{name}, '' ); - my $select = $c->select_field( $params{name}, \@months, @@ -120,10 +116,8 @@ sub _year_dropdown { my $has_year; my @years = map{ $has_year++ if $_ == $params{year}; - my %opts = ( $_ == $params{year} ) ? - ('selected' => 'selected') : - (); - [ $_ => $_, %opts ] + $c->param( $params{name} => $params{year} ) if $_ == $params{year}; + [ $_ => $_ ] }($start .. $stop); if ( !$has_year ) { diff --git a/t/01_date.t b/t/01_date.t index a7a6b44..cd42814 100644 --- a/t/01_date.t +++ b/t/01_date.t @@ -28,10 +28,10 @@ get '/' => sub { my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200)->content_is( -''); +''); $t->get_ok('/?name-day=13&name-month=10&name-year=2015')->status_is(200)->content_is( -''); +''); done_testing(); diff --git a/t/02_date_local_param.t b/t/02_date_local_param.t index a851379..e7d88ee 100644 --- a/t/02_date_local_param.t +++ b/t/02_date_local_param.t @@ -28,7 +28,7 @@ get '/' => sub { my $t = Test::Mojo->new; $t->get_ok('/')->status_is(200)->content_is( -''); +''); done_testing(); diff --git a/t/03_date_today.t b/t/03_date_today.t index 0008ac4..443e213 100644 --- a/t/03_date_today.t +++ b/t/03_date_today.t @@ -40,9 +40,9 @@ my $mon = $today->mon; my $day = sprintf "%02d", $today->mday; my $mday = $today->mday; -like $content, qr/selected="selected" value="$year">$year$mon$mday$year$mon$mday