Sha256: 7f9e4fe1859f4ae12a915a75ee44612c6fda6e9e6ee99583ec2f70181c29ba04

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

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

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

  should "cache find(id) calls" do
    post = Post.first
    Rails.cache.write(post.kasket_key, nil)
    assert_equal(post, Post.find(post.id))
    assert(Rails.cache.read(post.kasket_key))
    Post.connection.expects(:select_all).never
    assert_equal(post, Post.find(post.id))
  end

  should "only cache on indexed attributes" do
    Kasket.cache.expects(:read).twice
    Post.find_by_id(1)
    Post.find_by_id(1, :conditions => {:blog_id => 2})

    Kasket.cache.expects(:read).never
    Post.first :conditions => {:blog_id => 2}
  end

  should "not use cache when using the :select option" do
    post = Post.first
    assert_nil(Rails.cache.read(post.kasket_key))

    Post.find(post.id, :select => 'title')
    assert_nil(Rails.cache.read(post.kasket_key))

    Post.find(post.id)
    assert(Rails.cache.read(post.kasket_key))

    Kasket.cache.expects(:read)
    Post.find(post.id, :select => nil)

    Kasket.cache.expects(:read).never
    Post.find(post.id, :select => 'title')
  end

  should "respect scope" do
    post = Post.find(Post.first.id)
    other_blog = Blog.first(:conditions => "id != #{post.blog_id}")

    assert(Rails.cache.read(post.kasket_key))

    assert_raise(ActiveRecord::RecordNotFound) do
      other_blog.posts.find(post.id)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kasket-0.6.4 test/find_one_test.rb
kasket-0.6.3 test/find_one_test.rb
kasket-0.6.2 test/find_one_test.rb
kasket-0.6.1 test/find_one_test.rb
kasket-0.6.0 test/find_one_test.rb