2017-08-13 13:02:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-28 17:12:48 +00:00
|
|
|
require "bundler/inline"
|
2013-04-01 07:42:23 +00:00
|
|
|
|
2015-06-04 03:02:25 +00:00
|
|
|
gemfile(true) do
|
2016-08-06 17:21:59 +00:00
|
|
|
source "https://rubygems.org"
|
2017-09-27 08:55:43 +00:00
|
|
|
|
2017-09-26 21:02:11 +00:00
|
|
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
2017-09-27 08:55:43 +00:00
|
|
|
|
2021-01-19 20:43:24 +00:00
|
|
|
gem "rails", github: "rails/rails", branch: "main"
|
2016-08-06 17:21:59 +00:00
|
|
|
gem "sqlite3"
|
2015-06-04 03:02:25 +00:00
|
|
|
end
|
2013-04-01 07:42:23 +00:00
|
|
|
|
2016-08-06 17:21:59 +00:00
|
|
|
require "active_record"
|
|
|
|
require "minitest/autorun"
|
|
|
|
require "logger"
|
2013-04-01 07:42:23 +00:00
|
|
|
|
|
|
|
# This connection will do for database-independent bug reports.
|
2016-08-06 17:21:59 +00:00
|
|
|
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
2013-04-02 15:55:58 +00:00
|
|
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
2013-04-01 07:42:23 +00:00
|
|
|
|
|
|
|
ActiveRecord::Schema.define do
|
2016-05-05 13:07:31 +00:00
|
|
|
create_table :posts, force: true do |t|
|
2013-04-01 07:42:23 +00:00
|
|
|
end
|
|
|
|
|
2016-05-05 13:07:31 +00:00
|
|
|
create_table :comments, force: true do |t|
|
2013-04-01 07:42:23 +00:00
|
|
|
t.integer :post_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Post < ActiveRecord::Base
|
|
|
|
has_many :comments
|
|
|
|
end
|
|
|
|
|
|
|
|
class Comment < ActiveRecord::Base
|
|
|
|
belongs_to :post
|
|
|
|
end
|
|
|
|
|
2013-08-21 19:49:12 +00:00
|
|
|
class BugTest < Minitest::Test
|
2013-04-01 07:42:23 +00:00
|
|
|
def test_association_stuff
|
|
|
|
post = Post.create!
|
|
|
|
post.comments << Comment.create!
|
|
|
|
|
|
|
|
assert_equal 1, post.comments.count
|
|
|
|
assert_equal 1, Comment.count
|
|
|
|
assert_equal post.id, Comment.first.post.id
|
|
|
|
end
|
|
|
|
end
|