Bug 14693 - t/db_dependent/Contract.t fails do to fixed date
Summary: t/db_dependent/Contract.t fails do to fixed date
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Galen Charlton
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-19 13:26 UTC by Tomás Cohen Arazi
Modified: 2016-12-05 21:23 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 14693: Contract.t should generate dates based on current date (2.09 KB, patch)
2015-08-19 17:25 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 14693: Contract.t should generate dates based on current date (2.17 KB, patch)
2015-08-20 13:05 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
[SIGNED-OFF] Bug 14693: Contract.t should generate dates based on current date (2.24 KB, patch)
2015-08-21 13:28 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 14693: Contract.t should generate dates based on current date (2.29 KB, patch)
2015-08-21 13:43 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.