Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created February 5, 2025 19:10
Show Gist options
  • Save tomykaira/db05e00bfdfeddd6be1426f9b7f415b6 to your computer and use it in GitHub Desktop.
Save tomykaira/db05e00bfdfeddd6be1426f9b7f415b6 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails"
gem "mysql2"
end
require "active_record/railtie"
require "minitest/autorun"
ENV["DATABASE_URL"] = "mysql2://root:[email protected]/test_database"
class TestApp < Rails::Application
config.load_defaults Rails::VERSION::STRING.to_f
config.eager_load = false
config.logger = Logger.new($stdout)
config.secret_key_base = "secret_key_base"
config.active_record.encryption.primary_key = "primary_key"
config.active_record.encryption.deterministic_key = "deterministic_key"
config.active_record.encryption.key_derivation_salt = "key_derivation_salt"
end
Rails.application.initialize!
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
create_table :comments, force: true do |t|
t.integer :post_id
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class BugTest < ActiveSupport::TestCase
def test_association_stuff
post = Post.create!
post.comments.create!
100.times do
th = Thread.new do
loop do
Rails.application.executor.wrap do
Post.find_by(id:post.id)
end
end
end
sleep(0.1)
th.exit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment