-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Trailblazer | ||
class Finder | ||
module Utils | ||
class HashTest < Minitest::Test | ||
def setup | ||
@hash = [{ id: 1, value: 'Test 1' }, { id: 2, value: 'Test 2' }, { id: 3, value: '' }, | ||
{ id: 4, value: 'Test 4' }] | ||
end | ||
|
||
def test_deep_locate | ||
expected_result = [{ id: 2, value: 'Test 2' }] | ||
actual_result = Hash.deep_locate(->(k, v, _) { k == :value && v.to_s == 'Test 2' && !v.nil? }, @hash) | ||
assert_equal expected_result, actual_result | ||
end | ||
|
||
def test_returns_empty_when_nothing_found | ||
expected_result = [] | ||
actual_result = Hash.deep_locate(:muff, foo: 'bar') | ||
assert_equal expected_result, actual_result | ||
end | ||
end | ||
end | ||
end | ||
end |
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Trailblazer | ||
class Finder | ||
module Utils | ||
class SplitterTest < Minitest::Test | ||
def test_initialize | ||
splitter = Splitter.new 'attribute_eq', 'value' | ||
assert_equal 'attribute_eq', splitter.key | ||
assert_equal 'value', splitter.value | ||
end | ||
|
||
def test_split_key_exists | ||
splitter = Splitter.new 'attribute_eq', 'value' | ||
assert_equal false, splitter.split_key('random') | ||
assert_equal true, splitter.split_key('eq') | ||
end | ||
|
||
def test_field_value_when_split_key_exists | ||
splitter = Splitter.new 'attribute_eq', 'value' | ||
splitter.split_key('eq') | ||
assert_equal 'attribute', splitter.field | ||
end | ||
|
||
def test_predicate_value_when_split_key_exists | ||
splitter = Splitter.new 'attribute_eq', 'value' | ||
splitter.split_key('eq') | ||
assert_equal :eq, splitter.predicate | ||
end | ||
end | ||
end | ||
end | ||
end |
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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
module Trailblazer | ||
class Finder | ||
module Utils | ||
class StringTest < Minitest::Test | ||
def test_blank | ||
assert_equal true, String.blank?('') | ||
assert_equal true, String.blank?(nil) | ||
assert_equal false, String.blank?('what') | ||
assert_equal false, String.blank?(1) | ||
end | ||
|
||
def test_numeric | ||
assert_equal false, String.numeric?('') | ||
assert_equal false, String.numeric?(nil) | ||
assert_equal true, String.numeric?(1) | ||
assert_equal true, String.numeric?(0) | ||
assert_equal true, String.numeric?(1.00000) | ||
assert_equal true, String.numeric?('1') | ||
end | ||
|
||
def test_date | ||
assert_equal true, String.date?('2024-01-01') | ||
assert_equal false, String.date?(nil) | ||
assert_equal false, String.date?('random') | ||
assert_equal false, String.date?(1) | ||
assert_equal true, String.date?('2024/01/01') | ||
assert_equal true, String.date?('2024.01.01') | ||
assert_equal true, String.date?('21-12-2024') | ||
assert_equal false, String.date?('0fae2de1-6537-4d36-9cdb-30edf1e37990') | ||
end | ||
|
||
def test_to_date | ||
assert_equal '2024-09-28', String.to_date('28/09/2024') | ||
assert_equal '2024-09-28', String.to_date('2024/09/28') | ||
assert_equal '2024-09-28', String.to_date('28 september 2024') | ||
assert_nil String.to_date('third month of this year') | ||
end | ||
|
||
def test_camelize | ||
assert_equal 'Paging', String.camelize(:paging) | ||
assert_equal 'SomeRandomTest', String.camelize(:some_random_test) | ||
end | ||
|
||
def test_underscore | ||
assert_equal 'very_popular', String.underscore(:veryPopular) | ||
assert_equal 'very_popular', String.underscore(:VeryPopular) | ||
assert_equal 'somethingvery_popular_but_random', String.underscore(:SomethingveryPopularButRandom) | ||
assert_equal 'very_popular', String.underscore('Very Popular') | ||
end | ||
end | ||
end | ||
end | ||
end |