@@ -15,39 +15,49 @@ def method_missing(*args, &block)
15
15
end
16
16
17
17
context "given a Date or a Time" do
18
- it "should return a localized Date or Time with long format" do
19
- t = Time . now
20
- expect ( I18n ) . to receive ( :localize ) . with ( t , { format : : long} ) { "Just Now!" }
21
- expect ( pretty_format ( t ) ) . to eq "Just Now! "
18
+ let ( :t ) { Time . utc ( 1985 , "feb" , 28 , 20 , 15 , 1 ) }
19
+
20
+ it "formats it with the default long format" do
21
+ expect ( pretty_format ( t ) ) . to eq "February 28, 1985 20:15 "
22
22
end
23
23
24
- context "actually do the formatting" do
25
- it "should actually do the formatting" do
26
- t = Time . utc ( 1985 , "feb" , 28 , 20 , 15 , 1 )
27
- expect ( pretty_format ( t ) ) . to eq "February 28, 1985 20:15"
24
+ it "formats it with a customized long format" do
25
+ with_translation time : { formats : { long : "%B %d, %Y, %l:%M%P" } } do
26
+ expect ( pretty_format ( t ) ) . to eq "February 28, 1985, 8:15pm"
28
27
end
28
+ end
29
29
30
- context "apply custom localize format" do
31
- around do |example |
32
- previous_localize_format = ActiveAdmin . application . localize_format
33
- ActiveAdmin . application . localize_format = :short
34
- example . call
35
- ActiveAdmin . application . localize_format = previous_localize_format
36
- end
37
- it "should actually do the formatting" do
38
- t = Time . utc ( 1985 , "feb" , 28 , 20 , 15 , 1 )
30
+ context "with a custom localize format" do
31
+ around do |example |
32
+ previous_localize_format = ActiveAdmin . application . localize_format
33
+ ActiveAdmin . application . localize_format = :short
34
+ example . call
35
+ ActiveAdmin . application . localize_format = previous_localize_format
36
+ end
39
37
40
- expect ( pretty_format ( t ) ) . to eq "28 Feb 20:15"
41
- end
38
+ it "formats it with the default custom format" do
39
+ expect ( pretty_format ( t ) ) . to eq "28 Feb 20:15"
42
40
end
43
41
44
- context " with non-English locale " do
45
- around do | example |
46
- I18n . with_locale ( :es ) { example . call }
42
+ it "formats it with i18n custom format " do
43
+ with_translation time : { formats : { short : "%-m %d %Y" } } do
44
+ expect ( pretty_format ( t ) ) . to eq "2 28 1985"
47
45
end
48
- it "should return a localized Date or Time with long format for non-english locale" do
49
- t = Time . utc ( 1985 , "feb" , 28 , 20 , 15 , 1 )
50
- expect ( pretty_format ( t ) ) . to eq "28 de febrero de 1985 20:15"
46
+ end
47
+ end
48
+
49
+ context "with non-English locale" do
50
+ around do |example |
51
+ I18n . with_locale ( :es ) { example . call }
52
+ end
53
+
54
+ it "formats it with the default long format" do
55
+ expect ( pretty_format ( t ) ) . to eq "28 de febrero de 1985 20:15"
56
+ end
57
+
58
+ it "formats it with a customized long format" do
59
+ with_translation time : { formats : { long : "El %d de %B de %Y a las %H horas y %M minutos" } } do
60
+ expect ( pretty_format ( t ) ) . to eq "El 28 de febrero de 1985 a las 20 horas y 15 minutos"
51
61
end
52
62
end
53
63
end
0 commit comments