a866f90c5443ee83cb0d3a5ebdf83ba22266e7a8
[packages/precise/mcollective.git] / lib / mcollective / vendor / i18n / lib / i18n / tests / localization / date.rb
1 # encoding: utf-8
2
3 module I18n
4   module Tests
5     module Localization
6       module Date
7         def setup
8           super
9           setup_date_translations
10           @date = ::Date.new(2008, 3, 1)
11         end
12
13         test "localize Date: given the short format it uses it" do
14           # TODO should be Mrz, shouldn't it?
15           assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
16         end
17
18         test "localize Date: given the long format it uses it" do
19           assert_equal '01. März 2008', I18n.l(@date, :format => :long, :locale => :de)
20         end
21
22         test "localize Date: given the default format it uses it" do
23           assert_equal '01.03.2008', I18n.l(@date, :format => :default, :locale => :de)
24         end
25
26         test "localize Date: given a day name format it returns the correct day name" do
27           assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
28         end
29
30         test "localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
31           assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
32         end
33
34         test "localize Date: given a month name format it returns the correct month name" do
35           assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
36         end
37
38         test "localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
39           # TODO should be Mrz, shouldn't it?
40           assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
41         end
42
43         test "localize Date: given an unknown format it does not fail" do
44           assert_nothing_raised { I18n.l(@date, :format => '%x') }
45         end
46
47         test "localize Date: given nil it raises I18n::ArgumentError" do
48           assert_raise(I18n::ArgumentError) { I18n.l(nil) }
49         end
50
51         test "localize Date: given a plain Object it raises I18n::ArgumentError" do
52           assert_raise(I18n::ArgumentError) { I18n.l(Object.new) }
53         end
54
55         test "localize Date: given a format is missing it raises I18n::MissingTranslationData" do
56           assert_raise(I18n::MissingTranslationData) { I18n.l(@date, :format => :missing) }
57         end
58
59         test "localize Date: it does not alter the format string" do
60           assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
61           assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
62         end
63
64         protected
65
66           def setup_date_translations
67             I18n.backend.store_translations :de, {
68               :date => {
69                 :formats => {
70                   :default => "%d.%m.%Y",
71                   :short => "%d. %b",
72                   :long => "%d. %B %Y",
73                 },
74                 :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
75                 :abbr_day_names => %w(So Mo Di Mi Do Fr  Sa),
76                 :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
77                 :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil)
78               }
79             }
80           end
81       end
82     end
83   end
84 end