diff --git a/lib/ulid/generate.rb b/lib/ulid/generate.rb index fe205ee..0e5496b 100644 --- a/lib/ulid/generate.rb +++ b/lib/ulid/generate.rb @@ -19,10 +19,7 @@ def encode32 b32 = value.to_s(32) b32.tr!(B32_RCF4648_FRAGMENT, B32_CROCKFORD_FRAGMENT) b32.upcase! - - return "0#{b32}" if b32.length == 25 - - b32 + b32.rjust(26, "0") end def encode16 diff --git a/spec/ulid_spec.rb b/spec/ulid_spec.rb index e4052ea..81e418d 100644 --- a/spec/ulid_spec.rb +++ b/spec/ulid_spec.rb @@ -64,6 +64,10 @@ expect(ulid_string).to be_instance_of(String) end + it 'generates the minimum ULID at the Unix epoch' do + expect(ULID.min_ulid_at(Time.at(0))).to eq("00000000000000000000000000") + end + it 'generates the lowest lexicographical ULID' do expect(ulid_string).to match(/0000000000000000$/) end @@ -265,6 +269,10 @@ expect(other.bytes).to eq(first.bytes) expect(other.time).to eq(first.time) end + + it 'pads the lowest possible encoded value to 26 characters' do + expect(ULID.new(0).ulid).to eq("00000000000000000000000000") + end end describe 'compared to other ULIDs' do