Skip to content

Instantly share code, notes, and snippets.

@Edouard-chin
Created November 14, 2017 11:02
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 Edouard-chin/ec08693500b17ed5f1f4bf3f78a28c01 to your computer and use it in GitHub Desktop.
Save Edouard-chin/ec08693500b17ed5f1f4bf3f78a28c01 to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '5.1.0'
gem 'sqlite3'
gem 'byebug'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'byebug'
# 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 :posts, force: true do |t|
t.string :author
end
end
class Post < ActiveRecord::Base
after_commit :set_foo, on: :update
attr_accessor :foo
attr_reader :bar
def _run_commit_callbacks
super
ensure
@foo = nil
end
def set_foo
if foo
@bar = true
end
end
end
class BugTest < Minitest::Test
def test_association_stuff
post = Post.create!
post.foo = true
post.author = 'John Doe'
post.touch
post.save
assert_equal true, post.bar
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment