Sha256: a053786316c8d0ac2462ffd7102ae7664782ec636bb24ed56d1e311d7da785ee

Contents?: true

Size: 773 Bytes

Versions: 10

Compression:

Stored size: 773 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

10 entries across 10 versions & 2 rubygems

Version Path
ibm_db-3.0.4-x86-mingw32 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.4 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.3-x86-mingw32 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.3 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.2-x86-mingw32 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.2 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
activejob-lock-0.0.2 rails/activerecord/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.1 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
ibm_db-3.0.1-x86-mingw32 test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb
activejob-lock-0.0.1 rails/activerecord/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb