forked from butsjoh/localized_dates
/
localized_dates_spec.rb
57 lines (50 loc) · 2.3 KB
/
localized_dates_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require File.dirname(__FILE__) + '/spec_helper'
describe "Date and Time localization" do
before(:each) do
# load locale files
locales_dir = File.dirname(__FILE__) + "/../lib/templates/locales"
I18n.load_path << "#{locales_dir}/en.rb"
I18n.load_path << "#{locales_dir}/en.yml"
# set up defaults
@date_defaults = { :default => "%Y-%m-%d",
:short => "%e %b",
:long => "%B %e, %Y",
:long_ordinal => lambda { |date| "%B #{date.day.ordinalize}, %Y" } }
@time_defaults = { :default => "%a %b %d %H:%M:%S %Z %Y",
:time => "%H:%M",
:short => "%d %b %H:%M",
:long => "%B %d, %Y %H:%M",
:long_ordinal => lambda { |time| "%B #{time.day.ordinalize}, %Y %H:%M" } }
@datetime_defaults = { :default => "%Y-%m-%dT%H:%M:%S%Z" }
@time_with_zone_defaults = {
:default => lambda { |time| "%Y-%m-%d %H:%M:%S #{time.formatted_offset(false, 'UTC')}" }
}
end
describe Date do
it "should translate format when to_s is called" do
I18n.should_receive(:translate).with(:'date.formats', :raise => true).and_return(@date_defaults)
Date.today.to_s(:short)
end
end
describe Time do
it "should translate format when to_s is called" do
I18n.should_receive(:translate).with(:'time.formats', :raise => true).and_return(@time_defaults)
Time.now.to_s(:short)
end
end
describe DateTime do
it "should translate format when to_s is called" do
I18n.should_receive(:translate).with(:'time.formats', :raise => true).and_return(@time_defaults)
I18n.should_receive(:translate).with(:'time.datetime.formats', :raise => true).and_return(@datetime_defaults)
DateTime.now.to_s(:short)
end
end
describe ActiveSupport::TimeWithZone do
it "should translate format when to_s is called" do
I18n.should_receive(:translate).with(:'time.formats', :raise => true).and_return(@time_defaults)
I18n.should_receive(:translate).with(:'time.time_with_zone.formats', :raise => true).and_return(@time_with_zone_defaults)
t, z = Time.utc(2000, 1, 1, 0), ActiveSupport::TimeZone['UTC']
ActiveSupport::TimeWithZone.new(t, z).to_s(:short)
end
end
end