Commit 9a80f26153e994d6c29711125de82926d8c1929b

Authored by AntonioTerceiro
1 parent df43ced1

ActionItem436: falling back to current year/month


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2016 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/dates_helper.rb
... ... @@ -42,6 +42,14 @@ module DatesHelper
42 42 end
43 43  
44 44 def show_month(year, month)
  45 +
  46 + if year.blank?
  47 + year = Date.today.year
  48 + end
  49 + if month.blank?
  50 + month = Date.today.month
  51 + end
  52 +
45 53 # FIXME Date#strftime should translate this for us !!!
46 54 monthname = _([
47 55 N_('January'),
... ...
test/functional/search_controller_test.rb
... ... @@ -814,6 +814,13 @@ class SearchControllerTest < Test::Unit::TestCase
814 814 assert_equal 0, assigns(:calendar).size % 7
815 815 end
816 816  
  817 + should 'display current year/month by default' do
  818 + Date.expects(:today).returns(Date.new(2008, 8, 1)).at_least_once
  819 +
  820 + get :assets, :asset => 'events'
  821 + assert_tag :tag => 'h1', :content => /^\s*August 2008\s*$/
  822 + end
  823 +
817 824 should 'submit search form to /search when viewing asset' do
818 825 get :index, :asset => 'people'
819 826 assert_tag :tag => "form", :attributes => { :class => 'search_form', :action => '/search' }
... ...
test/unit/dates_helper_test.rb
... ... @@ -38,6 +38,15 @@ class DatesHelperTest < Test::Unit::TestCase
38 38 assert_equal 'January 2008', show_month(2008, 1)
39 39 end
40 40  
  41 + should 'fallback to current year/month in show_month' do
  42 + Date.expects(:today).returns(Date.new(2008,11,1)).at_least_once
  43 +
  44 + expects(:_).with('November').returns('November').at_least_once
  45 + expects(:_).with('%{month} %{year}').returns('%{month} %{year}').at_least_once
  46 + assert_equal 'November 2008', show_month(nil, nil)
  47 + assert_equal 'November 2008', show_month('', '')
  48 + end
  49 +
41 50 should 'provide link to previous month' do
42 51 expects(:link_to).with('← January 2008', { :year => 2008, :month => 1})
43 52 link_to_previous_month('2008', '2')
... ...