aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorlholden <lholden@yellowpages.com>2009-01-21 16:17:24 -0800
committerlholden <lholden@yellowpages.com>2009-01-21 16:17:24 -0800
commit19f8bb2808316dfca1f009538c3505ba144f614b (patch)
tree1ab9e925e83b988ed2a1858aa19236e2bcd79a60 /activesupport/test
parentb8fadd708b9850a77e1f64038763fffcff502499 (diff)
parent73cc5f270a5c2a2eab76c6c02615fec608822494 (diff)
downloadrails-19f8bb2808316dfca1f009538c3505ba144f614b.tar.gz
rails-19f8bb2808316dfca1f009538c3505ba144f614b.tar.bz2
rails-19f8bb2808316dfca1f009538c3505ba144f614b.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/caching_test.rb121
-rw-r--r--activesupport/test/core_ext/integer_ext_test.rb4
-rw-r--r--activesupport/test/json/encoding_test.rb4
-rw-r--r--activesupport/test/ordered_hash_test.rb10
4 files changed, 118 insertions, 21 deletions
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index d8506de986..e8e0b41d4d 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -1,18 +1,18 @@
require 'abstract_unit'
-class CacheKeyTest < Test::Unit::TestCase
+class CacheKeyTest < ActiveSupport::TestCase
def test_expand_cache_key
assert_equal 'name/1/2/true', ActiveSupport::Cache.expand_cache_key([1, '2', true], :name)
end
end
-class CacheStoreSettingTest < Test::Unit::TestCase
+class CacheStoreSettingTest < ActiveSupport::TestCase
def test_file_fragment_cache_store
store = ActiveSupport::Cache.lookup_store :file_store, "/path/to/cache/directory"
assert_kind_of(ActiveSupport::Cache::FileStore, store)
assert_equal "/path/to/cache/directory", store.cache_path
end
-
+
def test_drb_fragment_cache_store
store = ActiveSupport::Cache.lookup_store :drb_store, "druby://localhost:9192"
assert_kind_of(ActiveSupport::Cache::DRbStore, store)
@@ -24,13 +24,13 @@ 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)
@@ -45,7 +45,7 @@ class CacheStoreSettingTest < Test::Unit::TestCase
end
end
-class CacheStoreTest < Test::Unit::TestCase
+class CacheStoreTest < ActiveSupport::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
end
@@ -116,9 +116,15 @@ module CacheStoreBehavior
assert_equal 1, @cache.decrement('foo')
assert_equal 1, @cache.read('foo', :raw => true).to_i
end
+
+ def test_exist
+ @cache.write('foo', 'bar')
+ assert @cache.exist?('foo')
+ assert !@cache.exist?('bar')
+ end
end
-class FileStoreTest < Test::Unit::TestCase
+class FileStoreTest < ActiveSupport::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:file_store, Dir.pwd)
end
@@ -130,7 +136,7 @@ class FileStoreTest < Test::Unit::TestCase
include CacheStoreBehavior
end
-class MemoryStoreTest < Test::Unit::TestCase
+class MemoryStoreTest < ActiveSupport::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:memory_store)
end
@@ -145,28 +151,111 @@ class MemoryStoreTest < Test::Unit::TestCase
end
uses_memcached 'memcached backed store' do
- class MemCacheStoreTest < Test::Unit::TestCase
+ class MemCacheStoreTest < ActiveSupport::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
+ @data = @cache.instance_variable_get(:@data)
@cache.clear
end
include CacheStoreBehavior
def test_store_objects_should_be_immutable
- @cache.write('foo', 'bar')
- @cache.read('foo').gsub!(/.*/, 'baz')
- assert_equal 'bar', @cache.read('foo')
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @cache.read('foo').gsub!(/.*/, 'baz')
+ assert_equal 'bar', @cache.read('foo')
+ end
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
+ @cache.with_local_cache do
+ result = @cache.write('foo', 'bar')
+ assert_equal 'bar', @cache.read('foo') # make sure 'foo' was written
+ assert result
+ end
+ end
+
+ def test_local_writes_are_persistent_on_the_remote_cache
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ end
+
+ assert_equal 'bar', @cache.read('foo')
+ end
+
+ def test_clear_also_clears_local_cache
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @cache.clear
+ assert_nil @cache.read('foo')
+ end
+ end
+
+ def test_local_cache_of_read_and_write
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @data.flush_all # Clear remote cache
+ assert_equal 'bar', @cache.read('foo')
+ end
+ end
+
+ def test_local_cache_of_delete
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @cache.delete('foo')
+ @data.flush_all # Clear remote cache
+ assert_nil @cache.read('foo')
+ end
+ end
+
+ def test_local_cache_of_exist
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @cache.instance_variable_set(:@data, nil)
+ @data.flush_all # Clear remote cache
+ assert @cache.exist?('foo')
+ end
+ end
+
+ def test_local_cache_of_increment
+ @cache.with_local_cache do
+ @cache.write('foo', 1, :raw => true)
+ @cache.increment('foo')
+ @data.flush_all # Clear remote cache
+ assert_equal 2, @cache.read('foo', :raw => true).to_i
+ end
+ end
+
+ def test_local_cache_of_decrement
+ @cache.with_local_cache do
+ @cache.write('foo', 1, :raw => true)
+ @cache.decrement('foo')
+ @data.flush_all # Clear remote cache
+ assert_equal 0, @cache.read('foo', :raw => true).to_i
+ end
+ end
+
+ def test_exist_with_nulls_cached_locally
+ @cache.with_local_cache do
+ @cache.write('foo', 'bar')
+ @cache.delete('foo')
+ assert !@cache.exist?('foo')
+ end
+ end
+
+ def test_middleware
+ app = lambda { |env|
+ result = @cache.write('foo', 'bar')
+ assert_equal 'bar', @cache.read('foo') # make sure 'foo' was written
+ assert result
+ }
+ app = @cache.middleware.new(app)
+ app.call({})
end
end
- class CompressedMemCacheStore < Test::Unit::TestCase
+ class CompressedMemCacheStore < ActiveSupport::TestCase
def setup
@cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store)
@cache.clear
diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb
index 5ab36226a1..b7006a5c86 100644
--- a/activesupport/test/core_ext/integer_ext_test.rb
+++ b/activesupport/test/core_ext/integer_ext_test.rb
@@ -28,8 +28,8 @@ class IntegerExtTest < Test::Unit::TestCase
end
def test_ordinalize
- # These tests are mostly just to ensure that the ordinalize method exists
- # It's results are tested comprehensively in the inflector test cases.
+ # These tests are mostly just to ensure that the ordinalize method exists.
+ # Its results are tested comprehensively in the inflector test cases.
assert_equal '1st', 1.ordinalize
assert_equal '8th', 8.ordinalize
1000000000000000000000000000000000000000000000000000000000000000000000.ordinalize
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 8ed21cc9ad..2c5b4d0378 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -59,7 +59,7 @@ class TestJSONEncoding < Test::Unit::TestCase
assert_equal %({\"a\": \"b\"}), { :a => :b }.to_json
assert_equal %({\"a\": 1}), { 'a' => 1 }.to_json
assert_equal %({\"a\": [1, 2]}), { 'a' => [1,2] }.to_json
- assert_equal %({1: 2}), { 1 => 2 }.to_json
+ assert_equal %({"1": 2}), { 1 => 2 }.to_json
sorted_json = '{' + {:a => :b, :c => :d}.to_json[1..-2].split(', ').sort.join(', ') + '}'
assert_equal %({\"a\": \"b\", \"c\": \"d\"}), sorted_json
@@ -80,7 +80,7 @@ class TestJSONEncoding < Test::Unit::TestCase
def test_hash_key_identifiers_are_always_quoted
values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"}
- assert_equal %w( "$" "A" "A0" "A0B" "_" "a" 0 1 ), object_keys(values.to_json)
+ assert_equal %w( "$" "A" "A0" "A0B" "_" "a" "0" "1" ).sort, object_keys(values.to_json)
end
def test_hash_should_allow_key_filtering_with_only
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index 0e2aa4543d..fb76ca1ab6 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -98,7 +98,8 @@ class OrderedHashTest < Test::Unit::TestCase
end
def test_delete_if
- (copy = @ordered_hash.dup).delete('pink')
+ copy = @ordered_hash.dup
+ copy.delete('pink')
assert_equal copy, @ordered_hash.delete_if { |k, _| k == 'pink' }
assert !@ordered_hash.keys.include?('pink')
end
@@ -115,6 +116,7 @@ class OrderedHashTest < Test::Unit::TestCase
new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
assert_equal copy, @ordered_hash
assert !new_ordered_hash.keys.include?('pink')
+ assert @ordered_hash.keys.include?('pink')
end
def test_clear
@@ -140,4 +142,10 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal [@keys.first, @values.first], pair
assert !@ordered_hash.keys.include?(pair.first)
end
+
+ def test_keys
+ original = @ordered_hash.keys.dup
+ @ordered_hash.keys.pop
+ assert_equal original, @ordered_hash.keys
+ end
end \ No newline at end of file