From 2df891dccdcfbdfb176c55297589712ac379f87d Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Fri, 19 Feb 2016 15:31:56 -0800
Subject: eliminate warnings about multiple primary keys on habtm join tables

habtm join tables commonly have two id columns and it's OK to make those
two id columns a primary key.  This commit eliminates the warnings for
join tables that have this setup.

  ManageIQ/manageiq#6713
---
 .../has_and_belongs_to_many_associations_test.rb            | 13 +++++++++++++
 1 file changed, 13 insertions(+)

(limited to 'activerecord/test/cases/associations')

diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 5c4586da19..bae4197aaf 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -146,6 +146,19 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
     assert_equal 1, country.treaties.count
   end
 
+  def test_join_table_composit_primary_key_should_not_warn
+    country = Country.new(:name => 'India')
+    country.country_id = 'c1'
+    country.save!
+
+    treaty = Treaty.new(:name => 'peace')
+    treaty.treaty_id = 't1'
+    warning = capture(:stderr) do
+      country.treaties << treaty
+    end
+    assert_no_match(/WARNING: Rails does not support composite primary key\./, warning)
+  end
+
   def test_has_and_belongs_to_many
     david = Developer.find(1)
 
-- 
cgit v1.2.3