-
-
Save Edouard-chin/ec08693500b17ed5f1f4bf3f78a28c01 to your computer and use it in GitHub Desktop.
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
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