Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"
# Activate the gem you are reporting the issue against.
gem "rails", github: "rails/rails"
# gem "activerecord", "5.0.0"
# gem "activerecord", "4.2.7"
gem "sqlite3"
end
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|
t.string :title
end
create_table :comments, force: true do |t|
t.string :content
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! title: "Rails is so awesome"
post.comments << Comment.create!(content: "Sure it is")
post.comments << Comment.create!(content: "One hundred percent!!")
p post.comments.select { |c| c.content =~ /Sure/ }
p post.comments.select(:content) { |c| c.content =~ /Sure/ }
end
end
# Failure on Rails master, passes on Rails 4.2.7 and Rails 5.0.0
# 1) Error:
# BugTest#test_association_stuff:
# ArgumentError: wrong number of arguments (given 1, expected 0)
# /Users/prathamesh/.rbenv/versions/ruby-dev/lib/ruby/gems/2.4.0/bundler/gems/rails-06658f1d9db5/activerecord/lib/active_record/relation/query_methods.rb:245:in `select'
# /Users/prathamesh/.rbenv/versions/ruby-dev/lib/ruby/gems/2.4.0/bundler/gems/rails-06658f1d9db5/activerecord/lib/active_record/relation/query_methods.rb:245:in `select'
# select_regression.rb:54:in `test_association_stuff'
# 1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.