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

Ensure that decode returns all parts of composite key #71

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Unreleased

* Ensure that decode returns all parts of composite key

### 1.8.0

* Add composite key support #70

### 1.7.1
Expand Down
4 changes: 2 additions & 2 deletions lib/prefixed_ids/prefix_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def decode(id, fallback: false)
if !valid?(decoded_hashid)
fallback_value
else
_, id, *composite = decoded_hashid
composite.empty? ? id : composite
_, *ids = decoded_hashid
ids.size == 1 ? ids.first : ids
excid3 marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/prefixed_ids_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ class PrefixedIdsTest < ActiveSupport::TestCase
decoded = hashid.decode(second)
assert_equal decoded.size, 2
assert_equal decoded, [1, 1]

prefix_decoded = prefix.decode(first)
assert_equal prefix_decoded, [1, 1]
end
end
end
Loading