Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test case for bug in Rails 4.0.10.rc
# Activate the gem you are reporting the issue against.
# gem 'activerecord', '4.0.9' # works
gem 'activerecord', '4.0.10.rc1'
# gem 'activerecord', '4.1.5' # works
# gem 'activerecord', '4.1.6.rc1'
gem 'pg'
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.establish_connection(adapter: 'postgresql', database: 'test')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
unless ActiveRecord::Base.connection.table_exists?(:contacts)
create_table :contacts do |t|
t.string :company, :name
t.boolean :is_company
end
end
unless ActiveRecord::Base.connection.table_exists?(:properties)
create_table :properties do |t|
t.integer :contact_id
end
end
unless ActiveRecord::Base.connection.table_exists?(:things)
create_table :things do |t|
t.integer :property_id
end
end
end
class Contact < ActiveRecord::Base
has_many :properties
end
class Property < ActiveRecord::Base
belongs_to :contact
has_many :things
end
class Thing < ActiveRecord::Base
belongs_to :property
end
class BugTest < Minitest::Test
def test_stuff
# contact = Contact.create!(company: 'Basecamp', name: 'David Heinemeier Hansson')
q = Property.includes(:things, :contact)
q = q.order('CASE WHEN contacts.is_company THEN UPPER(contacts.company) ELSE UPPER(contacts.name) END').references(:contacts)
p q.limit(10)
# PG::SyntaxError
end
end
@nathany

This comment has been minimized.

Copy link
Owner Author

nathany commented Aug 21, 2014

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.