Skip to content

Instantly share code, notes, and snippets.

@jturkel
Created April 10, 2018 18:50
Show Gist options
  • Save jturkel/a4940d3486ebba51ef0381044144c0b2 to your computer and use it in GitHub Desktop.
Save jturkel/a4940d3486ebba51ef0381044144c0b2 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' # Works with '~> 5.1.0'
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
after_destroy do
association(:blog).target = blog
end
end
class BugTest < Minitest::Test
def test_bug
blog = Blog.create!
post = blog.posts.create!
post.reload
post.destroy!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment