Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohbarye/7a56f35e97fbbd47c46fb4d1f1b71b8c to your computer and use it in GitHub Desktop.
Save ohbarye/7a56f35e97fbbd47c46fb4d1f1b71b8c to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'activerecord', '7.0.5'
# gem 'activerecord', '7.0.4.3'
gem 'sqlite3'
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 'foos', force: :true do |t|
end
create_table 'bars', force: :true do |t|
end
create_table 'prefix_middles', force: :true do |t|
t.bigint 'foo_id'
t.bigint 'bar_id'
end
end
class Foo < ActiveRecord::Base
has_one :prefix_middle, class_name: 'Prefix::Middle'
has_one :bar, through: :prefix_middle
end
class Bar < ActiveRecord::Base
has_one :prefix_middle, class_name: 'Prefix::Middle'
has_one :foo, through: :prefix_middle
end
module Prefix
class Middle < ActiveRecord::Base
def self.table_name_prefix
'prefix_'
end
belongs_to :foo
belongs_to :bar
validates :bar_id, presence: true
end
end
class BugTest < Minitest::Test
def test_association_stuff
foo = Foo.create!
foo.create_bar!
foo.save! # <= This creates one middle record at 7.0.4.3, but not at 7.0.5
assert_equal 1, Prefix::Middle.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment