Skip to content

Commit

Permalink
Fix finding multiple non-hashids
Browse files Browse the repository at this point in the history
  • Loading branch information
jcypret committed Jan 8, 2017
1 parent f1887a7 commit 23caa22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/hashid/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def encode_id(ids)

def decode_id(ids)
if ids.is_a?(Array)
ids.map { |id| hashid_decode(id) }
decoded_ids = ids.map { |id| hashid_decode(id) }
decoded_ids.any? ? decoded_ids : nil
else
hashid_decode(ids)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/hashid/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
expect(decoded_ids).to eql [1, 3, 5]
end

it "finds muliple un-encoded ids" do
model_one = FakeModel.create!
model_two = FakeModel.create!

FakeModel.find([model_one.id, model_two.id])

FakeModel.delete_all
end

it "encodes multiple ids" do
encoded_ids = FakeModel.encode_id([2, 4, 6])
expect(encoded_ids).to eq %w(YznovR OeVre9 YNAOva)
Expand Down

0 comments on commit 23caa22

Please sign in to comment.