Bug 14693

Summary: t/db_dependent/Contract.t fails do to fixed date
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Test SuiteAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Galen Charlton <gmcharlt>
Severity: normal    
Priority: P5 - low CC: tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 14693: Contract.t should generate dates based on current date
Bug 14693: Contract.t should generate dates based on current date
[SIGNED-OFF] Bug 14693: Contract.t should generate dates based on current date
Bug 14693: Contract.t should generate dates based on current date

Description Tomás Cohen Arazi 2015-08-19 13:26:42 UTC
To reproduce:

- Run (on master)
  $ prove t/db_dependent/Contract.t
=> FAIL: tests fail due to a fixed date (2015-07-31) being set as a future date which hasn't arrived yet.
Comment 1 Tomás Cohen Arazi 2015-08-19 17:25:05 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2015-08-20 10:58:40 UTC
Comment on attachment 41682 [details] [review]
Bug 14693: Contract.t should generate dates based on current date

Review of attachment 41682 [details] [review]:
-----------------------------------------------------------------

::: t/db_dependent/Contract.t
@@ +72,5 @@
>  is( $contract->{contractdescription}, $my_contract1->{contractdescription}, 'AddContract stores the contract description correctly.' );
>  is( $contract->{booksellerid}, $my_contract1->{booksellerid}, 'AddContract stores the bookseller id correctly.' );
>  
> +my $now = dt_from_string;
> +my $three_more_days = $now + DateTime::Duration->new( days => 3 );

1/ DateTime::Duration should be imported
2/ Are you sure this works ? There are the 2 add_duration or subtract_duration methods, which is certainly better.
Comment 3 Tomás Cohen Arazi 2015-08-20 12:28:35 UTC
(In reply to Jonathan Druart from comment #2)
> Comment on attachment 41682 [details] [review] [review]
> 1/ DateTime::Duration should be imported

I agree. Will fix it now.

> 2/ Are you sure this works ? There are the 2 add_duration or
> subtract_duration methods, which is certainly better.

It is just syntax sugar. Using the plus symbol is correctly documented on DateTime:

$dt2 = $dt + $duration_object;
$dt3 = $dt - $duration_object;

I think it provides better readability.
Comment 4 Tomás Cohen Arazi 2015-08-20 13:05:17 UTC Comment hidden (obsolete)
Comment 5 Kyle M Hall 2015-08-21 13:28:34 UTC Comment hidden (obsolete)
Comment 6 Jonathan Druart 2015-08-21 13:43:09 UTC
Created attachment 41786 [details] [review]
Bug 14693: Contract.t should generate dates based on current date

The current test for still-active contracts fails because it was written
with fixed dates, which already passed :-D

This patch calculates the current date, and uses it to generate a future
one, so the tests serve their purpose no matter what the current date is.

To test:
- Run:
  $ prove t/db_dependent/Contract.t
=> FAIL: activeonly compares contractenddate with now(), and fails
         because a fixed 2015-07-31 is writteng on the test data
- Apply the patch
- Run:
  $ prove t/db_dependent/Contract.t
=> SUCCESS: the sample data has been calculated using the current date
            and the tests pass.
- Sign off :-D

Edit: added missing use DateTime::Duration,

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 7 Tomás Cohen Arazi 2015-08-21 18:39:13 UTC
Fix pushed to master.