aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/duration_test.rb50
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb8
-rw-r--r--activesupport/test/i18n_test.rb16
-rw-r--r--activesupport/test/inflector_test_cases.rb2
-rw-r--r--activesupport/test/json/encoding_test.rb12
-rw-r--r--activesupport/test/memoizable_test.rb5
6 files changed, 93 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb
index f802ed8760..80cc6d25d3 100644
--- a/activesupport/test/core_ext/duration_test.rb
+++ b/activesupport/test/core_ext/duration_test.rb
@@ -30,7 +30,57 @@ class DurationTest < Test::Unit::TestCase
end
end
+ def test_fractional_weeks
+ assert_equal (86400 * 7) * 1.5, 1.5.weeks
+ assert_equal (86400 * 7) * 1.7, 1.7.weeks
+ end
+
+ def test_fractional_days
+ assert_equal 86400 * 1.5, 1.5.days
+ assert_equal 86400 * 1.7, 1.7.days
+ end
+
uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do
+ def test_since_and_ago_with_fractional_days
+ Time.stubs(:now).returns Time.local(2000)
+ # since
+ assert_equal 36.hours.since, 1.5.days.since
+ assert_equal((24 * 1.7).hours.since, 1.7.days.since)
+ # ago
+ assert_equal 36.hours.ago, 1.5.days.ago
+ assert_equal((24 * 1.7).hours.ago, 1.7.days.ago)
+ end
+
+ def test_since_and_ago_with_fractional_weeks
+ Time.stubs(:now).returns Time.local(2000)
+ # since
+ assert_equal((7 * 36).hours.since, 1.5.weeks.since)
+ assert_equal((7 * 24 * 1.7).hours.since, 1.7.weeks.since)
+ # ago
+ assert_equal((7 * 36).hours.ago, 1.5.weeks.ago)
+ assert_equal((7 * 24 * 1.7).hours.ago, 1.7.weeks.ago)
+ end
+
+ def test_deprecated_fractional_years
+ years_re = /Fractional years are not respected\. Convert value to integer before calling #years\./
+ assert_deprecated(years_re){1.0.years}
+ assert_deprecated(years_re){1.5.years}
+ assert_not_deprecated{1.years}
+ assert_deprecated(years_re){1.0.year}
+ assert_deprecated(years_re){1.5.year}
+ assert_not_deprecated{1.year}
+ end
+
+ def test_deprecated_fractional_months
+ months_re = /Fractional months are not respected\. Convert value to integer before calling #months\./
+ assert_deprecated(months_re){1.5.months}
+ assert_deprecated(months_re){1.0.months}
+ assert_not_deprecated{1.months}
+ assert_deprecated(months_re){1.5.month}
+ assert_deprecated(months_re){1.0.month}
+ assert_not_deprecated{1.month}
+ end
+
def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
Time.zone_default = nil
with_env_tz 'US/Eastern' do
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 8ceaedc7f4..11ec1c6cd6 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -381,7 +381,11 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1)
assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4)
assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3)
+ assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5)
+ assert_equal Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7)
assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5)
+ assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5)
+ assert_equal Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7)
assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7)
assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5)
assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5)
@@ -399,7 +403,11 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1)
assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4)
assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3)
+ assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5)
+ assert_equal Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7)
assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5)
+ assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5)
+ assert_equal Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7)
assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7)
assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11)
assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5)
diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb
index 4b17e3c523..db5bd5e088 100644
--- a/activesupport/test/i18n_test.rb
+++ b/activesupport/test/i18n_test.rb
@@ -72,4 +72,20 @@ class I18nTest < Test::Unit::TestCase
def test_time_pm
assert_equal 'pm', I18n.translate(:'time.pm')
end
+
+ def test_sentence_connector
+ assert_equal 'and', I18n.translate(:'support.array.sentence_connector')
+ end
+
+ def test_skip_last_comma
+ assert_equal false, I18n.translate(:'support.array.skip_last_comma')
+ end
+
+ def test_to_sentence
+ assert_equal 'a, b, and c', %w[a b c].to_sentence
+ I18n.backend.store_translations 'en-US', :support => { :array => { :skip_last_comma => true } }
+ assert_equal 'a, b and c', %w[a b c].to_sentence
+ ensure
+ I18n.backend.store_translations 'en-US', :support => { :array => { :skip_last_comma => false } }
+ end
end
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index fc7a35f859..3aa18ca781 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
module InflectorTestCases
SingularToPlural = {
"search" => "searches",
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 497f028369..c070e0d9ed 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -100,6 +100,18 @@ class TestJSONEncoding < Test::Unit::TestCase
ActiveSupport.use_standard_json_time_format = false
end
+ def test_nested_hash_with_float
+ assert_nothing_raised do
+ hash = {
+ "CHI" => {
+ :dislay_name => "chicago",
+ :latitude => 123.234
+ }
+ }
+ result = hash.to_json
+ end
+ end
+
protected
def object_keys(json_object)
diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb
index 135d56f14a..a78ebd9425 100644
--- a/activesupport/test/memoizable_test.rb
+++ b/activesupport/test/memoizable_test.rb
@@ -100,6 +100,11 @@ uses_mocha 'Memoizable' do
def test_memoization_with_punctuation
assert_equal true, @person.name?
+
+ assert_nothing_raised(NameError) do
+ @person.memoize_all
+ @person.unmemoize_all
+ end
end
def test_memoization_with_nil_value