Commit a3816174d562ea655cdd5b8753d85375f3bb4eac
1 parent
9bd039ca
Exists in
master
and in
22 other branches
ActionItem172: handling nil date/time
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1549 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
18 additions
and
2 deletions
Show diff stats
app/helpers/application_helper.rb
| @@ -396,12 +396,20 @@ module ApplicationHelper | @@ -396,12 +396,20 @@ module ApplicationHelper | ||
| 396 | 396 | ||
| 397 | # formats a date for displaying. | 397 | # formats a date for displaying. |
| 398 | def show_date(date) | 398 | def show_date(date) |
| 399 | - date.strftime(_('%d %B %Y')) | 399 | + if date |
| 400 | + date.strftime(_('%d %B %Y')) | ||
| 401 | + else | ||
| 402 | + '' | ||
| 403 | + end | ||
| 400 | end | 404 | end |
| 401 | 405 | ||
| 402 | # formats a datetime for displaying. | 406 | # formats a datetime for displaying. |
| 403 | def show_time(time) | 407 | def show_time(time) |
| 404 | - time.strftime(_('%d %B %Y, %H:%m')) | 408 | + if time |
| 409 | + time.strftime(_('%d %B %Y, %H:%m')) | ||
| 410 | + else | ||
| 411 | + '' | ||
| 412 | + end | ||
| 405 | end | 413 | end |
| 406 | 414 | ||
| 407 | end | 415 | end |
test/unit/application_helper_test.rb
| @@ -35,6 +35,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -35,6 +35,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 35 | assert_equal 'translated date', show_date(date) | 35 | assert_equal 'translated date', show_date(date) |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | + should 'handle nil dates' do | ||
| 39 | + assert_equal '', show_date(nil) | ||
| 40 | + end | ||
| 41 | + | ||
| 38 | should 'translate time' do | 42 | should 'translate time' do |
| 39 | time = mock | 43 | time = mock |
| 40 | expects(:_).with('%d %B %Y, %H:%m').returns('the time') | 44 | expects(:_).with('%d %B %Y, %H:%m').returns('the time') |
| @@ -42,6 +46,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -42,6 +46,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 42 | assert_equal 'translated time', show_time(time) | 46 | assert_equal 'translated time', show_time(time) |
| 43 | end | 47 | end |
| 44 | 48 | ||
| 49 | + should 'handle nil time' do | ||
| 50 | + assert_equal '', show_time(nil) | ||
| 51 | + end | ||
| 52 | + | ||
| 45 | protected | 53 | protected |
| 46 | 54 | ||
| 47 | def content_tag(tag, content, options) | 55 | def content_tag(tag, content, options) |