Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Last active November 25, 2019 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredbeck/b931dc3b6d63c2fca1243dc3d8c66620 to your computer and use it in GitHub Desktop.
Save jaredbeck/b931dc3b6d63c2fca1243dc3d8c66620 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
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"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activerecord", "~> 6.0.1"
gem "sqlite3", "~> 1.4.1"
end
require "active_record"
require "minitest/autorun"
require "logger"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# 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 :projects, force: true do |t|
t.timestamps null: false
end
create_table :documents, force: true do |t|
t.belongs_to :project, null: false
t.timestamps null: false
end
end
class Project < ActiveRecord::Base
has_many :documents
after_touch :my_after_touch_callback
def my_after_touch_callback
$timestamp = updated_at_before_last_save
end
end
class Document < ActiveRecord::Base
belongs_to :project, touch: true
end
class BugTest < Minitest::Test
def test_1
p = Project.create
$timestamp = nil
p.touch
assert_kind_of Time, $timestamp # passes
end
def test_2
p = Project.create
d = Document.create(project: p)
$timestamp = nil
d.touch
assert_kind_of Time, $timestamp # fails
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment