Skip to content

Commit

Permalink
Merge pull request #1 from dtaniwaki/alphabet-option
Browse files Browse the repository at this point in the history
Add alphabet option
  • Loading branch information
dtaniwaki committed May 12, 2016
2 parents 6ccd1ce + 9fad7e1 commit c0aa58f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/acts_as_hashids/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def acts_as_hashids(options = {})

define_singleton_method :hashids do
length = options[:length] || 8
Hashids.new(hashids_secret, length)
alphabet = options[:alphabet] || Hashids::DEFAULT_ALPHABET
Hashids.new(hashids_secret, length, alphabet)
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/acts_as_hashids/methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@ def create_model(name, options = {})
expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 16).encode(1)
end
end
context 'with custom alphabet' do
subject { create_model 'MethodsFoo', alphabet: '1234567890abcdef' }
it 'returns the hashids instance' do
expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8, '1234567890abcdef').encode(1)
end
end
end
end

0 comments on commit c0aa58f

Please sign in to comment.