-
-
Save casperisfine/9bf39e7d27e553cd0b951acfff461118 to your computer and use it in GitHub Desktop.
Bug report related to regression in https://github.com/rails/rails/pull/35127
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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', github: 'rails/rails' | |
gem "sqlite3" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
require 'tmpdir' | |
require 'yaml' | |
require 'fileutils' | |
# 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 :posts, force: true do |t| | |
t.integer :comments_count | |
end | |
create_table :comments, force: true do |t| | |
t.integer :post_id | |
t.string :name | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post, counter_cache: true | |
end | |
class BugTest < Minitest::Test | |
@@tmpdir = Dir.mktmpdir | |
puts @@tmpdir | |
posts_data = { | |
first_post: { | |
id: 762893243, | |
} | |
} | |
comments_data = { | |
first_comment: { | |
id: 133709458, | |
name: 'foo', | |
post_id: 762893243 | |
} | |
} | |
File.write("#{@@tmpdir}/posts.yml", YAML.dump(posts_data)) | |
File.write("#{@@tmpdir}/comments.yml", YAML.dump(comments_data)) | |
include ActiveRecord::TestFixtures | |
self.use_transactional_tests = false | |
self.fixture_path = @@tmpdir | |
fixtures :posts, :comments | |
def teardown | |
FileUtils.rm_rf(@@tmpdir) | |
end | |
def test_broken_stuff | |
post = Post.first | |
assert_equal 'foo', post.comments.first.name | |
post.comments.destroy_all | |
assert_equal 0, post.comments.count # No comments got destroyed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment