-
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.
- Loading branch information
Matt Scriven
committed
Mar 18, 2019
1 parent
b6d21cf
commit 724d6bf
Showing
1 changed file
with
61 additions
and
0 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
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 |