Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent double find #148

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/global_id/global_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def find(options = {})
end

def model_class
model_name.constantize
model = model_name.constantize

unless model <= GlobalID
model
else
raise ArgumentError, "GlobalID and SignedGlobalID cannot be used as model_class."
end
end

def ==(other)
Expand Down
3 changes: 3 additions & 0 deletions test/cases/global_id_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class GlobalIDCreationTest < ActiveSupport::TestCase
assert_equal Person, @person_uuid_gid.model_class
assert_equal Person::Child, @person_namespaced_gid.model_class
assert_equal PersonModel, @person_model_gid.model_class
assert_raise ArgumentError do
person_gid = GlobalID.find 'gid://bcx/SignedGlobalID/5'
end
end

test ':app option' do
Expand Down