Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

once again fixing DateTime.inspect assertions

  • Loading branch information...
commit a63fb7fdfbd97cf4de02fad2b60f14a75c079ba2 1 parent ad3629a
@svenfuchs authored
View
3  ci/Gemfile.all.lock
@@ -37,3 +37,6 @@ DEPENDENCIES
rufus-tokyo
sqlite3-ruby
test_declarative
+
+METADATA
+ version: 1.0.6
View
21 ci/Gemfile.rails-2.3.x.lock
@@ -0,0 +1,21 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (2.3.10)
+ mocha (0.9.9)
+ rake
+ rake (0.8.7)
+ sqlite3-ruby (1.3.2)
+ test_declarative (0.0.4)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport (~> 2.3)
+ mocha
+ sqlite3-ruby
+ test_declarative
+
+METADATA
+ version: 1.0.6
View
3  ci/Gemfile.rails-3.x.lock
@@ -16,3 +16,6 @@ DEPENDENCIES
mocha
sqlite3-ruby
test_declarative
+
+METADATA
+ version: 1.0.6
View
2  lib/i18n/config.rb
@@ -41,7 +41,7 @@ def available_locales
# Sets the available locales.
def available_locales=(locales)
- @@available_locales = Array(locales).map {|locale| locale.to_sym}
+ @@available_locales = Array(locales).map { |locale| locale.to_sym }
@@available_locales = nil if @@available_locales.empty?
end
View
41 lib/i18n/tests/localization/procs.rb
@@ -1,17 +1,5 @@
# encoding: utf-8
-class DateTime
- def inspect
- strftime('%a, %d %b %Y %H:%M:%S %Z')
- end
-end
-
-class Date
- def inspect
- strftime('%a, %d %b %Y')
- end
-end
-
module I18n
module Tests
module Localization
@@ -52,44 +40,57 @@ module Procs
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
- assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
end
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
setup_time_proc_translations
datetime = ::DateTime.new(2008, 3, 1, 6)
- assert_equal '[Sat, 01 Mar 2008 06:00:00 +0000, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
end
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
setup_time_proc_translations
time = ::Time.utc(2008, 3, 1, 6, 0)
- assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
+ assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru)
end
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
setup_time_proc_translations
time = ::Time.utc(2008, 3, 1, 6, 0)
options = { :foo => 'foo' }
- assert_equal [time, options].inspect, I18n.l(time, options.merge(:format => :proc, :locale => :ru))
+ assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
end
protected
- def filter_args(*args)
- args.map { |arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
+ def inspect_args(args)
+ args = args.map do |arg|
+ case arg
+ when ::Time, ::DateTime
+ arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
+ when ::Date
+ arg.strftime('%a, %d %b %Y')
+ when Hash
+ arg.delete(:fallback)
+ arg.inspect
+ else
+ arg.inspect
+ end
+ end
+ "[#{args.join(', ')}]"
end
def setup_time_proc_translations
I18n.backend.store_translations :ru, {
:time => {
:formats => {
- :proc => lambda { |*args| filter_args(*args) }
+ :proc => lambda { |*args| inspect_args(args) }
}
},
:date => {
:formats => {
- :proc => lambda { |*args| filter_args(*args) }
+ :proc => lambda { |*args| inspect_args(args) }
},
:'day_names' => lambda { |key, options|
(options[:format] =~ /^%A/) ?
View
3  test/test_helper.rb
@@ -9,8 +9,7 @@
# to load I18n using the gem method. Instead, we want to test the local library of course.
alias :gem_for_ruby_19 :gem # for 1.9. gives a super ugly seg fault otherwise
def gem(gem_name, *version_requirements)
- puts("skipping loading the i18n gem ...") && return if gem_name =='i18n'
- super(gem_name, *version_requirements)
+ gem_name =='i18n' ? puts("skipping loading the i18n gem ...") : super
end
require 'bundler/setup'
Please sign in to comment.
Something went wrong with that request. Please try again.