Skip to content

Instantly share code, notes, and snippets.

@intrip
Created January 21, 2021 14:15
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 intrip/a9c83650e346d09866fefcb143cd2832 to your computer and use it in GitHub Desktop.
Save intrip/a9c83650e346d09866fefcb143cd2832 to your computer and use it in GitHub Desktop.
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'activerecord', '6.1'
gem "sqlite3"
end
require 'active_record'
require 'minitest/autorun'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :accounts do |t|
t.timestamps
t.string :name
end
create_table :users do |t|
t.references :account, foreign_key: true, index: true
t.timestamps
end
end
class Account < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :account
end
class BugTest < Minitest::Test
def test_inverse_of
a = Account.create!(name: 'a')
User.create!(account: a)
a = Account.first
u = a.users.first
assert a.name == u.account.name
a.name = 'a1'
assert a.name == u.account.name
u.account.name = 'a2'
assert a.name == u.account.name
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment