-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and improve #valid_ulid? method
Co-authored-by: Benjamin Quorning <[email protected]>
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require "test_helper" | ||
|
||
class ULID::Rails::Type::DataTest < Minitest::Test | ||
def test_has_26_valid_characters | ||
id = "01BX5ZZKBKACTAV9WEVGEMMVRZ" | ||
|
||
assert ULID::Rails::Type::Data.valid_ulid?(id) | ||
end | ||
|
||
def test_length_less_than_26 | ||
id = "A" * 25 | ||
|
||
refute ULID::Rails::Type::Data.valid_ulid?(id) | ||
end | ||
|
||
def test_length_greater_than_26 | ||
id = "A" * 27 | ||
|
||
refute ULID::Rails::Type::Data.valid_ulid?(id) | ||
end | ||
|
||
# Crockford's Base32 is used as shown. This alphabet excludes | ||
# the letters I, L, O, and U to avoid confusion and abuse. | ||
# https://github.com/ulid/spec#encoding | ||
def test_has_invalid_characters | ||
invalid_characters = %w(I L O U) | ||
|
||
invalid_characters.each do |char| | ||
id = char * 26 | ||
|
||
refute ULID::Rails::Type::Data.valid_ulid?(id) | ||
end | ||
end | ||
end |