Created
December 4, 2017 20:27
-
-
Save afair/b4cc7904a24476b5bba9fc3d133978e1 to your computer and use it in GitHub Desktop.
Possible AR Polymorphic Association Regression (5.2.0.beta2)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# https://raw.githubusercontent.com/rails/rails/master/guides/bug_report_templates/active_record_master.rb | |
gem "bundler", "< 1.16" | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: "rails/rails" | |
#gem 'rails', '~> 5.2.0.beta2' | |
#gem "sqlite3" | |
gem "pg" | |
end | |
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.establish_connection("postgresql://localhost/arpoly?pool=3") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
enable_extension 'uuid-ossp' | |
enable_extension 'pgcrypto' | |
create_table :posts, id: :uuid, force: true do |t| | |
t.timestamps null:false | |
end | |
create_table :trackers, force: true do |t| | |
t.string :track_type , null:false | |
t.uuid :track_id , null:false | |
t.timestamps null:false | |
end | |
end | |
class Post < ActiveRecord::Base | |
has_one :tracker, as: :track | |
end | |
class Tracker < ActiveRecord::Base | |
belongs_to :track, polymorphic:true | |
end | |
class BugTest < Minitest::Test | |
def test_association_stuff | |
post = Post.create | |
Tracker.create(track:post) | |
tracker = Tracker.first | |
p tracker | |
post = tracker.track | |
p post | |
assert_equal tracker.track_id, post.id | |
#assert_equal 1, post.comments.count | |
#assert_equal 1, Comment.count | |
#assert_equal post.id, Comment.first.post.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment