aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/abstract_unit.rb49
-rw-r--r--activesupport/test/caching_test.rb44
-rw-r--r--activesupport/test/clean_backtrace_test.rb47
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb24
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb68
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb112
-rw-r--r--activesupport/test/core_ext/duration_test.rb120
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb11
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb11
-rw-r--r--activesupport/test/core_ext/module/model_naming_test.rb8
-rw-r--r--activesupport/test/core_ext/module_test.rb11
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb32
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb4
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb146
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb138
-rw-r--r--activesupport/test/dependencies_test.rb10
-rw-r--r--activesupport/test/deprecation_test.rb26
-rw-r--r--activesupport/test/i18n_test.rb12
-rw-r--r--activesupport/test/inflector_test.rb6
-rw-r--r--activesupport/test/inflector_test_cases.rb15
-rw-r--r--activesupport/test/json/encoding_test.rb18
-rw-r--r--activesupport/test/memoizable_test.rb346
-rw-r--r--activesupport/test/message_encryptor_test.rb46
-rw-r--r--activesupport/test/message_verifier_test.rb25
-rw-r--r--activesupport/test/multibyte_unicode_database_test.rb6
-rw-r--r--activesupport/test/option_merger_test.rb8
-rw-r--r--activesupport/test/ordered_hash_test.rb12
-rw-r--r--activesupport/test/test_test.rb19
-rw-r--r--activesupport/test/time_zone_test.rb80
29 files changed, 810 insertions, 644 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb
index 9d8c252f86..ac362d14c8 100644
--- a/activesupport/test/abstract_unit.rb
+++ b/activesupport/test/abstract_unit.rb
@@ -1,44 +1,20 @@
-# encoding: utf-8
-
+require 'rubygems'
require 'test/unit'
+gem 'mocha', '>= 0.9.3'
+require 'mocha'
$:.unshift "#{File.dirname(__FILE__)}/../lib"
-$:.unshift File.dirname(__FILE__)
require 'active_support'
+require 'active_support/test_case'
-if RUBY_VERSION < '1.9'
- $KCODE = 'UTF8'
-end
-
-def uses_gem(gem_name, test_name, version = '> 0')
- require 'rubygems'
- gem gem_name.to_s, version
- require gem_name.to_s
+def uses_memcached(test_name)
+ require 'memcache'
+ MemCache.new('localhost').stats
yield
-rescue LoadError
- $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
-end
-
-# Wrap tests that use Mocha and skip if unavailable.
-unless defined? uses_mocha
- def uses_mocha(test_name, &block)
- uses_gem('mocha', test_name, '>= 0.5.5', &block)
- end
-end
-
-unless defined? uses_memcached
- def uses_memcached(test_name)
- require 'memcache'
- MemCache.new('localhost').stats
- yield
- rescue MemCache::MemCacheError
- $stderr.puts "Skipping #{test_name} tests. Start memcached and try again."
- end
+rescue MemCache::MemCacheError
+ $stderr.puts "Skipping #{test_name} tests. Start memcached and try again."
end
-# Show backtraces for deprecated behavior for quicker cleanup.
-ActiveSupport::Deprecation.debug = true
-
def with_kcode(code)
if RUBY_VERSION < '1.9'
begin
@@ -51,3 +27,10 @@ def with_kcode(code)
yield
end
end
+
+# Show backtraces for deprecated behavior for quicker cleanup.
+ActiveSupport::Deprecation.debug = true
+
+if RUBY_VERSION < '1.9'
+ $KCODE = 'UTF8'
+end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index cc371b3a7b..d8506de986 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -45,29 +45,27 @@ class CacheStoreSettingTest < Test::Unit::TestCase
end
end
-uses_mocha 'high-level cache store tests' do
- class CacheStoreTest < Test::Unit::TestCase
- def setup
- @cache = ActiveSupport::Cache.lookup_store(:memory_store)
- end
+class CacheStoreTest < Test::Unit::TestCase
+ def setup
+ @cache = ActiveSupport::Cache.lookup_store(:memory_store)
+ end
- def test_fetch_without_cache_miss
- @cache.stubs(:read).with('foo', {}).returns('bar')
- @cache.expects(:write).never
- assert_equal 'bar', @cache.fetch('foo') { 'baz' }
- end
+ def test_fetch_without_cache_miss
+ @cache.stubs(:read).with('foo', {}).returns('bar')
+ @cache.expects(:write).never
+ assert_equal 'bar', @cache.fetch('foo') { 'baz' }
+ end
- def test_fetch_with_cache_miss
- @cache.stubs(:read).with('foo', {}).returns(nil)
- @cache.expects(:write).with('foo', 'baz', {})
- assert_equal 'baz', @cache.fetch('foo') { 'baz' }
- end
+ def test_fetch_with_cache_miss
+ @cache.stubs(:read).with('foo', {}).returns(nil)
+ @cache.expects(:write).with('foo', 'baz', {})
+ assert_equal 'baz', @cache.fetch('foo') { 'baz' }
+ end
- def test_fetch_with_forced_cache_miss
- @cache.expects(:read).never
- @cache.expects(:write).with('foo', 'bar', :force => true)
- @cache.fetch('foo', :force => true) { 'bar' }
- end
+ def test_fetch_with_forced_cache_miss
+ @cache.expects(:read).never
+ @cache.expects(:write).with('foo', 'bar', :force => true)
+ @cache.fetch('foo', :force => true) { 'bar' }
end
end
@@ -160,6 +158,12 @@ uses_memcached 'memcached backed store' do
@cache.read('foo').gsub!(/.*/, 'baz')
assert_equal 'bar', @cache.read('foo')
end
+
+ def test_write_should_return_true_on_success
+ result = @cache.write('foo', 'bar')
+ assert_equal 'bar', @cache.read('foo') # make sure 'foo' was written
+ assert result
+ end
end
class CompressedMemCacheStore < Test::Unit::TestCase
diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb
new file mode 100644
index 0000000000..ddbc258df1
--- /dev/null
+++ b/activesupport/test/clean_backtrace_test.rb
@@ -0,0 +1,47 @@
+require 'abstract_unit'
+
+class BacktraceCleanerFilterTest < ActiveSupport::TestCase
+ def setup
+ @bc = ActiveSupport::BacktraceCleaner.new
+ @bc.add_filter { |line| line.gsub("/my/prefix", '') }
+ end
+
+ test "backtrace should not contain prefix when it has been filtered out" do
+ assert_equal "/my/class.rb", @bc.clean([ "/my/prefix/my/class.rb" ]).first
+ end
+
+ test "backtrace should contain unaltered lines if they dont match a filter" do
+ assert_equal "/my/other_prefix/my/class.rb", @bc.clean([ "/my/other_prefix/my/class.rb" ]).first
+ end
+
+ test "backtrace should filter all lines in a backtrace" do
+ assert_equal \
+ ["/my/class.rb", "/my/module.rb"],
+ @bc.clean([ "/my/prefix/my/class.rb", "/my/prefix/my/module.rb" ])
+ end
+end
+
+class BacktraceCleanerSilencerTest < ActiveSupport::TestCase
+ def setup
+ @bc = ActiveSupport::BacktraceCleaner.new
+ @bc.add_silencer { |line| line =~ /mongrel/ }
+ end
+
+ test "backtrace should not contain lines that match the silencer" do
+ assert_equal \
+ [ "/other/class.rb" ],
+ @bc.clean([ "/mongrel/class.rb", "/other/class.rb", "/mongrel/stuff.rb" ])
+ end
+end
+
+class BacktraceCleanerFilterAndSilencerTest < ActiveSupport::TestCase
+ def setup
+ @bc = ActiveSupport::BacktraceCleaner.new
+ @bc.add_filter { |line| line.gsub("/mongrel", "") }
+ @bc.add_silencer { |line| line =~ /mongrel/ }
+ end
+
+ test "backtrace should not silence lines that has first had their silence hook filtered out" do
+ assert_equal [ "/class.rb" ], @bc.clean([ "/mongrel/class.rb" ])
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 62a1f61d53..01b243cdb5 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -15,17 +15,13 @@ class ArrayExtAccessTests < Test::Unit::TestCase
end
def test_second_through_tenth
- array = (1..10).to_a
+ array = (1..42).to_a
assert_equal array[1], array.second
assert_equal array[2], array.third
assert_equal array[3], array.fourth
assert_equal array[4], array.fifth
- assert_equal array[5], array.sixth
- assert_equal array[6], array.seventh
- assert_equal array[7], array.eighth
- assert_equal array[8], array.ninth
- assert_equal array[9], array.tenth
+ assert_equal array[41], array.forty_two
end
end
@@ -294,16 +290,14 @@ class ArrayExtractOptionsTests < Test::Unit::TestCase
end
end
-uses_mocha "ArrayExtRandomTests" do
- class ArrayExtRandomTests < Test::Unit::TestCase
- def test_random_element_from_array
- assert_nil [].rand
+class ArrayExtRandomTests < Test::Unit::TestCase
+ def test_random_element_from_array
+ assert_nil [].rand
- Kernel.expects(:rand).with(1).returns(0)
- assert_equal 'x', ['x'].rand
+ Kernel.expects(:rand).with(1).returns(0)
+ assert_equal 'x', ['x'].rand
- Kernel.expects(:rand).with(3).returns(1)
- assert_equal 2, [1, 2, 3].rand
- end
+ Kernel.expects(:rand).with(3).returns(1)
+ assert_equal 2, [1, 2, 3].rand
end
end
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index b53c754780..2cedf65153 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -210,50 +210,46 @@ class DateExtCalculationsTest < Test::Unit::TestCase
end
end
- uses_mocha 'past?, today? and future?' do
- def test_today
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, Date.new(1999, 12, 31).today?
- assert_equal true, Date.new(2000,1,1).today?
- assert_equal false, Date.new(2000,1,2).today?
- end
-
- def test_past
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal true, Date.new(1999, 12, 31).past?
- assert_equal false, Date.new(2000,1,1).past?
- assert_equal false, Date.new(2000,1,2).past?
- end
-
- def test_future
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, Date.new(1999, 12, 31).future?
- assert_equal false, Date.new(2000,1,1).future?
- assert_equal true, Date.new(2000,1,2).future?
+ def test_today
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, Date.new(1999, 12, 31).today?
+ assert_equal true, Date.new(2000,1,1).today?
+ assert_equal false, Date.new(2000,1,2).today?
+ end
+
+ def test_past
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal true, Date.new(1999, 12, 31).past?
+ assert_equal false, Date.new(2000,1,1).past?
+ assert_equal false, Date.new(2000,1,2).past?
+ end
+
+ def test_future
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, Date.new(1999, 12, 31).future?
+ assert_equal false, Date.new(2000,1,1).future?
+ assert_equal true, Date.new(2000,1,2).future?
+ end
+
+ def test_current_returns_date_today_when_zone_default_not_set
+ with_env_tz 'US/Central' do
+ Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
+ assert_equal Date.new(1999, 12, 31), Date.today
+ assert_equal Date.new(1999, 12, 31), Date.current
end
end
- uses_mocha 'TestDateCurrent' do
- def test_current_returns_date_today_when_zone_default_not_set
+ def test_current_returns_time_zone_today_when_zone_default_set
+ silence_warnings do # silence warnings raised by tzinfo gem
+ Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
with_env_tz 'US/Central' do
Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
assert_equal Date.new(1999, 12, 31), Date.today
- assert_equal Date.new(1999, 12, 31), Date.current
- end
- end
-
- def test_current_returns_time_zone_today_when_zone_default_set
- silence_warnings do # silence warnings raised by tzinfo gem
- Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- with_env_tz 'US/Central' do
- Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
- assert_equal Date.new(1999, 12, 31), Date.today
- assert_equal Date.new(2000, 1, 1), Date.current
- end
+ assert_equal Date.new(2000, 1, 1), Date.current
end
- ensure
- Time.zone_default = nil
end
+ ensure
+ Time.zone_default = nil
end
protected
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index be3cd8b5d6..45eb52c720 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -207,69 +207,65 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase
assert_match(/^2080-02-28T15:15:10-06:?00$/, DateTime.civil(2080, 2, 28, 15, 15, 10, -0.25).xmlschema)
end
- uses_mocha 'Test DateTime past?, today? and future?' do
- def test_today_with_offset
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, DateTime.civil(1999,12,31,23,59,59, Rational(-18000, 86400)).today?
- assert_equal true, DateTime.civil(2000,1,1,0,0,0, Rational(-18000, 86400)).today?
- assert_equal true, DateTime.civil(2000,1,1,23,59,59, Rational(-18000, 86400)).today?
- assert_equal false, DateTime.civil(2000,1,2,0,0,0, Rational(-18000, 86400)).today?
- end
-
- def test_today_without_offset
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, DateTime.civil(1999,12,31,23,59,59).today?
- assert_equal true, DateTime.civil(2000,1,1,0).today?
- assert_equal true, DateTime.civil(2000,1,1,23,59,59).today?
- assert_equal false, DateTime.civil(2000,1,2,0).today?
- end
-
- def test_past_with_offset
- DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
- assert_equal true, DateTime.civil(2005,2,10,15,30,44, Rational(-18000, 86400)).past?
- assert_equal false, DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)).past?
- assert_equal false, DateTime.civil(2005,2,10,15,30,46, Rational(-18000, 86400)).past?
- end
-
- def test_past_without_offset
- DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
- assert_equal true, DateTime.civil(2005,2,10,20,30,44).past?
- assert_equal false, DateTime.civil(2005,2,10,20,30,45).past?
- assert_equal false, DateTime.civil(2005,2,10,20,30,46).past?
- end
-
- def test_future_with_offset
- DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
- assert_equal false, DateTime.civil(2005,2,10,15,30,44, Rational(-18000, 86400)).future?
- assert_equal false, DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)).future?
- assert_equal true, DateTime.civil(2005,2,10,15,30,46, Rational(-18000, 86400)).future?
- end
-
- def test_future_without_offset
- DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
- assert_equal false, DateTime.civil(2005,2,10,20,30,44).future?
- assert_equal false, DateTime.civil(2005,2,10,20,30,45).future?
- assert_equal true, DateTime.civil(2005,2,10,20,30,46).future?
- end
+ def test_today_with_offset
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, DateTime.civil(1999,12,31,23,59,59, Rational(-18000, 86400)).today?
+ assert_equal true, DateTime.civil(2000,1,1,0,0,0, Rational(-18000, 86400)).today?
+ assert_equal true, DateTime.civil(2000,1,1,23,59,59, Rational(-18000, 86400)).today?
+ assert_equal false, DateTime.civil(2000,1,2,0,0,0, Rational(-18000, 86400)).today?
+ end
+
+ def test_today_without_offset
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, DateTime.civil(1999,12,31,23,59,59).today?
+ assert_equal true, DateTime.civil(2000,1,1,0).today?
+ assert_equal true, DateTime.civil(2000,1,1,23,59,59).today?
+ assert_equal false, DateTime.civil(2000,1,2,0).today?
+ end
+
+ def test_past_with_offset
+ DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
+ assert_equal true, DateTime.civil(2005,2,10,15,30,44, Rational(-18000, 86400)).past?
+ assert_equal false, DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)).past?
+ assert_equal false, DateTime.civil(2005,2,10,15,30,46, Rational(-18000, 86400)).past?
end
- uses_mocha 'TestDateTimeCurrent' do
- def test_current_returns_date_today_when_zone_default_not_set
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns Time.local(1999, 12, 31, 23, 59, 59)
- assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current
- end
+ def test_past_without_offset
+ DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
+ assert_equal true, DateTime.civil(2005,2,10,20,30,44).past?
+ assert_equal false, DateTime.civil(2005,2,10,20,30,45).past?
+ assert_equal false, DateTime.civil(2005,2,10,20,30,46).past?
+ end
+
+ def test_future_with_offset
+ DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
+ assert_equal false, DateTime.civil(2005,2,10,15,30,44, Rational(-18000, 86400)).future?
+ assert_equal false, DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)).future?
+ assert_equal true, DateTime.civil(2005,2,10,15,30,46, Rational(-18000, 86400)).future?
+ end
+
+ def test_future_without_offset
+ DateTime.stubs(:current).returns(DateTime.civil(2005,2,10,15,30,45, Rational(-18000, 86400)))
+ assert_equal false, DateTime.civil(2005,2,10,20,30,44).future?
+ assert_equal false, DateTime.civil(2005,2,10,20,30,45).future?
+ assert_equal true, DateTime.civil(2005,2,10,20,30,46).future?
+ end
+
+ def test_current_returns_date_today_when_zone_default_not_set
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns Time.local(1999, 12, 31, 23, 59, 59)
+ assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current
end
+ end
- def test_current_returns_time_zone_today_when_zone_default_set
- Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns Time.local(1999, 12, 31, 23, 59, 59)
- assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current
- end
- ensure
- Time.zone_default = nil
+ def test_current_returns_time_zone_today_when_zone_default_set
+ Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns Time.local(1999, 12, 31, 23, 59, 59)
+ assert_equal DateTime.new(1999, 12, 31, 23, 59, 59, Rational(-18000, 86400)), DateTime.current
end
+ ensure
+ Time.zone_default = nil
end
def test_current_without_time_zone
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb
index 5cd52d8d79..3948006b42 100644
--- a/activesupport/test/core_ext/duration_test.rb
+++ b/activesupport/test/core_ext/duration_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-class DurationTest < Test::Unit::TestCase
+class DurationTest < ActiveSupport::TestCase
def test_inspect
assert_equal '1 month', 1.month.inspect
assert_equal '1 month and 1 day', (1.month + 1.day).inspect
@@ -40,78 +40,76 @@ class DurationTest < Test::Unit::TestCase
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_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_since_and_ago_with_fractional_weeks
+ 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
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)
+ assert_equal false, 5.seconds.since.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal Time.local(2000,1,1,0,0,5), 5.seconds.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}
+ assert_equal false, 5.seconds.ago.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal Time.local(1999,12,31,23,59,55), 5.seconds.ago
end
+ end
- def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
- Time.zone_default = nil
+ def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
+ silence_warnings do # silence warnings raised by tzinfo gem
+ Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
with_env_tz 'US/Eastern' do
Time.stubs(:now).returns Time.local(2000)
# since
- assert_equal false, 5.seconds.since.is_a?(ActiveSupport::TimeWithZone)
- assert_equal Time.local(2000,1,1,0,0,5), 5.seconds.since
+ assert_equal true, 5.seconds.since.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal Time.utc(2000,1,1,0,0,5), 5.seconds.since.time
+ assert_equal 'Eastern Time (US & Canada)', 5.seconds.since.time_zone.name
# ago
- assert_equal false, 5.seconds.ago.is_a?(ActiveSupport::TimeWithZone)
- assert_equal Time.local(1999,12,31,23,59,55), 5.seconds.ago
+ assert_equal true, 5.seconds.ago.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal Time.utc(1999,12,31,23,59,55), 5.seconds.ago.time
+ assert_equal 'Eastern Time (US & Canada)', 5.seconds.ago.time_zone.name
end
end
-
- def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
- silence_warnings do # silence warnings raised by tzinfo gem
- Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns Time.local(2000)
- # since
- assert_equal true, 5.seconds.since.is_a?(ActiveSupport::TimeWithZone)
- assert_equal Time.utc(2000,1,1,0,0,5), 5.seconds.since.time
- assert_equal 'Eastern Time (US & Canada)', 5.seconds.since.time_zone.name
- # ago
- assert_equal true, 5.seconds.ago.is_a?(ActiveSupport::TimeWithZone)
- assert_equal Time.utc(1999,12,31,23,59,55), 5.seconds.ago.time
- assert_equal 'Eastern Time (US & Canada)', 5.seconds.ago.time_zone.name
- end
- end
- ensure
- Time.zone_default = nil
- end
+ ensure
+ Time.zone_default = nil
end
protected
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index deb9b7544d..92db977a77 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -79,4 +79,15 @@ class EnumerableTests < Test::Unit::TestCase
assert ![ 1, 2 ].many? {|x| x > 1 }
assert [ 1, 2, 2 ].many? {|x| x > 1 }
end
+
+ def test_none
+ assert [].none?
+ assert [nil, false].none?
+ assert ![1].none?
+
+ assert [].none? {|x| x > 1 }
+ assert ![ 2 ].none? {|x| x > 1 }
+ assert ![ 1, 2 ].none? {|x| x > 1 }
+ assert [ 1, 1 ].none? {|x| x > 1 }
+ end
end
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 9537f486cb..30cbba26b0 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'builder'
class HashExtTest < Test::Unit::TestCase
def setup
@@ -358,12 +359,10 @@ class HashExtTest < Test::Unit::TestCase
assert_nothing_raised { original.except(:a) }
end
- uses_mocha 'except with expectation' do
- def test_except_with_mocha_expectation_on_original
- original = { :a => 'x', :b => 'y' }
- original.expects(:delete).never
- original.except(:a)
- end
+ def test_except_with_mocha_expectation_on_original
+ original = { :a => 'x', :b => 'y' }
+ original.expects(:delete).never
+ original.except(:a)
end
end
diff --git a/activesupport/test/core_ext/module/model_naming_test.rb b/activesupport/test/core_ext/module/model_naming_test.rb
index fc73fa5c36..d08349dd97 100644
--- a/activesupport/test/core_ext/module/model_naming_test.rb
+++ b/activesupport/test/core_ext/module/model_naming_test.rb
@@ -2,18 +2,18 @@ require 'abstract_unit'
class ModelNamingTest < Test::Unit::TestCase
def setup
- @name = ActiveSupport::ModelName.new('Post::TrackBack')
+ @model_name = ActiveSupport::ModelName.new('Post::TrackBack')
end
def test_singular
- assert_equal 'post_track_back', @name.singular
+ assert_equal 'post_track_back', @model_name.singular
end
def test_plural
- assert_equal 'post_track_backs', @name.plural
+ assert_equal 'post_track_backs', @model_name.plural
end
def test_partial_path
- assert_equal 'post/track_backs/track_back', @name.partial_path
+ assert_equal 'post/track_backs/track_back', @model_name.partial_path
end
end
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index 7fe5d0faee..886f692499 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -106,6 +106,17 @@ class ModuleTest < Test::Unit::TestCase
assert_equal invoice.customer_city, "Chicago"
end
+ def test_delegation_prefix_with_instance_variable
+ assert_raise ArgumentError do
+ Class.new do
+ def initialize(client)
+ @client = client
+ end
+ delegate :name, :address, :to => :@client, :prefix => true
+ end
+ end
+ end
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index e88dcb52d5..2f79b6f67f 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -247,3 +247,35 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase
[arg] + instance_exec('bar') { |v| [reverse, v] } }
end
end
+
+class ObjectTryTest < Test::Unit::TestCase
+ def setup
+ @string = "Hello"
+ end
+
+ def test_nonexisting_method
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_nil @string.try(method)
+ end
+
+ def test_valid_method
+ assert_equal 5, @string.try(:size)
+ end
+
+ def test_valid_private_method
+ class << @string
+ private :size
+ end
+
+ assert_equal 5, @string.try(:size)
+ end
+
+ def test_argument_forwarding
+ assert_equal 'Hey', @string.try(:sub, 'llo', 'y')
+ end
+
+ def test_block_forwarding
+ assert_equal 'Hey', @string.try(:sub, 'llo') { |match| 'y' }
+ end
+end
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index b086c957fe..e232bf8384 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -207,7 +207,7 @@ class StringBehaviourTest < Test::Unit::TestCase
end
end
-class CoreExtStringMultibyteTest < Test::Unit::TestCase
+class CoreExtStringMultibyteTest < ActiveSupport::TestCase
UNICODE_STRING = 'こにちわ'
ASCII_STRING = 'ohayo'
BYTE_STRING = "\270\236\010\210\245"
@@ -253,4 +253,4 @@ class CoreExtStringMultibyteTest < Test::Unit::TestCase
assert UNICODE_STRING.mb_chars.kind_of?(String)
end
end
-end \ No newline at end of file
+end
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 11ec1c6cd6..52d6c18dce 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -123,7 +123,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
def test_end_of_year
assert_equal Time.local(2007,12,31,23,59,59), Time.local(2007,2,22,10,10,10).end_of_year
assert_equal Time.local(2007,12,31,23,59,59), Time.local(2007,12,31,10,10,10).end_of_year
- end
+ end
def test_beginning_of_year
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_year
@@ -515,16 +515,14 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal 31, Time.days_in_month(12, 2005)
end
- uses_mocha 'TestTimeDaysInMonthWithoutYearArg' do
- def test_days_in_month_feb_in_common_year_without_year_arg
- Time.stubs(:now).returns(Time.utc(2007))
- assert_equal 28, Time.days_in_month(2)
- end
+ def test_days_in_month_feb_in_common_year_without_year_arg
+ Time.stubs(:now).returns(Time.utc(2007))
+ assert_equal 28, Time.days_in_month(2)
+ end
- def test_days_in_month_feb_in_leap_year_without_year_arg
- Time.stubs(:now).returns(Time.utc(2008))
- assert_equal 29, Time.days_in_month(2)
- end
+ def test_days_in_month_feb_in_leap_year_without_year_arg
+ Time.stubs(:now).returns(Time.utc(2008))
+ assert_equal 29, Time.days_in_month(2)
end
def test_time_with_datetime_fallback
@@ -572,71 +570,69 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_nothing_raised { Time.now.xmlschema }
end
- uses_mocha 'Test Time past?, today? and future?' do
- def test_today_with_time_local
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, Time.local(1999,12,31,23,59,59).today?
- assert_equal true, Time.local(2000,1,1,0).today?
- assert_equal true, Time.local(2000,1,1,23,59,59).today?
- assert_equal false, Time.local(2000,1,2,0).today?
- end
-
- def test_today_with_time_utc
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, Time.utc(1999,12,31,23,59,59).today?
- assert_equal true, Time.utc(2000,1,1,0).today?
- assert_equal true, Time.utc(2000,1,1,23,59,59).today?
- assert_equal false, Time.utc(2000,1,2,0).today?
- end
-
- def test_past_with_time_current_as_time_local
- with_env_tz 'US/Eastern' do
- Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
- assert_equal true, Time.local(2005,2,10,15,30,44).past?
- assert_equal false, Time.local(2005,2,10,15,30,45).past?
- assert_equal false, Time.local(2005,2,10,15,30,46).past?
- assert_equal true, Time.utc(2005,2,10,20,30,44).past?
- assert_equal false, Time.utc(2005,2,10,20,30,45).past?
- assert_equal false, Time.utc(2005,2,10,20,30,46).past?
- end
- end
-
- def test_past_with_time_current_as_time_with_zone
- with_env_tz 'US/Eastern' do
- twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)')
- Time.stubs(:current).returns(twz)
- assert_equal true, Time.local(2005,2,10,10,30,44).past?
- assert_equal false, Time.local(2005,2,10,10,30,45).past?
- assert_equal false, Time.local(2005,2,10,10,30,46).past?
- assert_equal true, Time.utc(2005,2,10,15,30,44).past?
- assert_equal false, Time.utc(2005,2,10,15,30,45).past?
- assert_equal false, Time.utc(2005,2,10,15,30,46).past?
- end
- end
-
- def test_future_with_time_current_as_time_local
- with_env_tz 'US/Eastern' do
- Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
- assert_equal false, Time.local(2005,2,10,15,30,44).future?
- assert_equal false, Time.local(2005,2,10,15,30,45).future?
- assert_equal true, Time.local(2005,2,10,15,30,46).future?
- assert_equal false, Time.utc(2005,2,10,20,30,44).future?
- assert_equal false, Time.utc(2005,2,10,20,30,45).future?
- assert_equal true, Time.utc(2005,2,10,20,30,46).future?
- end
- end
-
- def test_future_with_time_current_as_time_with_zone
- with_env_tz 'US/Eastern' do
- twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)')
- Time.stubs(:current).returns(twz)
- assert_equal false, Time.local(2005,2,10,10,30,44).future?
- assert_equal false, Time.local(2005,2,10,10,30,45).future?
- assert_equal true, Time.local(2005,2,10,10,30,46).future?
- assert_equal false, Time.utc(2005,2,10,15,30,44).future?
- assert_equal false, Time.utc(2005,2,10,15,30,45).future?
- assert_equal true, Time.utc(2005,2,10,15,30,46).future?
- end
+ def test_today_with_time_local
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, Time.local(1999,12,31,23,59,59).today?
+ assert_equal true, Time.local(2000,1,1,0).today?
+ assert_equal true, Time.local(2000,1,1,23,59,59).today?
+ assert_equal false, Time.local(2000,1,2,0).today?
+ end
+
+ def test_today_with_time_utc
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, Time.utc(1999,12,31,23,59,59).today?
+ assert_equal true, Time.utc(2000,1,1,0).today?
+ assert_equal true, Time.utc(2000,1,1,23,59,59).today?
+ assert_equal false, Time.utc(2000,1,2,0).today?
+ end
+
+ def test_past_with_time_current_as_time_local
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
+ assert_equal true, Time.local(2005,2,10,15,30,44).past?
+ assert_equal false, Time.local(2005,2,10,15,30,45).past?
+ assert_equal false, Time.local(2005,2,10,15,30,46).past?
+ assert_equal true, Time.utc(2005,2,10,20,30,44).past?
+ assert_equal false, Time.utc(2005,2,10,20,30,45).past?
+ assert_equal false, Time.utc(2005,2,10,20,30,46).past?
+ end
+ end
+
+ def test_past_with_time_current_as_time_with_zone
+ with_env_tz 'US/Eastern' do
+ twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)')
+ Time.stubs(:current).returns(twz)
+ assert_equal true, Time.local(2005,2,10,10,30,44).past?
+ assert_equal false, Time.local(2005,2,10,10,30,45).past?
+ assert_equal false, Time.local(2005,2,10,10,30,46).past?
+ assert_equal true, Time.utc(2005,2,10,15,30,44).past?
+ assert_equal false, Time.utc(2005,2,10,15,30,45).past?
+ assert_equal false, Time.utc(2005,2,10,15,30,46).past?
+ end
+ end
+
+ def test_future_with_time_current_as_time_local
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
+ assert_equal false, Time.local(2005,2,10,15,30,44).future?
+ assert_equal false, Time.local(2005,2,10,15,30,45).future?
+ assert_equal true, Time.local(2005,2,10,15,30,46).future?
+ assert_equal false, Time.utc(2005,2,10,20,30,44).future?
+ assert_equal false, Time.utc(2005,2,10,20,30,45).future?
+ assert_equal true, Time.utc(2005,2,10,20,30,46).future?
+ end
+ end
+
+ def test_future_with_time_current_as_time_with_zone
+ with_env_tz 'US/Eastern' do
+ twz = Time.utc(2005,2,10,15,30,45).in_time_zone('Central Time (US & Canada)')
+ Time.stubs(:current).returns(twz)
+ assert_equal false, Time.local(2005,2,10,10,30,44).future?
+ assert_equal false, Time.local(2005,2,10,10,30,45).future?
+ assert_equal true, Time.local(2005,2,10,10,30,46).future?
+ assert_equal false, Time.utc(2005,2,10,15,30,44).future?
+ assert_equal false, Time.utc(2005,2,10,15,30,45).future?
+ assert_equal true, Time.utc(2005,2,10,15,30,46).future?
end
end
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 774fd57ee6..dc36336239 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -152,50 +152,48 @@ class TimeWithZoneTest < Test::Unit::TestCase
assert_equal false, @twz.between?(Time.utc(2000,1,1,0,0,1), Time.utc(2000,1,1,0,0,2))
end
- uses_mocha 'TimeWithZone past?, today? and future?' do
- def test_today
- Date.stubs(:current).returns(Date.new(2000, 1, 1))
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(1999,12,31,23,59,59) ).today?
- assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,1,0) ).today?
- assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,1,23,59,59) ).today?
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,2,0) ).today?
- end
-
- def test_past_with_time_current_as_time_local
- with_env_tz 'US/Eastern' do
- Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
- assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).past?
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).past?
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).past?
- end
- end
-
- def test_past_with_time_current_as_time_with_zone
- twz = ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45) )
- Time.stubs(:current).returns(twz)
+ def test_today
+ Date.stubs(:current).returns(Date.new(2000, 1, 1))
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(1999,12,31,23,59,59) ).today?
+ assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,1,0) ).today?
+ assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,1,23,59,59) ).today?
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.utc(2000,1,2,0) ).today?
+ end
+
+ def test_past_with_time_current_as_time_local
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).past?
assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).past?
assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).past?
end
-
- def test_future_with_time_current_as_time_local
- with_env_tz 'US/Eastern' do
- Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).future?
- assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).future?
- assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).future?
- end
- end
-
- def future_with_time_current_as_time_with_zone
- twz = ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45) )
- Time.stubs(:current).returns(twz)
+ end
+
+ def test_past_with_time_current_as_time_with_zone
+ twz = ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45) )
+ Time.stubs(:current).returns(twz)
+ assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).past?
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).past?
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).past?
+ end
+
+ def test_future_with_time_current_as_time_local
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:current).returns(Time.local(2005,2,10,15,30,45))
assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).future?
assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).future?
assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).future?
end
end
+ def future_with_time_current_as_time_with_zone
+ twz = ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45) )
+ Time.stubs(:current).returns(twz)
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,44)).future?
+ assert_equal false, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,45)).future?
+ assert_equal true, ActiveSupport::TimeWithZone.new( nil, @time_zone, Time.local(2005,2,10,15,30,46)).future?
+ end
+
def test_eql?
assert @twz.eql?(Time.utc(2000))
assert @twz.eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) )
@@ -399,28 +397,26 @@ class TimeWithZoneTest < Test::Unit::TestCase
end
end
- uses_mocha 'TestDatePartValueMethods' do
- def test_method_missing_with_non_time_return_value
- silence_warnings do # silence warnings raised by tzinfo gem
- @twz.time.expects(:foo).returns('bar')
- assert_equal 'bar', @twz.foo
- end
+ def test_method_missing_with_non_time_return_value
+ silence_warnings do # silence warnings raised by tzinfo gem
+ @twz.time.expects(:foo).returns('bar')
+ assert_equal 'bar', @twz.foo
end
+ end
- def test_date_part_value_methods
- silence_warnings do # silence warnings raised by tzinfo gem
- twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone)
- twz.expects(:method_missing).never
- assert_equal 1999, twz.year
- assert_equal 12, twz.month
- assert_equal 31, twz.day
- assert_equal 14, twz.hour
- assert_equal 18, twz.min
- assert_equal 17, twz.sec
- assert_equal 500, twz.usec
- assert_equal 5, twz.wday
- assert_equal 365, twz.yday
- end
+ def test_date_part_value_methods
+ silence_warnings do # silence warnings raised by tzinfo gem
+ twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone)
+ twz.expects(:method_missing).never
+ assert_equal 1999, twz.year
+ assert_equal 12, twz.month
+ assert_equal 31, twz.day
+ assert_equal 14, twz.hour
+ assert_equal 18, twz.min
+ assert_equal 17, twz.sec
+ assert_equal 500, twz.usec
+ assert_equal 5, twz.wday
+ assert_equal 365, twz.yday
end
end
@@ -885,28 +881,26 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase
assert_equal nil, Time.zone
end
- uses_mocha 'TestTimeCurrent' do
- def test_current_returns_time_now_when_zone_default_not_set
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns Time.local(2000)
- assert_equal false, Time.current.is_a?(ActiveSupport::TimeWithZone)
- assert_equal Time.local(2000), Time.current
- end
+ def test_current_returns_time_now_when_zone_default_not_set
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns Time.local(2000)
+ assert_equal false, Time.current.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal Time.local(2000), Time.current
end
+ end
- def test_current_returns_time_zone_now_when_zone_default_set
- silence_warnings do # silence warnings raised by tzinfo gem
- Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns Time.local(2000)
- assert_equal true, Time.current.is_a?(ActiveSupport::TimeWithZone)
- assert_equal 'Eastern Time (US & Canada)', Time.current.time_zone.name
- assert_equal Time.utc(2000), Time.current.time
- end
+ def test_current_returns_time_zone_now_when_zone_default_set
+ silence_warnings do # silence warnings raised by tzinfo gem
+ Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns Time.local(2000)
+ assert_equal true, Time.current.is_a?(ActiveSupport::TimeWithZone)
+ assert_equal 'Eastern Time (US & Canada)', Time.current.time_zone.name
+ assert_equal Time.utc(2000), Time.current.time
end
- ensure
- Time.zone_default = nil
end
+ ensure
+ Time.zone_default = nil
end
protected
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 6c3bd1a4fd..fe04b91f2b 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -694,17 +694,17 @@ class DependenciesTest < Test::Unit::TestCase
with_loading 'autoloading_fixtures' do
ActiveSupport::Dependencies.mechanism = :require
2.times do
- assert_raise(NameError) {"RaisesNameError".constantize}
+ assert_raise(NameError) { assert_equal 123, ::RaisesNameError::FooBarBaz }
end
end
end
def test_autoload_doesnt_shadow_name_error
with_loading 'autoloading_fixtures' do
- assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it hasn't been referenced yet!"
+ Object.send(:remove_const, :RaisesNameError) if defined?(::RaisesNameError)
2.times do
begin
- ::RaisesNameError.object_id
+ ::RaisesNameError::FooBarBaz.object_id
flunk 'should have raised NameError when autoloaded file referenced FooBarBaz'
rescue NameError => e
assert_equal 'uninitialized constant RaisesNameError::FooBarBaz', e.message
@@ -712,9 +712,9 @@ class DependenciesTest < Test::Unit::TestCase
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"
end
- assert !defined?(RaisesNameError)
+ assert !defined?(::RaisesNameError)
2.times do
- assert_raise(NameError) { RaisesNameError }
+ assert_raise(NameError) { ::RaisesNameError }
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"
end
end
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index 27e9573ce2..73a1f9959c 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -32,7 +32,7 @@ class Deprecatee
end
-class DeprecationTest < Test::Unit::TestCase
+class DeprecationTest < ActiveSupport::TestCase
def setup
# Track the last warning.
@old_behavior = ActiveSupport::Deprecation.behavior
@@ -143,19 +143,21 @@ class DeprecationTest < Test::Unit::TestCase
assert_deprecated(/you now need to do something extra for this one/) { @dtc.d }
end
- def test_assertion_failed_error_doesnt_spout_deprecation_warnings
- error_class = Class.new(StandardError) do
- def message
- ActiveSupport::Deprecation.warn 'warning in error message'
- super
+ unless defined?(::MiniTest)
+ def test_assertion_failed_error_doesnt_spout_deprecation_warnings
+ error_class = Class.new(StandardError) do
+ def message
+ ActiveSupport::Deprecation.warn 'warning in error message'
+ super
+ end
end
- end
- raise error_class.new('hmm')
+ raise error_class.new('hmm')
- rescue => e
- error = Test::Unit::Error.new('testing ur doodz', e)
- assert_not_deprecated { error.message }
- assert_nil @last_message
+ rescue => e
+ error = Test::Unit::Error.new('testing ur doodz', e)
+ assert_not_deprecated { error.message }
+ assert_nil @last_message
+ end
end
end
diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb
index db5bd5e088..cfb8c76d52 100644
--- a/activesupport/test/i18n_test.rb
+++ b/activesupport/test/i18n_test.rb
@@ -6,11 +6,9 @@ class I18nTest < Test::Unit::TestCase
@time = Time.utc(2008, 7, 2, 16, 47, 1)
end
- uses_mocha 'I18nTimeZoneTest' do
- def test_time_zone_localization_with_default_format
- Time.zone.stubs(:now).returns Time.local(2000)
- assert_equal Time.zone.now.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(Time.zone.now)
- end
+ def test_time_zone_localization_with_default_format
+ Time.zone.stubs(:now).returns Time.local(2000)
+ assert_equal Time.zone.now.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(Time.zone.now)
end
def test_date_localization_should_use_default_format
@@ -83,9 +81,9 @@ class I18nTest < Test::Unit::TestCase
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 } }
+ I18n.backend.store_translations 'en', :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 } }
+ I18n.backend.store_translations 'en', :support => { :array => { :skip_last_comma => false } }
end
end
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index d30852c013..d8c93dc9ae 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -104,6 +104,12 @@ class InflectorTest < Test::Unit::TestCase
end
end
+ def test_parameterize_and_normalize
+ StringToParameterizedAndNormalized.each do |some_string, parameterized_string|
+ assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))
+ end
+ end
+
def test_parameterize_with_custom_separator
StringToParameterized.each do |some_string, parameterized_string|
assert_equal(parameterized_string.gsub('-', '_'), ActiveSupport::Inflector.parameterize(some_string, '_'))
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index 3aa18ca781..481c3e835c 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -147,14 +147,25 @@ module InflectorTestCases
StringToParameterized = {
"Donald E. Knuth" => "donald-e-knuth",
"Random text with *(bad)* characters" => "random-text-with-bad-characters",
- "Malmö" => "malmo",
- "Garçons" => "garcons",
"Allow_Under_Scores" => "allow_under_scores",
"Trailing bad characters!@#" => "trailing-bad-characters",
"!@#Leading bad characters" => "leading-bad-characters",
"Squeeze separators" => "squeeze-separators"
}
+ # Ruby 1.9 doesn't do Unicode normalization yet.
+ if RUBY_VERSION >= '1.9'
+ StringToParameterizedAndNormalized = {
+ "Malmö" => "malm",
+ "Garçons" => "gar-ons"
+ }
+ else
+ StringToParameterizedAndNormalized = {
+ "Malmö" => "malmo",
+ "Garçons" => "garcons"
+ }
+ end
+
UnderscoreToHuman = {
"employee_salary" => "Employee salary",
"employee_id" => "Employee",
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index c070e0d9ed..8ed21cc9ad 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -126,15 +126,13 @@ class TestJSONEncoding < Test::Unit::TestCase
end
end
-uses_mocha 'JsonOptionsTests' do
- class JsonOptionsTests < Test::Unit::TestCase
- def test_enumerable_should_passthrough_options_to_elements
- json_options = { :include => :posts }
- ActiveSupport::JSON.expects(:encode).with(1, json_options)
- ActiveSupport::JSON.expects(:encode).with(2, json_options)
- ActiveSupport::JSON.expects(:encode).with('foo', json_options)
-
- [1, 2, 'foo'].to_json(json_options)
- end
+class JsonOptionsTests < Test::Unit::TestCase
+ def test_enumerable_should_passthrough_options_to_elements
+ json_options = { :include => :posts }
+ ActiveSupport::JSON.expects(:encode).with(1, json_options)
+ ActiveSupport::JSON.expects(:encode).with(2, json_options)
+ ActiveSupport::JSON.expects(:encode).with('foo', json_options)
+
+ [1, 2, 'foo'].to_json(json_options)
end
end
diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb
index a78ebd9425..069ae27eb2 100644
--- a/activesupport/test/memoizable_test.rb
+++ b/activesupport/test/memoizable_test.rb
@@ -1,218 +1,226 @@
require 'abstract_unit'
-uses_mocha 'Memoizable' do
- class MemoizableTest < Test::Unit::TestCase
- class Person
- extend ActiveSupport::Memoizable
-
- attr_reader :name_calls, :age_calls
- def initialize
- @name_calls = 0
- @age_calls = 0
- end
+class MemoizableTest < Test::Unit::TestCase
+ class Person
+ extend ActiveSupport::Memoizable
- def name
- @name_calls += 1
- "Josh"
- end
+ attr_reader :name_calls, :age_calls
+ def initialize
+ @name_calls = 0
+ @age_calls = 0
+ end
- def name?
- true
- end
- memoize :name?
+ def name
+ @name_calls += 1
+ "Josh"
+ end
- def update(name)
- "Joshua"
- end
- memoize :update
+ def name?
+ true
+ end
+ memoize :name?
- def age
- @age_calls += 1
- nil
- end
+ def update(name)
+ "Joshua"
+ end
+ memoize :update
- memoize :name, :age
+ def age
+ @age_calls += 1
+ nil
end
- class Company
- attr_reader :name_calls
- def initialize
- @name_calls = 0
- end
+ memoize :name, :age
+ end
- def name
- @name_calls += 1
- "37signals"
- end
+ class Company
+ attr_reader :name_calls
+ def initialize
+ @name_calls = 0
end
- module Rates
- extend ActiveSupport::Memoizable
-
- attr_reader :sales_tax_calls
- def sales_tax(price)
- @sales_tax_calls ||= 0
- @sales_tax_calls += 1
- price * 0.1025
- end
- memoize :sales_tax
+ def name
+ @name_calls += 1
+ "37signals"
end
+ end
- class Calculator
- extend ActiveSupport::Memoizable
- include Rates
+ module Rates
+ extend ActiveSupport::Memoizable
- attr_reader :fib_calls
- def initialize
- @fib_calls = 0
- end
+ attr_reader :sales_tax_calls
+ def sales_tax(price)
+ @sales_tax_calls ||= 0
+ @sales_tax_calls += 1
+ price * 0.1025
+ end
+ memoize :sales_tax
+ end
- def fib(n)
- @fib_calls += 1
+ class Calculator
+ extend ActiveSupport::Memoizable
+ include Rates
- if n == 0 || n == 1
- n
- else
- fib(n - 1) + fib(n - 2)
- end
- end
- memoize :fib
+ attr_reader :fib_calls
+ def initialize
+ @fib_calls = 0
+ end
- def counter
- @count ||= 0
- @count += 1
+ def fib(n)
+ @fib_calls += 1
+
+ if n == 0 || n == 1
+ n
+ else
+ fib(n - 1) + fib(n - 2)
end
- memoize :counter
end
+ memoize :fib
- def setup
- @person = Person.new
- @calculator = Calculator.new
+ def counter
+ @count ||= 0
+ @count += 1
end
+ memoize :counter
+ end
- def test_memoization
- assert_equal "Josh", @person.name
- assert_equal 1, @person.name_calls
-
- 3.times { assert_equal "Josh", @person.name }
- assert_equal 1, @person.name_calls
- end
+ def setup
+ @person = Person.new
+ @calculator = Calculator.new
+ end
- def test_memoization_with_punctuation
- assert_equal true, @person.name?
+ def test_memoization
+ assert_equal "Josh", @person.name
+ assert_equal 1, @person.name_calls
- assert_nothing_raised(NameError) do
- @person.memoize_all
- @person.unmemoize_all
- end
- end
+ 3.times { assert_equal "Josh", @person.name }
+ assert_equal 1, @person.name_calls
+ end
- def test_memoization_with_nil_value
- assert_equal nil, @person.age
- assert_equal 1, @person.age_calls
+ def test_memoization_with_punctuation
+ assert_equal true, @person.name?
- 3.times { assert_equal nil, @person.age }
- assert_equal 1, @person.age_calls
+ assert_nothing_raised(NameError) do
+ @person.memoize_all
+ @person.unmemoize_all
end
+ end
- def test_memorized_results_are_immutable
- assert_equal "Josh", @person.name
- assert_raise(ActiveSupport::FrozenObjectError) { @person.name.gsub!("Josh", "Gosh") }
- end
+ def test_memoization_with_nil_value
+ assert_equal nil, @person.age
+ assert_equal 1, @person.age_calls
- def test_reloadable
- counter = @calculator.counter
- assert_equal 1, @calculator.counter
- assert_equal 2, @calculator.counter(:reload)
- assert_equal 2, @calculator.counter
- assert_equal 3, @calculator.counter(true)
- assert_equal 3, @calculator.counter
- end
-
- def test_unmemoize_all
- assert_equal 1, @calculator.counter
+ 3.times { assert_equal nil, @person.age }
+ assert_equal 1, @person.age_calls
+ end
- assert @calculator.instance_variable_get(:@_memoized_counter).any?
- @calculator.unmemoize_all
- assert @calculator.instance_variable_get(:@_memoized_counter).empty?
+ def test_memorized_results_are_immutable
+ assert_equal "Josh", @person.name
+ assert_raise(ActiveSupport::FrozenObjectError) { @person.name.gsub!("Josh", "Gosh") }
+ end
- assert_equal 2, @calculator.counter
- end
+ def test_reloadable
+ counter = @calculator.counter
+ assert_equal 1, @calculator.counter
+ assert_equal 2, @calculator.counter(:reload)
+ assert_equal 2, @calculator.counter
+ assert_equal 3, @calculator.counter(true)
+ assert_equal 3, @calculator.counter
+ end
- def test_memoize_all
- @calculator.memoize_all
- assert @calculator.instance_variable_defined?(:@_memoized_counter)
- end
+ def test_flush_cache
+ assert_equal 1, @calculator.counter
- def test_memoization_cache_is_different_for_each_instance
- assert_equal 1, @calculator.counter
- assert_equal 2, @calculator.counter(:reload)
- assert_equal 1, Calculator.new.counter
- end
+ assert @calculator.instance_variable_get(:@_memoized_counter).any?
+ @calculator.flush_cache(:counter)
+ assert @calculator.instance_variable_get(:@_memoized_counter).empty?
- def test_memoized_is_not_affected_by_freeze
- @person.freeze
- assert_equal "Josh", @person.name
- assert_equal "Joshua", @person.update("Joshua")
- end
+ assert_equal 2, @calculator.counter
+ end
- def test_memoization_with_args
- assert_equal 55, @calculator.fib(10)
- assert_equal 11, @calculator.fib_calls
- end
+ def test_unmemoize_all
+ assert_equal 1, @calculator.counter
- def test_reloadable_with_args
- assert_equal 55, @calculator.fib(10)
- assert_equal 11, @calculator.fib_calls
- assert_equal 55, @calculator.fib(10, :reload)
- assert_equal 12, @calculator.fib_calls
- assert_equal 55, @calculator.fib(10, true)
- assert_equal 13, @calculator.fib_calls
- end
+ assert @calculator.instance_variable_get(:@_memoized_counter).any?
+ @calculator.unmemoize_all
+ assert @calculator.instance_variable_get(:@_memoized_counter).empty?
- def test_object_memoization
- [Company.new, Company.new, Company.new].each do |company|
- company.extend ActiveSupport::Memoizable
- company.memoize :name
+ assert_equal 2, @calculator.counter
+ end
- assert_equal "37signals", company.name
- assert_equal 1, company.name_calls
- assert_equal "37signals", company.name
- assert_equal 1, company.name_calls
- end
- end
+ def test_memoize_all
+ @calculator.memoize_all
+ assert @calculator.instance_variable_defined?(:@_memoized_counter)
+ end
- def test_memoized_module_methods
- assert_equal 1.025, @calculator.sales_tax(10)
- assert_equal 1, @calculator.sales_tax_calls
- assert_equal 1.025, @calculator.sales_tax(10)
- assert_equal 1, @calculator.sales_tax_calls
- assert_equal 2.5625, @calculator.sales_tax(25)
- assert_equal 2, @calculator.sales_tax_calls
- end
+ def test_memoization_cache_is_different_for_each_instance
+ assert_equal 1, @calculator.counter
+ assert_equal 2, @calculator.counter(:reload)
+ assert_equal 1, Calculator.new.counter
+ end
- def test_object_memoized_module_methods
- company = Company.new
- company.extend(Rates)
+ def test_memoized_is_not_affected_by_freeze
+ @person.freeze
+ assert_equal "Josh", @person.name
+ assert_equal "Joshua", @person.update("Joshua")
+ end
- assert_equal 1.025, company.sales_tax(10)
- assert_equal 1, company.sales_tax_calls
- assert_equal 1.025, company.sales_tax(10)
- assert_equal 1, company.sales_tax_calls
- assert_equal 2.5625, company.sales_tax(25)
- assert_equal 2, company.sales_tax_calls
- end
+ def test_memoization_with_args
+ assert_equal 55, @calculator.fib(10)
+ assert_equal 11, @calculator.fib_calls
+ end
- def test_double_memoization
- assert_raise(RuntimeError) { Person.memoize :name }
- person = Person.new
- person.extend ActiveSupport::Memoizable
- assert_raise(RuntimeError) { person.memoize :name }
+ def test_reloadable_with_args
+ assert_equal 55, @calculator.fib(10)
+ assert_equal 11, @calculator.fib_calls
+ assert_equal 55, @calculator.fib(10, :reload)
+ assert_equal 12, @calculator.fib_calls
+ assert_equal 55, @calculator.fib(10, true)
+ assert_equal 13, @calculator.fib_calls
+ end
- company = Company.new
+ def test_object_memoization
+ [Company.new, Company.new, Company.new].each do |company|
company.extend ActiveSupport::Memoizable
company.memoize :name
- assert_raise(RuntimeError) { company.memoize :name }
+
+ assert_equal "37signals", company.name
+ assert_equal 1, company.name_calls
+ assert_equal "37signals", company.name
+ assert_equal 1, company.name_calls
end
end
+
+ def test_memoized_module_methods
+ assert_equal 1.025, @calculator.sales_tax(10)
+ assert_equal 1, @calculator.sales_tax_calls
+ assert_equal 1.025, @calculator.sales_tax(10)
+ assert_equal 1, @calculator.sales_tax_calls
+ assert_equal 2.5625, @calculator.sales_tax(25)
+ assert_equal 2, @calculator.sales_tax_calls
+ end
+
+ def test_object_memoized_module_methods
+ company = Company.new
+ company.extend(Rates)
+
+ assert_equal 1.025, company.sales_tax(10)
+ assert_equal 1, company.sales_tax_calls
+ assert_equal 1.025, company.sales_tax(10)
+ assert_equal 1, company.sales_tax_calls
+ assert_equal 2.5625, company.sales_tax(25)
+ assert_equal 2, company.sales_tax_calls
+ end
+
+ def test_double_memoization
+ assert_raise(RuntimeError) { Person.memoize :name }
+ person = Person.new
+ person.extend ActiveSupport::Memoizable
+ assert_raise(RuntimeError) { person.memoize :name }
+
+ company = Company.new
+ company.extend ActiveSupport::Memoizable
+ company.memoize :name
+ assert_raise(RuntimeError) { company.memoize :name }
+ end
end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
new file mode 100644
index 0000000000..c0b4a4658c
--- /dev/null
+++ b/activesupport/test/message_encryptor_test.rb
@@ -0,0 +1,46 @@
+require 'abstract_unit'
+
+class MessageEncryptorTest < Test::Unit::TestCase
+ def setup
+ @encryptor = ActiveSupport::MessageEncryptor.new(ActiveSupport::SecureRandom.hex(64))
+ @data = {:some=>"data", :now=>Time.now}
+ end
+
+ def test_simple_round_tripping
+ message = @encryptor.encrypt(@data)
+ assert_equal @data, @encryptor.decrypt(message)
+ end
+
+ def test_encrypting_twice_yields_differing_cipher_text
+ first_messqage = @encryptor.encrypt(@data)
+ second_message = @encryptor.encrypt(@data)
+ assert_not_equal first_messqage, second_message
+ end
+
+ def test_messing_with_either_value_causes_failure
+ text, iv = @encryptor.encrypt(@data).split("--")
+ assert_not_decrypted([iv, text] * "--")
+ assert_not_decrypted([text, munge(iv)] * "--")
+ assert_not_decrypted([munge(text), iv] * "--")
+ assert_not_decrypted([munge(text), munge(iv)] * "--")
+ end
+
+ def test_signed_round_tripping
+ message = @encryptor.encrypt_and_sign(@data)
+ assert_equal @data, @encryptor.decrypt_and_verify(message)
+ end
+
+
+ private
+ def assert_not_decrypted(value)
+ assert_raises(ActiveSupport::MessageEncryptor::InvalidMessage) do
+ @encryptor.decrypt(value)
+ end
+ end
+
+ def munge(base64_string)
+ bits = ActiveSupport::Base64.decode64(base64_string)
+ bits.reverse!
+ ActiveSupport::Base64.encode64s(bits)
+ end
+end
diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb
new file mode 100644
index 0000000000..2190308856
--- /dev/null
+++ b/activesupport/test/message_verifier_test.rb
@@ -0,0 +1,25 @@
+require 'abstract_unit'
+
+class MessageVerifierTest < Test::Unit::TestCase
+ def setup
+ @verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!")
+ @data = {:some=>"data", :now=>Time.now}
+ end
+
+ def test_simple_round_tripping
+ message = @verifier.generate(@data)
+ assert_equal @data, @verifier.verify(message)
+ end
+
+ def test_tampered_data_raises
+ data, hash = @verifier.generate(@data).split("--")
+ assert_not_verified("#{data.reverse}--#{hash}")
+ assert_not_verified("#{data}--#{hash.reverse}")
+ end
+
+ def assert_not_verified(message)
+ assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
+ @verifier.verify(message)
+ end
+ end
+end
diff --git a/activesupport/test/multibyte_unicode_database_test.rb b/activesupport/test/multibyte_unicode_database_test.rb
index fb415e08d3..405c7c2108 100644
--- a/activesupport/test/multibyte_unicode_database_test.rb
+++ b/activesupport/test/multibyte_unicode_database_test.rb
@@ -1,11 +1,7 @@
# encoding: utf-8
-
require 'abstract_unit'
-uses_mocha "MultibyteUnicodeDatabaseTest" do
-
class MultibyteUnicodeDatabaseTest < Test::Unit::TestCase
-
def setup
@ucd = ActiveSupport::Multibyte::UnicodeDatabase.new
end
@@ -24,5 +20,3 @@ class MultibyteUnicodeDatabaseTest < Test::Unit::TestCase
end
end
end
-
-end \ No newline at end of file
diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb
index 0d72314880..f26d61617d 100644
--- a/activesupport/test/option_merger_test.rb
+++ b/activesupport/test/option_merger_test.rb
@@ -64,6 +64,14 @@ class OptionMergerTest < Test::Unit::TestCase
end
end
end
+
+ def test_nested_method_with_options_using_lamdba
+ local_lamdba = lambda { { :lambda => true } }
+ with_options(@options) do |o|
+ assert_equal @options.merge(local_lamdba.call),
+ o.method_with_options(local_lamdba).call
+ end
+ end
# Needed when counting objects with the ObjectSpace
def test_option_merger_class_method
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index 98a6ad6b26..17dffbd624 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -61,4 +61,16 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal false, @ordered_hash.has_value?('ABCABC')
assert_equal false, @ordered_hash.value?('ABCABC')
end
+
+ def test_each_key
+ keys = []
+ @ordered_hash.each_key { |k| keys << k }
+ assert_equal @keys, keys
+ end
+
+ def test_each_value
+ values = []
+ @ordered_hash.each_value { |v| values << v }
+ assert_equal @values, values
+ end
end
diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb
index 4e253848f6..298037e27c 100644
--- a/activesupport/test/test_test.rb
+++ b/activesupport/test/test_test.rb
@@ -1,7 +1,6 @@
require 'abstract_unit'
-require 'active_support/test_case'
-class AssertDifferenceTest < Test::Unit::TestCase
+class AssertDifferenceTest < ActiveSupport::TestCase
def setup
@object = Class.new do
attr_accessor :num
@@ -66,8 +65,8 @@ class AssertDifferenceTest < Test::Unit::TestCase
@object.increment
end
fail 'should not get to here'
- rescue Test::Unit::AssertionFailedError => e
- assert_equal "<1 + 1> was the expression that failed.\n<3> expected but was\n<2>.", e.message
+ rescue Exception => e
+ assert_equal "<3> expected but was\n<2>.", e.message
end
def test_array_of_expressions_identify_failure_when_message_provided
@@ -75,8 +74,8 @@ class AssertDifferenceTest < Test::Unit::TestCase
@object.increment
end
fail 'should not get to here'
- rescue Test::Unit::AssertionFailedError => e
- assert_equal "something went wrong.\n<1 + 1> was the expression that failed.\n<3> expected but was\n<2>.", e.message
+ rescue Exception => e
+ assert_equal "something went wrong.\n<3> expected but was\n<2>.", e.message
end
else
def default_test; end
@@ -84,15 +83,17 @@ class AssertDifferenceTest < Test::Unit::TestCase
end
# These should always pass
-class NotTestingThingsTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Default
+if ActiveSupport::Testing.const_defined?(:Default)
+ class NotTestingThingsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Default
+ end
end
class AlsoDoingNothingTest < ActiveSupport::TestCase
end
# Setup and teardown callbacks.
-class SetupAndTeardownTest < Test::Unit::TestCase
+class SetupAndTeardownTest < ActiveSupport::TestCase
setup :reset_callback_record, :foo
teardown :foo, :sentinel, :foo
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index 515ffcf0bf..f80575cfd4 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -51,52 +51,50 @@ class TimeZoneTest < Test::Unit::TestCase
define_method("test_utc_offset_for_#{name}") do
silence_warnings do # silence warnings raised by tzinfo gem
- period = zone.tzinfo.period_for_utc(Time.utc(2006,1,1,0,0,0))
+ period = zone.tzinfo.current_period
assert_equal period.utc_offset, zone.utc_offset
end
end
end
- uses_mocha 'TestTimeZoneNowAndToday' do
- def test_now
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns(Time.local(2000))
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- assert_instance_of ActiveSupport::TimeWithZone, zone.now
- assert_equal Time.utc(2000,1,1,5), zone.now.utc
- assert_equal Time.utc(2000), zone.now.time
- assert_equal zone, zone.now.time_zone
- end
+ def test_now
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns(Time.local(2000))
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert_instance_of ActiveSupport::TimeWithZone, zone.now
+ assert_equal Time.utc(2000,1,1,5), zone.now.utc
+ assert_equal Time.utc(2000), zone.now.time
+ assert_equal zone, zone.now.time_zone
end
+ end
- def test_now_enforces_spring_dst_rules
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns(Time.local(2006,4,2,2)) # 2AM springs forward to 3AM
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- assert_equal Time.utc(2006,4,2,3), zone.now.time
- assert_equal true, zone.now.dst?
- end
+ def test_now_enforces_spring_dst_rules
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns(Time.local(2006,4,2,2)) # 2AM springs forward to 3AM
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert_equal Time.utc(2006,4,2,3), zone.now.time
+ assert_equal true, zone.now.dst?
end
+ end
- def test_now_enforces_fall_dst_rules
- with_env_tz 'US/Eastern' do
- Time.stubs(:now).returns(Time.at(1162098000)) # equivalent to 1AM DST
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- assert_equal Time.utc(2006,10,29,1), zone.now.time
- assert_equal true, zone.now.dst?
- end
+ def test_now_enforces_fall_dst_rules
+ with_env_tz 'US/Eastern' do
+ Time.stubs(:now).returns(Time.at(1162098000)) # equivalent to 1AM DST
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert_equal Time.utc(2006,10,29,1), zone.now.time
+ assert_equal true, zone.now.dst?
end
+ end
- def test_today
- Time.stubs(:now).returns(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST
- assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
- Time.stubs(:now).returns(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST
- assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
- Time.stubs(:now).returns(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST
- assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
- Time.stubs(:now).returns(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST
- assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
- end
+ def test_today
+ Time.stubs(:now).returns(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST
+ assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
+ Time.stubs(:now).returns(Time.utc(2000, 1, 1, 5)) # midnight Jan 1 EST
+ assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
+ Time.stubs(:now).returns(Time.utc(2000, 1, 2, 4, 59, 59)) # 1 sec before midnight Jan 2 EST
+ assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
+ Time.stubs(:now).returns(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST
+ assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
end
def test_local
@@ -206,13 +204,11 @@ class TimeZoneTest < Test::Unit::TestCase
end
end
- uses_mocha 'TestParseWithIncompleteDate' do
- def test_parse_with_incomplete_date
- zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
- zone.stubs(:now).returns zone.local(1999,12,31)
- twz = zone.parse('19:00:00')
- assert_equal Time.utc(1999,12,31,19), twz.time
- end
+ def test_parse_with_incomplete_date
+ zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ zone.stubs(:now).returns zone.local(1999,12,31)
+ twz = zone.parse('19:00:00')
+ assert_equal Time.utc(1999,12,31,19), twz.time
end
def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize