Sha256: 0f4713e3ee2ff70604ccd20ef159bf98118c05e38ffe2e5cf23a956c856166f0

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

require "test_helper"

class CacheFetchIncludesTest < IdentityCache::TestCase
  def setup
    super
  end

  def test_cached_embedded_has_manys_are_included_in_includes
    Item.send(:cache_has_many, :associated_records, :embed => true)
    assert_equal [:associated_records], Item.send(:cache_fetch_includes)
  end

  def test_cached_nonembedded_has_manys_are_included_in_includes
    Item.send(:cache_has_many, :associated_records, :embed => :ids)
    assert_equal [], Item.send(:cache_fetch_includes)
  end

  def test_cached_has_ones_are_included_in_includes
    Item.send(:cache_has_one, :associated)
    assert_equal [:associated], Item.send(:cache_fetch_includes)
  end

  def test_cached_nonembedded_belongs_tos_are_not_included_in_includes
    Item.send(:cache_belongs_to, :item)
    assert_equal [], Item.send(:cache_fetch_includes)
  end

  def test_cached_child_associations_are_included_in_includes
    Item.send(:cache_has_many, :associated_records, :embed => true)
    AssociatedRecord.send(:cache_has_many, :deeply_associated_records, :embed => true)
    assert_equal [{:associated_records => [:deeply_associated_records]}], Item.send(:cache_fetch_includes)
  end

  def test_multiple_cached_associations_and_child_associations_are_included_in_includes
    Item.send(:cache_has_many, :associated_records, :embed => true)
    PolymorphicRecord.send(:include, IdentityCache::WithoutPrimaryIndex)
    Item.send(:cache_has_many, :polymorphic_records, {:inverse_name => :owner, :embed => true})
    Item.send(:cache_has_one, :associated, :embed => true)
    AssociatedRecord.send(:cache_has_many, :deeply_associated_records, :embed => true)
    assert_equal [
      {:associated_records => [:deeply_associated_records]},
      :polymorphic_records,
      {:associated => [:deeply_associated_records]}
    ],  Item.send(:cache_fetch_includes)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
identity_cache-0.5.1 test/cache_fetch_includes_test.rb
identity_cache-0.5.0 test/cache_fetch_includes_test.rb
identity_cache-0.4.1 test/cache_fetch_includes_test.rb