aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
commit3b93ca221d3a1b777bd880c18f52010cbd56c18c (patch)
tree7b49713994125de123775102eac2655d7b29b231 /activesupport/test
parentdaab53d8c0bca1114c1485d0dcc52858a264ab9e (diff)
parent46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd (diff)
downloadrails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.gz
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.bz2
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.zip
Merge commit 'rails/master'
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/caching_test.rb13
-rw-r--r--activesupport/test/callbacks_test.rb31
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb1
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb55
4 files changed, 98 insertions, 2 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index a038f29f53..09b56525e0 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -18,6 +18,19 @@ class CacheStoreSettingTest < Test::Unit::TestCase
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
assert_equal %w(localhost), store.addresses
end
+
+ def test_mem_cache_fragment_cache_store_with_multiple_servers
+ store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
+ assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
+ assert_equal %w(localhost 192.168.1.1), store.addresses
+ end
+
+ def test_mem_cache_fragment_cache_store_with_options
+ store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo'
+ assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
+ assert_equal %w(localhost 192.168.1.1), store.addresses
+ assert_equal 'foo', store.instance_variable_get('@data').instance_variable_get('@namespace')
+ end
def test_object_assigned_fragment_cache_store
store = ActiveSupport::Cache.lookup_store ActiveSupport::Cache::FileStore.new("/path/to/cache/directory")
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 3f8cb7f01a..7f71ca2262 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -96,6 +96,8 @@ class ConditionalCallbackTest < Test::Unit::TestCase
end
class CallbackTest < Test::Unit::TestCase
+ include ActiveSupport::Callbacks
+
def test_eql
callback = Callback.new(:before, :save, :identifier => :lifesaver)
assert callback.eql?(Callback.new(:before, :save, :identifier => :lifesaver))
@@ -115,3 +117,32 @@ class CallbackTest < Test::Unit::TestCase
assert_equal({}, a.options)
end
end
+
+class CallbackChainTest < Test::Unit::TestCase
+ include ActiveSupport::Callbacks
+
+ def setup
+ @chain = CallbackChain.build(:make, :bacon, :lettuce, :tomato)
+ end
+
+ def test_build
+ assert_equal 3, @chain.size
+ assert_equal [:bacon, :lettuce, :tomato], @chain.map(&:method)
+ end
+
+ def test_find
+ assert_equal :bacon, @chain.find(:bacon).method
+ end
+
+ def test_union
+ assert_equal [:bacon, :lettuce, :tomato], (@chain | Callback.new(:make, :bacon)).map(&:method)
+ assert_equal [:bacon, :lettuce, :tomato, :turkey], (@chain | CallbackChain.build(:make, :bacon, :lettuce, :tomato, :turkey)).map(&:method)
+ assert_equal [:bacon, :lettuce, :tomato, :turkey, :mayo], (@chain | Callback.new(:make, :mayo)).map(&:method)
+ end
+
+ def test_delete
+ assert_equal [:bacon, :lettuce, :tomato], @chain.map(&:method)
+ @chain.delete(:bacon)
+ assert_equal [:lettuce, :tomato], @chain.map(&:method)
+ end
+end
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 25a8e878f9..ed45daf403 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -240,6 +240,7 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase
assert_equal DateTime.civil(2005, 2, 21, 15, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc
assert_equal DateTime.civil(2005, 2, 21, 10, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc
assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).utc
+ assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).getutc
end
def test_formatted_offset_with_utc
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index d1d92964c3..e53b7193ea 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -205,6 +205,31 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
+ def test_daylight_savings_time_crossings_backward_start_1day
+ with_env_tz 'US/Eastern' do
+ # dt: US: 2005 April 3rd 4:18am
+ assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(1.day), 'dt-1.day=>st'
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(1.day), 'st-1.day=>st'
+ end
+ with_env_tz 'NZ' do
+ # dt: New Zealand: 2006 October 1st 4:18am
+ assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(1.day), 'dt-1.day=>st'
+ assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(1.day), 'st-1.day=>st'
+ end
+ end
+
+ def test_daylight_savings_time_crossings_backward_end_1day
+ with_env_tz 'US/Eastern' do
+ # st: US: 2005 October 30th 4:03am
+ assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(1.day), 'st-1.day=>dt'
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(1.day), 'dt-1.day=>dt'
+ end
+ with_env_tz 'NZ' do
+ # st: New Zealand: 2006 March 19th 4:03am
+ assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(1.day), 'st-1.day=>dt'
+ assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), 'dt-1.day=>dt'
+ end
+ end
def test_since
assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1)
assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600)
@@ -227,6 +252,19 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
+ def test_daylight_savings_time_crossings_forward_start_1day
+ with_env_tz 'US/Eastern' do
+ # st: US: 2005 April 2nd 7:27pm
+ assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(1.day), 'st+1.day=>dt'
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(1.day), 'dt+1.day=>dt'
+ end
+ with_env_tz 'NZ' do
+ # st: New Zealand: 2006 September 30th 7:27pm
+ assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(1.day), 'st+1.day=>dt'
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(1.day), 'dt+1.day=>dt'
+ end
+ end
+
def test_daylight_savings_time_crossings_forward_start_tomorrow
with_env_tz 'US/Eastern' do
# st: US: 2005 April 2nd 7:27pm
@@ -240,7 +278,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
- def test_daylight_savings_time_crossings_forward_start_yesterday
+ def test_daylight_savings_time_crossings_backward_start_yesterday
with_env_tz 'US/Eastern' do
# st: US: 2005 April 2nd 7:27pm
assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st'
@@ -266,6 +304,19 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
+ def test_daylight_savings_time_crossings_forward_end_1day
+ with_env_tz 'US/Eastern' do
+ # dt: US: 2005 October 30th 12:45am
+ assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(1.day), 'dt+1.day=>st'
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(1.day), 'st+1.day=>st'
+ end
+ with_env_tz 'NZ' do
+ # dt: New Zealand: 2006 March 19th 1:45am
+ assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(1.day), 'dt+1.day=>st'
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(1.day), 'st+1.day=>st'
+ end
+ end
+
def test_daylight_savings_time_crossings_forward_end_tomorrow
with_env_tz 'US/Eastern' do
# dt: US: 2005 October 30th 12:45am
@@ -279,7 +330,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
end
end
- def test_daylight_savings_time_crossings_forward_end_yesterday
+ def test_daylight_savings_time_crossings_backward_end_yesterday
with_env_tz 'US/Eastern' do
# dt: US: 2005 October 30th 12:45am
assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt'