Skip to content

Instantly share code, notes, and snippets.

@everton
Created May 30, 2014 02:56
Show Gist options
  • Save everton/91a2cb2aed4258218ad9 to your computer and use it in GitHub Desktop.
Save everton/91a2cb2aed4258218ad9 to your computer and use it in GitHub Desktop.
rails-4.1.2.rc2 before_create bug report
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.2.rc1'
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 :posts do |t|
t.timestamp :published_at
t.timestamps
end
end
class Post < ActiveRecord::Base
before_create do
self.published_at = self.created_at
end
end
class BugTest < Minitest::Test
def test_before_create
Post.create!
refute_nil Post.last.published_at,
"Didn't set 'published_at' on #before_create (because 'created_at' was nil)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment