-
Notifications
You must be signed in to change notification settings - Fork 22.2k
Closed
Labels
Description
Steps to reproduce
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", path: "./"
# gem "rails", github: "rails/rails", branch: "main"
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.collection_cache_versioning = true
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.timestamps
end
create_table :comments, force: true do |t|
t.integer :post_id
t.timestamps
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class BugTest < Minitest::Test
def test_association_cache_key
post = Post.create!
post.comments << Comment.create!
cache_key = post.comments.cache_key_with_version
comment = post.comments.first
comment.touch(:updated_at, time: Time.new(2021, 5, 1))
new_cache_key = post.comments.cache_key_with_version
refute_equal cache_key, new_cache_key
end
endExpected behavior
cache_key_with_version is different since max value of updated_at in the collection has changed.
Actual behavior
cache_key_with_version remains the same.
System configuration
Rails version: 6.1.3.1
Ruby version: 2.7.2
related issues/prs
Reactions are currently unavailable