Skip to content

Instantly share code, notes, and snippets.

@JDutil
Created February 26, 2015 18:24
Show Gist options
  • Save JDutil/1710c49b6a39bb81dada to your computer and use it in GitHub Desktop.
Save JDutil/1710c49b6a39bb81dada to your computer and use it in GitHub Desktop.
rails issue 19087
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.1.rc2'
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, force: true do |t|
end
create_table :comments, force: true do |t|
t.integer :commentable_id
t.string :commentable_type
end
end
module CommentSource
extend ActiveSupport::Concern
included do
has_many :comments, as: :commentable
end
end
class Post < ActiveRecord::Base
include CommentSource
end
class Comment < ActiveRecord::Base
belongs_to :post, polymorphic: true
end
class BugTest < Minitest::Test
def test_association_stuff
post = Post.create!
post.comments << Comment.create!
assert_equal 1, post.comments.count
assert_equal 1, Comment.count
assert_equal [], Comment.where(commentable: []).to_a
assert_equal [], Post.where(comments: []).to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment