aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_one_associations_test.rb
diff options
context:
space:
mode:
authorNick LaMuro <nicklamuro@gmail.com>2017-01-06 17:49:19 -0600
committerNick LaMuro <nicklamuro@gmail.com>2017-01-06 17:49:19 -0600
commitb42e594a43e00d00b018868481927584d358f756 (patch)
tree24b80a207fe66787179386c35837306e57cfa903 /activerecord/test/cases/associations/has_one_associations_test.rb
parent98c6e4e56ca2a8f9f987e12815f7cdf66e5f1485 (diff)
downloadrails-b42e594a43e00d00b018868481927584d358f756.tar.gz
rails-b42e594a43e00d00b018868481927584d358f756.tar.bz2
rails-b42e594a43e00d00b018868481927584d358f756.zip
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`
Diffstat (limited to 'activerecord/test/cases/associations/has_one_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb17
1 files changed, 17 insertions, 0 deletions
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