Created
February 17, 2017 01:35
-
-
Save awmichel/ba34381fe418f761932b12ef8ff2063f to your computer and use it in GitHub Desktop.
Pluck UUID Bug
This file contains 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
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" | |
gem "rails", github: "rails/rails" | |
gem "arel", github: "rails/arel" | |
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: "postgresql", | |
database: "testing", | |
username: "permitzone", | |
password: "permitzone", | |
host: '127.0.0.1' | |
) | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
enable_extension 'pgcrypto' | |
create_table :posts, force: true do |t| | |
end | |
create_table :comments, id: :uuid, force: true 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::Test | |
def test_association_stuff | |
post = Post.create! | |
post.comments << Comment.create! | |
ids = Post.joins(:comments).pluck('posts.id', 'comments.id') | |
assert_equal post.id, ids[0][0] | |
assert_equal post.comments.first.id, ids[0][1] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment