Skip to content

Instantly share code, notes, and snippets.

@amuhle
Last active August 29, 2015 13:57
Show Gist options
  • Save amuhle/9516499 to your computer and use it in GitHub Desktop.
Save amuhle/9516499 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'mysql2'
require 'minitest/autorun'
require 'logger'
puts "ActiveRecord: #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(adapter: "mysql2", host: "localhost", database: "test")
ActiveRecord::Base.logger = Logger.new(STDOUT)
class Author < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.string :name
end
has_many :posts
end
class Post < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.column :author_id, :integer
t.string :title
t.string :body
end
belongs_to :author
end
class BugTest < MiniTest::Unit::TestCase
def test_select_values_works_with_arel_binds
connection = ActiveRecord::Base.connection
author = Author.create!(name: 'john')
Post.create!(author: author, title: 'foo', body: 'bar')
query = author.posts
#args = query ## uncomment this line, and comment the next to fail
args = query.to_sql
assert_equal(ActiveRecord::Result, connection.select_all(args).class)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment