Fix AR signed IDs for STI models

Closes #40187.
This commit is contained in:
Muhammad Usman 2020-09-07 02:00:02 +02:00 committed by GitHub
parent 812a2c1d6c
commit 580eefe1bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

@ -90,7 +90,7 @@ def signed_id_verifier=(verifier)
# :nodoc:
def combine_signed_id_purposes(purpose)
[ name.underscore, purpose.to_s ].compact_blank.join("/")
[ base_class.name.underscore, purpose.to_s ].compact_blank.join("/")
end
end

@ -11,7 +11,7 @@
ActiveRecord::Base.signed_id_verifier_secret = SIGNED_ID_VERIFIER_TEST_SECRET
class SignedIdTest < ActiveRecord::TestCase
fixtures :accounts, :toys
fixtures :accounts, :toys, :companies
setup do
@account = Account.first
@ -26,6 +26,10 @@ class SignedIdTest < ActiveRecord::TestCase
assert_equal @toy, Toy.find_signed(@toy.signed_id)
end
test "find signed record for single table inheritance (STI Models)" do
assert_equal Company.first, Company.find_signed(Company.first.signed_id)
end
test "raise UnknownPrimaryKey when model have no primary key" do
error = assert_raises(ActiveRecord::UnknownPrimaryKey) do
Matey.find_signed("this will not be even verified")