1 require 'abstract_unit'
3 class DateHelperDistanceOfTimeInWordsI18nTests
< Test
::Unit::TestCase
4 include ActionView
::Helpers::DateHelper
8 @from = Time
.mktime(2004, 6, 6, 21, 45, 0)
11 uses_mocha
'date_helper_distance_of_time_in_words_i18n_test' do
12 # distance_of_time_in_words
14 def test_distance_of_time_in_words_calls_i18n
15 { # with include_seconds
16 [2.seconds
, true] => [:'less_than_x_seconds', 5],
17 [9.seconds
, true] => [:'less_than_x_seconds', 10],
18 [19.seconds
, true] => [:'less_than_x_seconds', 20],
19 [30.seconds
, true] => [:'half_a_minute', nil],
20 [59.seconds
, true] => [:'less_than_x_minutes', 1],
21 [60.seconds
, true] => [:'x_minutes', 1],
23 # without include_seconds
24 [29.seconds
, false] => [:'less_than_x_minutes', 1],
25 [60.seconds
, false] => [:'x_minutes', 1],
26 [44.minutes
, false] => [:'x_minutes', 44],
27 [61.minutes
, false] => [:'about_x_hours', 1],
28 [24.hours
, false] => [:'x_days', 1],
29 [30.days
, false] => [:'about_x_months', 1],
30 [60.days
, false] => [:'x_months', 2],
31 [1.year
, false] => [:'about_x_years', 1],
32 [3.years
, false] => [:'over_x_years', 3]
34 }.each
do |passed
, expected
|
35 assert_distance_of_time_in_words_translates_key passed
, expected
39 def assert_distance_of_time_in_words_translates_key(passed
, expected
)
40 diff
, include_seconds
= *passed
41 key
, count
= *expected
44 options
= {:locale => 'en', :scope => :'datetime.distance_in_words'}
45 options
[:count] = count
if count
47 I18n
.expects(:t).with(key
, options
)
48 distance_of_time_in_words(@from, to
, include_seconds
, :locale => 'en')
51 def test_distance_of_time_pluralizations
52 { [:'less_than_x_seconds', 1] => 'less than 1 second',
53 [:'less_than_x_seconds', 2] => 'less than 2 seconds',
54 [:'less_than_x_minutes', 1] => 'less than a minute',
55 [:'less_than_x_minutes', 2] => 'less than 2 minutes',
56 [:'x_minutes', 1] => '1 minute',
57 [:'x_minutes', 2] => '2 minutes',
58 [:'about_x_hours', 1] => 'about 1 hour',
59 [:'about_x_hours', 2] => 'about 2 hours',
60 [:'x_days', 1] => '1 day',
61 [:'x_days', 2] => '2 days',
62 [:'about_x_years', 1] => 'about 1 year',
63 [:'about_x_years', 2] => 'about 2 years',
64 [:'over_x_years', 1] => 'over 1 year',
65 [:'over_x_years', 2] => 'over 2 years'
67 }.each
do |args
, expected
|
69 assert_equal expected
, I18n
.t(key
, :count => count
, :scope => 'datetime.distance_in_words')
75 class DateHelperSelectTagsI18nTests
< Test
::Unit::TestCase
76 include ActionView
::Helpers::DateHelper
79 uses_mocha
'date_helper_select_tags_i18n_tests' do
81 I18n
.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date
::MONTHNAMES
86 def test_select_month_given_use_month_names_option_does_not_translate_monthnames
87 I18n
.expects(:translate).never
88 select_month(8, :locale => 'en', :use_month_names => Date
::MONTHNAMES)
91 def test_select_month_translates_monthnames
92 I18n
.expects(:translate).with(:'date.month_names', :locale => 'en').returns Date
::MONTHNAMES
93 select_month(8, :locale => 'en')
96 def test_select_month_given_use_short_month_option_translates_abbr_monthnames
97 I18n
.expects(:translate).with(:'date.abbr_month_names', :locale => 'en').returns Date
::ABBR_MONTHNAMES
98 select_month(8, :locale => 'en', :use_short_month => true)
101 # date_or_time_select
103 def test_date_or_time_select_given_an_order_options_does_not_translate_order
104 I18n
.expects(:translate).never
105 datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en')
108 def test_date_or_time_select_given_no_order_options_translates_order
109 I18n
.expects(:translate).with(:'date.order', :locale => 'en').returns
[:year, :month, :day]
110 datetime_select('post', 'updated_at', :locale => 'en')