~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/template/date_helper_i18n_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'abstract_unit'
2
 
 
3
 
class DateHelperDistanceOfTimeInWordsI18nTests < Test::Unit::TestCase
4
 
  include ActionView::Helpers::DateHelper
5
 
  attr_reader :request
6
 
 
7
 
  def setup
8
 
    @from = Time.mktime(2004, 6, 6, 21, 45, 0)
9
 
  end
10
 
 
11
 
  # distance_of_time_in_words
12
 
 
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],
21
 
 
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]
33
 
 
34
 
      }.each do |passed, expected|
35
 
      assert_distance_of_time_in_words_translates_key passed, expected
36
 
    end
37
 
  end
38
 
 
39
 
  def assert_distance_of_time_in_words_translates_key(passed, expected)
40
 
    diff, include_seconds = *passed
41
 
    key, count = *expected
42
 
    to = @from + diff
43
 
 
44
 
    options = {:locale => 'en', :scope => :'datetime.distance_in_words'}
45
 
    options[:count] = count if count
46
 
 
47
 
    I18n.expects(:t).with(key, options)
48
 
    distance_of_time_in_words(@from, to, include_seconds, :locale => 'en')
49
 
  end
50
 
 
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' 
66
 
 
67
 
      }.each do |args, expected|
68
 
      key, count = *args
69
 
      assert_equal expected, I18n.t(key, :count => count, :scope => 'datetime.distance_in_words')
70
 
    end
71
 
  end
72
 
end
73
 
 
74
 
class DateHelperSelectTagsI18nTests < Test::Unit::TestCase
75
 
  include ActionView::Helpers::DateHelper
76
 
  attr_reader :request
77
 
 
78
 
  def setup
79
 
    @prompt_defaults = {:year => 'Year', :month => 'Month', :day => 'Day', :hour => 'Hour', :minute => 'Minute', :second => 'Seconds'}
80
 
 
81
 
    I18n.stubs(:translate).with(:'date.month_names', :locale => 'en').returns Date::MONTHNAMES
82
 
  end
83
 
 
84
 
  # select_month
85
 
 
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)
89
 
  end
90
 
 
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')
94
 
  end
95
 
 
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)
99
 
  end
100
 
 
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
104
 
    end
105
 
 
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)
108
 
  end
109
 
 
110
 
  # date_or_time_select
111
 
 
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')
115
 
  end
116
 
 
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')
120
 
  end
121
 
end