Sha256: 7a524c715cc1d2d7e58b5b8c9ef22803ea8135194fdb3ff85d62700c8dea0895

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require File.dirname(__FILE__) + '/helper'

class FindSomeTest < ActiveSupport::TestCase
  fixtures :blogs, :posts

  Post.has_cache_back

  should "cache find(id, id) calls" do
    post1 = Post.first
    post2 = Post.last

    assert_nil(Rails.cache.read(post1.cache_back_key))
    assert_nil(Rails.cache.read(post2.cache_back_key))

    Post.find(post1.id, post2.id)

    assert(Rails.cache.read(post1.cache_back_key))
    assert(Rails.cache.read(post2.cache_back_key))

    Post.connection.expects(:select_all).never
    Post.find(post1.id, post2.id)
  end

  should "only lookup the records that are not in the cache" do
    post1 = Post.first
    post2 = Post.last
    assert_equal(post1, Post.find(post1.id))
    assert(Rails.cache.read(post1.cache_back_key))
    assert_nil(Rails.cache.read(post2.cache_back_key))

    Post.expects(:find_some_without_cache_back).with([post2.id], {}).returns([post2])
    found_posts = Post.find(post1.id, post2.id)
    assert_equal([post1, post2].map(&:id).sort, found_posts.map(&:id).sort)

    Post.expects(:find_some_without_cache_back).never
    found_posts = Post.find(post1.id, post2.id)
    assert_equal([post1, post2].map(&:id).sort, found_posts.map(&:id).sort)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cache_back-0.4.1 test/find_some_test.rb