From b42e594a43e00d00b018868481927584d358f756 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Fri, 6 Jan 2017 17:49:19 -0600 Subject: Add failing test for where with joins This will cause a failure with the changes from 8e2e5f9: https://github.com/rails/rails/commit/8e2e5f9e3d1f434e265dc104ea9b00ff75702fc3 With the `singularize` call that is being done in that method when there is multiple nestings of associations (JOIN calling a JOIN) and the `stringify_keys!` is only called once here: https://github.com/rails/rails/blob/21e5fd4/activerecord/lib/active_record/relation/where_clause_factory.rb#L16 And not in the subsequent recursion in `.predicate_builder` --- .../cases/associations/has_one_associations_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index ed22a9802f..aa910ba409 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -648,6 +648,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase class SpecialBook < ActiveRecord::Base self.table_name = "books" belongs_to :author, class_name: "SpecialAuthor" + has_one :subscription, class_name: "SpecialSupscription", foreign_key: "subscriber_id" end class SpecialAuthor < ActiveRecord::Base @@ -655,6 +656,11 @@ class HasOneAssociationsTest < ActiveRecord::TestCase has_one :book, class_name: "SpecialBook", foreign_key: "author_id" end + class SpecialSupscription < ActiveRecord::Base + self.table_name = "subscriptions" + belongs_to :book, class_name: "SpecialBook" + end + def test_assocation_enum_works_properly author = SpecialAuthor.create!(name: "Test") book = SpecialBook.create!(status: "published") @@ -662,4 +668,15 @@ class HasOneAssociationsTest < ActiveRecord::TestCase refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: "published" }).count end + + def test_assocation_enum_works_properly_with_nested_join + author = SpecialAuthor.create!(name: "Test") + book = SpecialBook.create!(status: "published") + author.book = book + + where_clause = { books: { subscriptions: { subscriber_id: nil } } } + assert_nothing_raised do + SpecialAuthor.joins(book: :subscription).where.not(where_clause) + end + end end -- cgit v1.2.3