Commit a3816174d562ea655cdd5b8753d85375f3bb4eac
1 parent
9bd039ca
Exists in
master
and in
28 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 | 396 | |
397 | 397 | # formats a date for displaying. |
398 | 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 | 404 | end |
401 | 405 | |
402 | 406 | # formats a datetime for displaying. |
403 | 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 | 413 | end |
406 | 414 | |
407 | 415 | end | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -35,6 +35,10 @@ class ApplicationHelperTest < Test::Unit::TestCase |
35 | 35 | assert_equal 'translated date', show_date(date) |
36 | 36 | end |
37 | 37 | |
38 | + should 'handle nil dates' do | |
39 | + assert_equal '', show_date(nil) | |
40 | + end | |
41 | + | |
38 | 42 | should 'translate time' do |
39 | 43 | time = mock |
40 | 44 | expects(:_).with('%d %B %Y, %H:%m').returns('the time') |
... | ... | @@ -42,6 +46,10 @@ class ApplicationHelperTest < Test::Unit::TestCase |
42 | 46 | assert_equal 'translated time', show_time(time) |
43 | 47 | end |
44 | 48 | |
49 | + should 'handle nil time' do | |
50 | + assert_equal '', show_time(nil) | |
51 | + end | |
52 | + | |
45 | 53 | protected |
46 | 54 | |
47 | 55 | def content_tag(tag, content, options) | ... | ... |