Skip to content

Commit

Permalink
Merge branch 'enterprisemodules-fix_when_array_passed_to_find'
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Nov 17, 2023
2 parents 5c7b56c + 3bf52ee commit 7a07568
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/prefixed_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ module Finder

class_methods do
def find(*ids)
prefix_ids = *ids.map do |id|
# Skip if model doesn't use prefixed ids
next id unless _prefix_id.present?
# Skip if model doesn't use prefixed ids
return super if _prefix_id.blank?

prefix_ids = ids.flatten.map do |id|
prefix_id = _prefix_id.decode(id, fallback: _prefix_id_fallback)
raise Error, "#{id} is not a valid prefix_id" if !_prefix_id_fallback && prefix_id.nil?
prefix_id
end
prefix_ids = [prefix_ids] if ids.first.is_a?(Array)

super(*prefix_ids)
end

Expand Down
11 changes: 11 additions & 0 deletions test/prefixed_ids_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ class PrefixedIdsTest < ActiveSupport::TestCase
assert_equal [user, user2], User.find(user.prefix_id, user2.prefix_id)
end

test "overridden finders with array args" do
user = users(:one)
user2 = users(:two)
assert_equal [user, user2], User.find([user.prefix_id, user2.prefix_id])
end

test "overridden finders with single array args" do
user = users(:one)
assert_equal [user], User.find([user.prefix_id])
end

test "minimum length" do
assert_equal 32 + 5, accounts(:one).prefix_id.length
end
Expand Down

0 comments on commit 7a07568

Please sign in to comment.