Skip to content

Instantly share code, notes, and snippets.

@derekprior
Created April 24, 2015 18:37
Show Gist options
  • Save derekprior/f231c46d626697b9965f to your computer and use it in GitHub Desktop.
Save derekprior/f231c46d626697b9965f to your computer and use it in GitHub Desktop.
Reproducible error for 19863
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
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 = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
create_table :comments, force: true do |t|
t.integer :post_id
end
end
class Post < ActiveRecord::Base
has_many :comments
accepts_nested_attributes_for :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
ERROR = 'Comment has an error on base'
validate do |comment|
comment.errors.add(:base, ERROR)
end
end
class BugTest < Minitest::Test
def test_association_stuff
post = Post.new
post.comments << Comment.new
post.save
assert_equal [Comment::ERROR], post.errors.full_messages
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment