Commit 70811f900ec4a15107c6e6b5a66323b52b0f5ad8

Authored by Braulio Bhavamitra
1 parent ad280692

dates_helper: don't use constant for translation

app/helpers/dates_helper.rb
@@ -2,13 +2,15 @@ require 'noosfero/i18n' @@ -2,13 +2,15 @@ require 'noosfero/i18n'
2 2
3 module DatesHelper 3 module DatesHelper
4 4
5 - MONTHS = I18n.t('date.month_names') 5 + def months
  6 + I18n.t('date.month_names')
  7 + end
6 8
7 def month_name(n, abbreviated = false) 9 def month_name(n, abbreviated = false)
8 if abbreviated 10 if abbreviated
9 I18n.t('date.abbr_month_names')[n] 11 I18n.t('date.abbr_month_names')[n]
10 else 12 else
11 - MONTHS[n] 13 + months[n]
12 end 14 end
13 end 15 end
14 16
@@ -37,7 +39,7 @@ module DatesHelper @@ -37,7 +39,7 @@ module DatesHelper
37 end 39 end
38 end 40 end
39 41
40 - # formats a datetime for displaying. 42 + # formats a datetime for displaying.
41 def show_time(time) 43 def show_time(time)
42 if time 44 if time
43 _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") } 45 _('%{day} %{month} %{year}, %{hour}:%{minutes}') % { :year => time.year, :month => month_name(time.month), :day => time.day, :hour => time.hour, :minutes => time.strftime("%M") }
@@ -138,7 +140,7 @@ module DatesHelper @@ -138,7 +140,7 @@ module DatesHelper
138 else 140 else
139 order = [:day, :month, :year] 141 order = [:day, :month, :year]
140 end 142 end
141 - date_select(object, method, html_options.merge(options.merge(:include_blank => true, :order => order, :use_month_names => MONTHS))) 143 + date_select(object, method, html_options.merge(options.merge(:include_blank => true, :order => order, :use_month_names => months)))
142 end 144 end
143 145
144 end 146 end
test/unit/dates_helper_test.rb
@@ -99,20 +99,20 @@ class DatesHelperTest < ActiveSupport::TestCase @@ -99,20 +99,20 @@ class DatesHelperTest < ActiveSupport::TestCase
99 99
100 should 'provide an intertionalized date selector pass month names' do 100 should 'provide an intertionalized date selector pass month names' do
101 expects(:language).returns('en') 101 expects(:language).returns('en')
102 - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") 102 + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => months }).returns("KKKKKKKK")
103 assert_equal 'KKKKKKKK', pick_date(:object, :method) 103 assert_equal 'KKKKKKKK', pick_date(:object, :method)
104 end 104 end
105 105
106 should 'order date in english like month day year' do 106 should 'order date in english like month day year' do
107 expects(:language).returns('en') 107 expects(:language).returns('en')
108 - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") 108 + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:month, :day, :year], :use_month_names => months }).returns("KKKKKKKK")
109 109
110 assert_equal 'KKKKKKKK', pick_date(:object, :method) 110 assert_equal 'KKKKKKKK', pick_date(:object, :method)
111 end 111 end
112 112
113 should 'order date in other languages like day month year' do 113 should 'order date in other languages like day month year' do
114 expects(:language).returns('pt_BR') 114 expects(:language).returns('pt_BR')
115 - expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:day, :month, :year], :use_month_names => MONTHS }).returns("KKKKKKKK") 115 + expects(:date_select).with(:object, :method, { :include_blank => true, :order => [:day, :month, :year], :use_month_names => months }).returns("KKKKKKKK")
116 116
117 assert_equal 'KKKKKKKK', pick_date(:object, :method) 117 assert_equal 'KKKKKKKK', pick_date(:object, :method)
118 end 118 end