1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

View file

@ -90,7 +90,7 @@ module ActiveRecord
# :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

View file

@ -11,7 +11,7 @@ SIGNED_ID_VERIFIER_TEST_SECRET = -> { "This is normally set by the railtie initi
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")