1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #11785 from grosser/grosser/file-unless-exist

support :unless_exist for FileCache

Conflicts:
	activesupport/CHANGELOG.md
	activesupport/test/caching_test.rb
This commit is contained in:
Rafael Mendonça França 2013-10-28 19:09:22 -02:00
commit f18cf8e488
3 changed files with 12 additions and 0 deletions

View file

@ -1,3 +1,7 @@
* Support :unless_exist in FileStore
*Michael Grosser*
* Fix `slice!` deleting the default value of the hash.
*Antonio Santos*

View file

@ -97,6 +97,7 @@ module ActiveSupport
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

View file

@ -721,6 +721,13 @@ class FileStoreTest < ActiveSupport::TestCase
assert @cache.exist?('baz')
assert @cache.exist?('quux')
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