Permalink
Browse files

Revert "tests predicates according to the boolean interpretation of t…

…heir return value, not expecting specifically true or false"

Reason: there were some genuine tests for false when
reading values, going to revise those ones.

This reverts commit a539a5e.
  • Loading branch information...
1 parent a539a5e commit f312e2142b59b39637ab3d668876c3babac22087 @fxn fxn committed Nov 21, 2011
Showing with 55 additions and 51 deletions.
  1. +6 −2 activesupport/lib/active_support/cache.rb
  2. +49 −49 activesupport/test/caching_test.rb
View
8 activesupport/lib/active_support/cache.rb
@@ -365,7 +365,7 @@ def write(name, value, options = nil)
end
end
- # Deletes an entry in the cache. Returns true if an entry is deleted.
+ # Deletes an entry in the cache. Returns +true+ if an entry is deleted.
#
# Options are passed to the underlying cache implementation.
def delete(name, options = nil)
@@ -382,7 +382,11 @@ def exist?(name, options = nil)
options = merged_options(options)
instrument(:exist?, name) do |payload|
entry = read_entry(namespaced_key(name, options), options)
- entry && !entry.expired?
+ if entry && !entry.expired?
+ true
+ else
+ false
+ end
end
end
View
98 activesupport/test/caching_test.rb
@@ -122,24 +122,24 @@ def test_delete_matched_key_start
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/^fo/)
- assert !cache.exist?("foo")
- assert cache.exist?("fu")
+ assert_equal false, cache.exist?("foo")
+ assert_equal true, cache.exist?("fu")
end
def test_delete_matched_key
cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "foo")
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/OO/i)
- assert !cache.exist?("foo")
- assert cache.exist?("fu")
+ assert_equal false, cache.exist?("foo")
+ assert_equal true, cache.exist?("fu")
end
end
# Tests the base functionality that should be identical across all cache stores.
module CacheStoreBehavior
def test_should_read_and_write_strings
- assert @cache.write('foo', 'bar')
+ assert_equal true, @cache.write('foo', 'bar')
assert_equal 'bar', @cache.read('foo')
end
@@ -174,23 +174,23 @@ def test_fetch_with_cached_nil
end
def test_should_read_and_write_hash
- assert @cache.write('foo', {:a => "b"})
+ assert_equal true, @cache.write('foo', {:a => "b"})
assert_equal({:a => "b"}, @cache.read('foo'))
end
def test_should_read_and_write_integer
- assert @cache.write('foo', 1)
+ assert_equal true, @cache.write('foo', 1)
assert_equal 1, @cache.read('foo')
end
def test_should_read_and_write_nil
- assert @cache.write('foo', nil)
+ assert_equal true, @cache.write('foo', nil)
assert_equal nil, @cache.read('foo')
end
def test_should_read_and_write_false
- assert @cache.write('foo', false)
- assert !@cache.read('foo')
+ assert_equal true, @cache.write('foo', false)
+ assert_equal false, @cache.read('foo')
end
def test_read_multi
@@ -262,19 +262,19 @@ def test_keys_are_case_sensitive
def test_exist
@cache.write('foo', 'bar')
- assert @cache.exist?('foo')
- assert !@cache.exist?('bar')
+ assert_equal true, @cache.exist?('foo')
+ assert_equal false, @cache.exist?('bar')
end
def test_nil_exist
@cache.write('foo', nil)
- assert @cache.exist?('foo')
+ assert_equal true, @cache.exist?('foo')
end
def test_delete
@cache.write('foo', 'bar')
assert @cache.exist?('foo')
- assert @cache.delete('foo')
+ assert_equal true, @cache.delete('foo')
assert !@cache.exist?('foo')
end
@@ -346,10 +346,10 @@ def test_race_condition_protection_is_safe
def test_crazy_key_characters
crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-"
- assert @cache.write(crazy_key, "1", :raw => true)
+ assert_equal true, @cache.write(crazy_key, "1", :raw => true)
assert_equal "1", @cache.read(crazy_key)
assert_equal "1", @cache.fetch(crazy_key)
- assert @cache.delete(crazy_key)
+ assert_equal true, @cache.delete(crazy_key)
assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" }
assert_equal 3, @cache.increment(crazy_key)
assert_equal 2, @cache.decrement(crazy_key)
@@ -358,12 +358,12 @@ def test_crazy_key_characters
def test_really_long_keys
key = ""
900.times{key << "x"}
- assert @cache.write(key, "bar")
+ assert_equal true, @cache.write(key, "bar")
assert_equal "bar", @cache.read(key)
assert_equal "bar", @cache.fetch(key)
assert_nil @cache.read("#{key}x")
assert_equal({key => "bar"}, @cache.read_multi(key))
- assert @cache.delete(key)
+ assert_equal true, @cache.delete(key)
end
end
@@ -375,10 +375,10 @@ module EncodedKeyCacheBehavior
Encoding.list.each do |encoding|
define_method "test_#{encoding.name.underscore}_encoded_values" do
key = "foo".force_encoding(encoding)
- assert @cache.write(key, "1", :raw => true)
+ assert_equal true, @cache.write(key, "1", :raw => true)
assert_equal "1", @cache.read(key)
assert_equal "1", @cache.fetch(key)
- assert @cache.delete(key)
+ assert_equal true, @cache.delete(key)
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
assert_equal 3, @cache.increment(key)
assert_equal 2, @cache.decrement(key)
@@ -387,18 +387,18 @@ module EncodedKeyCacheBehavior
def test_common_utf8_values
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
- assert @cache.write(key, "1", :raw => true)
+ assert_equal true, @cache.write(key, "1", :raw => true)
assert_equal "1", @cache.read(key)
assert_equal "1", @cache.fetch(key)
- assert @cache.delete(key)
+ assert_equal true, @cache.delete(key)
assert_equal "2", @cache.fetch(key, :raw => true) { "2" }
assert_equal 3, @cache.increment(key)
assert_equal 2, @cache.decrement(key)
end
def test_retains_encoding
key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8)
- assert @cache.write(key, "1", :raw => true)
+ assert_equal true, @cache.write(key, "1", :raw => true)
assert_equal Encoding::UTF_8, key.encoding
end
end
@@ -411,10 +411,10 @@ def test_delete_matched
@cache.write("foo/bar", "baz")
@cache.write("fu/baz", "bar")
@cache.delete_matched(/oo/)
- assert !@cache.exist?("foo")
- assert @cache.exist?("fu")
- assert !@cache.exist?("foo/bar")
- assert @cache.exist?("fu/baz")
+ assert_equal false, @cache.exist?("foo")
+ assert_equal true, @cache.exist?("fu")
+ assert_equal false, @cache.exist?("foo/bar")
+ assert_equal true, @cache.exist?("fu/baz")
end
end
@@ -443,7 +443,7 @@ def test_local_writes_are_persistent_on_the_remote_cache
retval = @cache.with_local_cache do
@cache.write('foo', 'bar')
end
- assert retval
+ assert_equal true, retval
assert_equal 'bar', @cache.read('foo')
end
@@ -595,11 +595,11 @@ def test_prune_size
@cache.read(2) && sleep(0.001)
@cache.read(4)
@cache.prune(@record_size * 3)
- assert @cache.exist?(5)
- assert @cache.exist?(4)
- assert !@cache.exist?(3)
- assert @cache.exist?(2)
- assert !@cache.exist?(1)
+ assert_equal true, @cache.exist?(5)
+ assert_equal true, @cache.exist?(4)
+ assert_equal false, @cache.exist?(3)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(1)
end
def test_prune_size_on_write
@@ -616,17 +616,17 @@ def test_prune_size_on_write
@cache.read(2) && sleep(0.001)
@cache.read(4) && sleep(0.001)
@cache.write(11, "llllllllll")
- assert @cache.exist?(11)
- assert @cache.exist?(10)
- assert @cache.exist?(9)
- assert @cache.exist?(8)
- assert @cache.exist?(7)
- assert !@cache.exist?(6)
- assert !@cache.exist?(5)
- assert @cache.exist?(4)
- assert !@cache.exist?(3)
- assert @cache.exist?(2)
- assert !@cache.exist?(1)
+ assert_equal true, @cache.exist?(11)
+ assert_equal true, @cache.exist?(10)
+ assert_equal true, @cache.exist?(9)
+ assert_equal true, @cache.exist?(8)
+ assert_equal true, @cache.exist?(7)
+ assert_equal false, @cache.exist?(6)
+ assert_equal false, @cache.exist?(5)
+ assert_equal true, @cache.exist?(4)
+ assert_equal false, @cache.exist?(3)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(1)
end
def test_pruning_is_capped_at_a_max_time
@@ -640,11 +640,11 @@ def @cache.delete_entry (*args)
@cache.write(4, "dddddddddd") && sleep(0.001)
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
@cache.prune(30, 0.001)
- assert @cache.exist?(5)
- assert @cache.exist?(4)
- assert @cache.exist?(3)
- assert @cache.exist?(2)
- assert !@cache.exist?(1)
+ assert_equal true, @cache.exist?(5)
+ assert_equal true, @cache.exist?(4)
+ assert_equal true, @cache.exist?(3)
+ assert_equal true, @cache.exist?(2)
+ assert_equal false, @cache.exist?(1)
end
end

0 comments on commit f312e21

Please sign in to comment.