Skip to content

Instantly share code, notes, and snippets.

@mjankowski
Last active June 18, 2024 23:45
Show Gist options
  • Save mjankowski/5fb5ca03b2d3e5198e62741222fab2b9 to your computer and use it in GitHub Desktop.
Save mjankowski/5fb5ca03b2d3e5198e62741222fab2b9 to your computer and use it in GitHub Desktop.
AR Promise Complete instance instead of value?
# frozen_string_literal: true
# RE: https://github.com/rails/rails/issues/50776#issuecomment-2148033957
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", "7.1.3.3"
gem "sqlite3", "~> 1.4"
end
require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
end
class Post < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_return_value
Post.cache do
@posts_count = Post.async_count
end
assert_equal 0, @posts_count.value
# When run from within `cache` block above, this requires `@posts_count.value.value`?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment