Skip to content

Instantly share code, notes, and snippets.

@jturkel
Last active March 29, 2018 15:15
Show Gist options
  • Save jturkel/3980f7d9bb0cd9f892766648538e1966 to your computer and use it in GitHub Desktop.
Save jturkel/3980f7d9bb0cd9f892766648538e1966 to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.2.0.rc2' # works with '5.1.5'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
puts "Using ActiveRecord #{ActiveRecord::VERSION::STRING}"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
# Schema
ActiveRecord::Schema.define do
ActiveRecord::Base.connection.create_table(:blogs) do |t|
end
ActiveRecord::Base.connection.create_table(:posts) do |t|
t.integer :blog_id
end
end
# Models
class Blog < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :blog
end
class BugTest < Minitest::Test
def test_bug
blog = Blog.create!
post = blog.posts.create!
post.reload
post.destroy!
::ActiveRecord::Associations::Preloader.new.preload([post], [:blog])
assert_equal(blog, post.blog)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment