Skip to content

Commit

Permalink
Add test for basic behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Scriven committed Mar 18, 2019
1 parent b6d21cf commit 724d6bf
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/fetch_multi_by_test.rb
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

0 comments on commit 724d6bf

Please sign in to comment.