Created
July 20, 2023 02:02
-
-
Save pjambet/5aef5bcfa04d67d17db9aade23a827ed to your computer and use it in GitHub Desktop.
Example for bugsnag PR
This file contains 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" | |
require "active_support/concern" | |
require_relative "./repro_helper" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# Activate the gem you are reporting the issue against. | |
gem "activerecord", "~> 7.0.0" | |
gem "sqlite3" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
# 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| | |
end | |
create_table :comments, force: true do |t| | |
t.integer :post_id | |
t.text :body | |
end | |
# Adding this contrived index to cause the creation of a second comment to | |
# fail at the DB layer | |
add_index(:comments, :post_id, unique: true) | |
end | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
include Foo | |
belongs_to :post | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
Comment.delete_all | |
post = Post.create! | |
begin | |
post.comments.create! | |
# This will fail due to a uniqueness constraint, and because the Comment | |
# model includes the Foo module, the first "in-project" stacktrace will be | |
# from block.call in the file defining Foo | |
post.comments.create! | |
rescue StandardError => e | |
puts e.class | |
puts e.backtrace | |
end | |
comments_count = post.comments | |
assert_equal 1, comments_count | |
assert_equal 1, Comment.count | |
assert_equal post.id, Comment.first.post.id | |
end | |
end |
This file contains 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
module Foo | |
extend ActiveSupport::Concern | |
included do | |
around_create :around_cb | |
def around_cb(&block) | |
block.call | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment