Sha256: 7b01c6a4f2a0920c676cda2d43f158b3cc6499abf0f6b2eb5d602567054c62ec

Contents?: true

Size: 1.75 KB

Versions: 11

Compression:

Stored size: 1.75 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)
    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

11 entries across 11 versions & 1 rubygems

Version Path
identity_cache-0.4.0 test/cache_fetch_includes_test.rb
identity_cache-0.3.2 test/cache_fetch_includes_test.rb
identity_cache-0.3.1 test/cache_fetch_includes_test.rb
identity_cache-0.3.0 test/cache_fetch_includes_test.rb
identity_cache-0.2.5 test/cache_fetch_includes_test.rb
identity_cache-0.2.4 test/cache_fetch_includes_test.rb
identity_cache-0.2.3 test/cache_fetch_includes_test.rb
identity_cache-0.2.2 test/cache_fetch_includes_test.rb
identity_cache-0.2.1 test/cache_fetch_includes_test.rb
identity_cache-0.2.0 test/cache_fetch_includes_test.rb
identity_cache-0.1.0 test/cache_fetch_includes_test.rb