Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Created March 11, 2014 19:57
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 arthurnn/9493767 to your computer and use it in GitHub Desktop.
Save arthurnn/9493767 to your computer and use it in GitHub Desktop.
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 do |t|
end
create_table :comments do |t|
t.integer :post_id
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
class BugTest < MiniTest::Unit::TestCase
def test_association_stuff
post = Post.create!
com = Comment.create(post: post)
puts post.comments.inspect
post.comments = [com]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment