Skip to content

Instantly share code, notes, and snippets.

@BlakeWilliams
Created March 2, 2025 15:41
Show Gist options
  • Save BlakeWilliams/b2f3a5f84e0eeb38b9772dd854bfe90d to your computer and use it in GitHub Desktop.
Save BlakeWilliams/b2f3a5f84e0eeb38b9772dd854bfe90d 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"
# If you want to test against edge Rails replace the previous line with this:
# gem "rails", github: "rails/rails", branch: "main"
gem "sqlite3"
end
require "active_record/railtie"
require "active_job/railtie"
require "minitest/autorun"
# This connection will do for database-independent bug reports.
ENV["DATABASE_URL"] = "sqlite3::memory:"
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"
config.active_record.query_log_tags_enabled = true
# taken directly from the docs
config.active_record.query_log_tags =[ :application, :controller, :action, :job]
end
Rails.application.initialize!
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
end
class Post < ActiveRecord::Base
end
class OuterJob < ActiveJob::Base
def perform
Post.first
InnerJob.perform_now
Post.second
end
end
class InnerJob < ActiveJob::Base
def perform
puts "Hello world"
end
end
class BugTest < ActiveSupport::TestCase
def test_query_association
queries = []
ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload|
queries << payload[:sql]
Rails.logger.info "[SQL] #{payload[:sql]}" if ENV["DEBUG_QUERIES"] == 1
end
OuterJob.perform_now
refute queries.any? { |query| query.match?(/InnerJob/) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment