-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fetch_multi_by_* support for cache_index with a single field
- Loading branch information
1 parent
32aac1a
commit 5d2c5ef
Showing
4 changed files
with
129 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "test_helper" | ||
|
||
class FetchMultiByTest < IdentityCache::TestCase | ||
NAMESPACE = IdentityCache::CacheKeyGeneration::DEFAULT_NAMESPACE | ||
|
||
def setup | ||
super | ||
@bob = Item.new | ||
@bob.id = 1 | ||
@bob.title = 'bob' | ||
|
||
@bertha = Item.new | ||
@bertha.id = 2 | ||
@bertha.title = 'bertha' | ||
end | ||
|
||
def test_fetch_multi_by_cache_key | ||
Item.cache_index :title, unique: false | ||
|
||
@bob.save! | ||
@bertha.save! | ||
|
||
assert_equal [@bob], Item.fetch_by_title('bob') | ||
|
||
assert_equal [@bob, @bertha], Item.fetch_multi_by_title(['bob', 'bertha']) | ||
end | ||
|
||
def test_fetch_multi_by_unique_cache_key | ||
Item.cache_index :title, unique: true | ||
|
||
@bob.save! | ||
@bertha.save! | ||
|
||
assert_equal @bob, Item.fetch_by_title('bob') | ||
|
||
assert_equal [@bob, @bertha], Item.fetch_multi_by_title(['bob', 'bertha']) | ||
end | ||
|
||
def test_fetch_multi_attribute_by_cache_key | ||
Item.cache_attribute :title, by: :id, unique: false | ||
|
||
@bob.save! | ||
@bertha.save! | ||
|
||
assert_equal ['bob'], Item.fetch_title_by_id(1) | ||
|
||
assert_equal({ 1 => ['bob'], 2 => ['bertha'] }, Item.fetch_multi_title_by_id([1, 2])) | ||
end | ||
|
||
|
||
def test_fetch_multi_attribute_by_unique_cache_key | ||
Item.cache_attribute :title, by: :id, unique: true | ||
|
||
@bob.save! | ||
@bertha.save! | ||
|
||
assert_equal 'bob', Item.fetch_title_by_id(1) | ||
|
||
assert_equal({ 1 => 'bob', 2 => 'bertha' }, Item.fetch_multi_title_by_id([1, 2])) | ||
end | ||
end |
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