Sha256: 20af8c0ee6e995b1e26ab854f7a276f745f9daaa1b0bb8f377deb8b77ee813e1

Contents?: true

Size: 799 Bytes

Versions: 2

Compression:

Stored size: 799 Bytes

Contents

require "cases/helper"

class DeprecatedCounterCacheOnHasManyThroughTest < ActiveRecord::TestCase
  class Post < ActiveRecord::Base
    has_many :taggings, as: :taggable
    has_many :tags, through: :taggings
  end

  class Tagging < ActiveRecord::Base
    belongs_to :taggable, polymorphic: true
    belongs_to :tag
  end

  class Tag < ActiveRecord::Base
  end

  test "counter caches are updated in the database if the belongs_to association doesn't specify a counter cache" do
    post = Post.create!(title: 'Hello', body: 'World!')
    assert_deprecated { post.tags << Tag.create!(name: 'whatever') }

    assert_equal 1, post.tags.size
    assert_equal 1, post.tags_count
    assert_equal 1, post.reload.tags.size
    assert_equal 1, post.reload.tags_count
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ibm_db-3.0.5-x86-mingw32 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.5 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb