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
# distance_of_time_in_words
13
def test_distance_of_time_in_words_calls_i18n
14
{ # with include_seconds
15
[2.seconds, true] => [:'less_than_x_seconds', 5],
16
[9.seconds, true] => [:'less_than_x_seconds', 10],
17
[19.seconds, true] => [:'less_than_x_seconds', 20],
18
[30.seconds, true] => [:'half_a_minute', nil],
19
[59.seconds, true] => [:'less_than_x_minutes', 1],
20
[60.seconds, true] => [:'x_minutes', 1],
22
# without include_seconds
23
[29.seconds, false] => [:'less_than_x_minutes', 1],
24
[60.seconds, false] => [:'x_minutes', 1],
25
[44.minutes, false] => [:'x_minutes', 44],
26
[61.minutes, false] => [:'about_x_hours', 1],
27
[24.hours, false] => [:'x_days', 1],
28
[30.days, false] => [:'about_x_months', 1],
29
[60.days, false] => [:'x_months', 2],
30
[1.year, false] => [:'about_x_years', 1],
31
[3.years + 6.months, false] => [:'over_x_years', 3],
32
[3.years + 10.months, false] => [:'almost_x_years', 4]
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')
74
class DateHelperSelectTagsI18nTests < Test::Unit::TestCase
75
include ActionView::Helpers::DateHelper
79
@prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'}
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
def test_date_or_time_select_translates_prompts
102
@prompt_defaults.each do |key, prompt|
103
I18n.expects(:translate).with(('datetime.prompts.' + key.to_s).to_sym, :locale => 'en').returns prompt
106
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
107
datetime_select('post', 'updated_at', :locale => 'en', :include_seconds => true, :prompt => true)
110
# date_or_time_select
112
def test_date_or_time_select_given_an_order_options_does_not_translate_order
113
I18n.expects(:translate).never
114
datetime_select('post', 'updated_at', :order => [:year, :month, :day], :locale => 'en')
117
def test_date_or_time_select_given_no_order_options_translates_order
118
I18n.expects(:translate).with(:'date.order', :locale => 'en').returns [:year, :month, :day]
119
datetime_select('post', 'updated_at', :locale => 'en')