Permalink
Browse files

support :unless_exist for FileCache

  • Loading branch information...
grosser committed Aug 7, 2013
1 parent f90aa72 commit c17bd7476abb0bade3c27e652b1d56548d0ee4ae
@@ -1,3 +1,7 @@
+* Support :unless_exist in FileStore
+
+ *Michael Grosser*
+
* Ensure that autoloaded constants in all-caps nestings are marked as
autoloaded.
@@ -96,6 +96,7 @@ def read_entry(key, options)
def write_entry(key, entry, options)
file_name = key_file_path(key)
+ return false if options[:unless_exist] && File.exist?(file_name)
ensure_cache_path(File.dirname(file_name))
File.atomic_write(file_name, cache_path) {|f| Marshal.dump(entry, f)}
true
@@ -709,6 +709,13 @@ def test_log_exception_when_cache_read_fails
@cache.send(:read_entry, "winston", {})
assert @buffer.string.present?
end
+
+ def test_write_with_unless_exist
+ assert_equal true, @cache.write(1, "aaaaaaaaaa")
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
+ @cache.write(1, nil)
+ assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)
+ end
end
class MemoryStoreTest < ActiveSupport::TestCase

0 comments on commit c17bd74

Please sign in to comment.