Created
February 14, 2021 12:33
-
-
Save xTRiM/c10a492fc64da29109bad61716df83a4 to your computer and use it in GitHub Desktop.
Dumb usage of after_commit
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" | |
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", "6.1.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 = nil | |
ActiveRecord::Schema.define do | |
create_table :posts, force: true do |t| | |
end | |
end | |
class Post < ActiveRecord::Base | |
def self.bulk_ops | |
find_each do | |
after_commit { p "Some doesn't expect that to happen in SecondTest, but they should" } | |
end | |
end | |
end | |
class FirstTest < Minitest::Test | |
def test_adds_after_commit_to_model | |
p "First test" | |
Post.create! | |
Post.bulk_ops | |
end | |
end | |
class SecondTest < Minitest::Test | |
def test_has_after_commit_triggered | |
p "Second test" | |
Post.create! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment