-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defaults to `truncate`, but can be set with the `clear_with` option. If `Rails.test.env?` is true though it will default to `delete` as truncation is not always transactional (e.g. in MySQL) so clearing the cache would break transactional tests.
- Loading branch information
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "test_helper" | ||
|
||
class DeleteMatchedTest < ActiveSupport::TestCase | ||
setup do | ||
@namespace = "test-#{SecureRandom.hex}" | ||
|
||
@delete_cache = lookup_store(expires_in: 60, clear_with: :delete) | ||
end | ||
|
||
test "clear by truncation" do | ||
cache = lookup_store(expires_in: 60, clear_with: :truncate) | ||
write_values(cache) | ||
|
||
cache.clear | ||
|
||
assert_equal cache.clear_with, :truncate | ||
assert_equal 0, uncached_entry_count | ||
end | ||
|
||
test "clear by deletion" do | ||
cache = lookup_store(expires_in: 60, clear_with: :delete) | ||
write_values(cache) | ||
|
||
cache.clear | ||
|
||
assert_equal cache.clear_with, :delete | ||
assert_equal 0, uncached_entry_count | ||
end | ||
|
||
private | ||
def write_values(cache) | ||
20.times.map { |i| cache.write("key#{i}", "value#{i}") } | ||
end | ||
end |