Sha256: 422bf0d68992b38f284d1500eeab810755546d221a92d2e4563b507e260b8e88

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

# collection_cache_versioning was added in Rails 6.0. It performs a
# SELECT COUNT(*), MAX(updated_at) which will have an unnecessary ORDER BY RANDOM()
# applied to it. That shouldn't hurt anything. This is a simple way to both
# cover that important code and ensure Unreliable works correctly with
# aggregate SELECTs.

RSpec.describe Cat do
  it "in ActiveRecord >= 6, calculates cache versions",
    skip: ((ActiveRecord::VERSION::MAJOR < 6) ? "test is for ActiveRecord >= 6 only" : false) do
    old_setting = ActiveRecord::Base.collection_cache_versioning
    ActiveRecord::Base.collection_cache_versioning = true
    Cat.new(name: "spot").save!
    Cat.new(name: "sadie").save!
    expect(Cat.where("name LIKE 's%'").cache_version).to start_with("2-")
    expect(Cat.where(name: "foo").cache_version).to eq("0")
  ensure
    Cat.delete_all
    ActiveRecord::Base.collection_cache_versioning = old_setting
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unreliable-0.10.0 spec/model_cache_versioning_spec.rb
unreliable-0.9.1 spec/model_cache_versioning_spec.rb
unreliable-0.9.0 spec/model_cache_versioning_spec.rb