diff --git a/lib/prefixed_ids.rb b/lib/prefixed_ids.rb index 96a2d5f..e7ce9bf 100644 --- a/lib/prefixed_ids.rb +++ b/lib/prefixed_ids.rb @@ -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 diff --git a/test/prefixed_ids_test.rb b/test/prefixed_ids_test.rb index d31c611..8edd30e 100644 --- a/test/prefixed_ids_test.rb +++ b/test/prefixed_ids_test.rb @@ -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