Sha256: 046b8bd93b8e8597f3b9a1be3ade453283404a7259bf13ecff8d9e030ec54ac1

Contents?: true

Size: 1006 Bytes

Versions: 12

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

require "test_helper"

class SingleTableInheritanceTest < ActiveSupport::TestCase
  def test_superclass_find__caches_superclass_record
    animal = Animal.create
    assert_no_queries do
      assert_equal animal, Animal.find(animal.id)
    end
  end

  def test_superclass_find__caches_subclass_record
    dog = Dog.create
    assert_no_queries do
      assert_equal dog, Animal.find(dog.id)
    end
  end

  def test_subclass_find__caches_subclass_record
    dog = Dog.create
    dog_id = dog.id
    assert_no_queries do
      newdog = Dog.find(dog_id)
      assert_equal dog, newdog
    end
  end

  def test_subclass_find__doesnt_find_superclass_record
    animal = Animal.create
    assert_queries(:any) do
      assert_raises ActiveRecord::RecordNotFound do
        Dog.find(animal.id)
      end
    end
  end

  def test_superclass_find__caches_all_subclasses
    cat = Cat.create
    assert_no_queries do
      assert_equal cat, Animal.find(cat.id)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
second_level_cache-2.7.1 test/single_table_inheritance_test.rb
second_level_cache-2.7.0 test/single_table_inheritance_test.rb
second_level_cache-2.6.4 test/single_table_inheritance_test.rb
second_level_cache-2.6.3 test/single_table_inheritance_test.rb
second_level_cache-2.6.2 test/single_table_inheritance_test.rb
second_level_cache-2.6.1 test/single_table_inheritance_test.rb
second_level_cache-2.6.0 test/single_table_inheritance_test.rb
second_level_cache-2.5.3 test/single_table_inheritance_test.rb
second_level_cache-2.5.2 test/single_table_inheritance_test.rb
second_level_cache-2.5.0 test/single_table_inheritance_test.rb
second_level_cache-2.4.4 test/single_table_inheritance_test.rb
second_level_cache-2.4.3 test/single_table_inheritance_test.rb