Skip to content

Instantly share code, notes, and snippets.

@jeremyevans
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyevans/9645417 to your computer and use it in GitHub Desktop.
Save jeremyevans/9645417 to your computer and use it in GitHub Desktop.
gem 'activerecord', '4.0.4'
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 "nodes", :force => true do |t|
t.column "node_id", :integer
end
end
class Node < ActiveRecord::Base
Node.belongs_to :parent, :class_name=>'Node', :foreign_key=>'node_id'
Node.has_many :children, :class_name=>'Node', :foreign_key=>'node_id'
end
class BugTest < Minitest::Test
def test_no_silent_failure_for_filtering_by_has_many_association
node1 = Node.create(:id=>1)
node2 = Node.create(:id=>2, :node_id=>1)
node3 = Node.create(:id=>3, :node_id=>2)
assert_equal node3, Node.where(:parent=>node2).first
refute_equal node3, Node.where(:children=>node2).first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment