|
3 | 3 | class TypeScopes::StringTest < TypeScopes::TestCase |
4 | 4 | def setup |
5 | 5 | TypeScopes::Transaction.connection.truncate(TypeScopes::Transaction.table_name) |
6 | | - TypeScopes::Transaction.create!(amount: 100, paid_at: "2021-06-23", description: "First transaction") |
7 | | - TypeScopes::Transaction.create!(amount: 200, paid_at: "2021-06-24", description: "Last transaction") |
| 6 | + TypeScopes::Transaction.create!(amount: 100, paid_at: "2021-06-23", description: "Lorem ipsum") |
| 7 | + TypeScopes::Transaction.create!(amount: 200, paid_at: "2021-06-24", description: "Lorem ipsum") |
8 | 8 | end |
9 | 9 |
|
10 | 10 | def test_like |
11 | | - assert_equal(1, TypeScopes::Transaction.description_like("%First%").count) |
12 | | - return unless like_case_sensitive? |
13 | | - assert_equal(0, TypeScopes::Transaction.description_like("%FIRST%").count) |
14 | | - assert_equal(1, TypeScopes::Transaction.description_like("%FIRST%", sensitive: false).count) |
| 11 | + assert_equal(2, TypeScopes::Transaction.description_like("%Lorem%").count) |
| 12 | + return unless sql_adapter_like_case_sensitive? |
| 13 | + assert_equal(0, TypeScopes::Transaction.description_like("%LOREM%").count) |
| 14 | + assert_equal(2, TypeScopes::Transaction.description_like("%LOREM%", sensitive: false).count) |
| 15 | + end |
| 16 | + |
| 17 | + def test_not_like |
| 18 | + assert_equal(0, TypeScopes::Transaction.description_not_like("%ipsum").count) |
| 19 | + return unless sql_adapter_like_case_sensitive? |
| 20 | + assert_equal(2, TypeScopes::Transaction.description_not_like("%IPSUM").count) |
| 21 | + assert_equal(0, TypeScopes::Transaction.description_not_like("%IPSUM", sensitive: false).count) |
15 | 22 | end |
16 | 23 |
|
17 | 24 | def test_ilike |
18 | | - assert_equal(1, TypeScopes::Transaction.description_ilike("%First%").count) |
19 | | - assert_equal(1, TypeScopes::Transaction.description_ilike("%FIRST%").count) |
| 25 | + assert_equal(0, TypeScopes::Transaction.description_ilike("%xxx%").count) |
| 26 | + assert_equal(2, TypeScopes::Transaction.description_ilike("LOREM%").count) |
| 27 | + end |
| 28 | + |
| 29 | + def test_not_ilike |
| 30 | + assert_equal(0, TypeScopes::Transaction.description_not_ilike("%IPSUM").count) |
| 31 | + assert_equal(2, TypeScopes::Transaction.description_not_ilike("%xxx%").count) |
20 | 32 | end |
21 | 33 |
|
22 | 34 | def test_contains |
23 | | - assert_equal(2, TypeScopes::Transaction.description_contains("t t").count) |
| 35 | + assert_equal(2, TypeScopes::Transaction.description_contains("m i").count) |
24 | 36 | assert_equal(0, TypeScopes::Transaction.description_contains("xxx").count) |
25 | 37 | end |
26 | 38 |
|
| 39 | + def test_does_not_contain |
| 40 | + assert_equal(0, TypeScopes::Transaction.description_does_not_contain("m i").count) |
| 41 | + assert_equal(2, TypeScopes::Transaction.description_does_not_contain("xxx").count) |
| 42 | + end |
| 43 | + |
27 | 44 | def test_starts_with |
28 | | - assert_equal(1, TypeScopes::Transaction.description_starts_with("First").count) |
29 | | - assert_equal(1, TypeScopes::Transaction.description_starts_with("FIRST", sensitive: false).count) |
30 | | - return unless like_case_sensitive? |
31 | | - assert_equal(0, TypeScopes::Transaction.description_starts_with("FIRST").count) |
| 45 | + assert_equal(2, TypeScopes::Transaction.description_starts_with("Lorem").count) |
| 46 | + assert_equal(2, TypeScopes::Transaction.description_starts_with("LOREM", sensitive: false).count) |
| 47 | + return unless sql_adapter_like_case_sensitive? |
| 48 | + assert_equal(0, TypeScopes::Transaction.description_starts_with("LOREM").count) |
| 49 | + end |
| 50 | + |
| 51 | + def test_does_not_start_with |
| 52 | + assert_equal(0, TypeScopes::Transaction.description_does_not_start_with("Lorem").count) |
| 53 | + assert_equal(0, TypeScopes::Transaction.description_does_not_start_with("LOREM", sensitive: false).count) |
| 54 | + return unless sql_adapter_like_case_sensitive? |
| 55 | + assert_equal(2, TypeScopes::Transaction.description_does_not_start_with("LOREM").count) |
32 | 56 | end |
33 | 57 |
|
34 | 58 | def test_ends_with |
35 | | - assert_equal(2, TypeScopes::Transaction.description_ends_with("tion").count) |
36 | | - assert_equal(2, TypeScopes::Transaction.description_ends_with("TION", sensitive: false).count) |
37 | | - return unless like_case_sensitive? |
38 | | - assert_equal(0, TypeScopes::Transaction.description_ends_with("TION").count) |
| 59 | + assert_equal(2, TypeScopes::Transaction.description_ends_with("ipsum").count) |
| 60 | + assert_equal(2, TypeScopes::Transaction.description_ends_with("IPSUM", sensitive: false).count) |
| 61 | + return unless sql_adapter_like_case_sensitive? |
| 62 | + assert_equal(0, TypeScopes::Transaction.description_ends_with("IPSUM").count) |
| 63 | + end |
| 64 | + |
| 65 | + def test_does_not_end_with |
| 66 | + assert_equal(0, TypeScopes::Transaction.description_does_not_end_with("ipsum").count) |
| 67 | + assert_equal(0, TypeScopes::Transaction.description_does_not_end_with("IPSUM", sensitive: false).count) |
| 68 | + return unless sql_adapter_like_case_sensitive? |
| 69 | + assert_equal(2, TypeScopes::Transaction.description_does_not_end_with("IPSUM").count) |
39 | 70 | end |
40 | 71 |
|
41 | 72 | def test_escaped_characters |
42 | 73 | assert_equal(0, TypeScopes::Transaction.description_contains("%").count) |
43 | 74 | assert_equal(0, TypeScopes::Transaction.description_contains("_").count) |
44 | 75 | end |
| 76 | + |
| 77 | + def test_matches |
| 78 | + skip unless sql_adapter_supports_regex? |
| 79 | + assert_equal(2, TypeScopes::Transaction.description_matches("Lorem.").count) |
| 80 | + assert_equal(2, TypeScopes::Transaction.description_matches("LOREM.", sensitive: false).count) |
| 81 | + assert_equal(0, TypeScopes::Transaction.description_matches("LOREM.").count) |
| 82 | + end |
| 83 | + |
| 84 | + def test_does_not_match |
| 85 | + skip unless sql_adapter_supports_regex? |
| 86 | + assert_equal(0, TypeScopes::Transaction.description_does_not_match("Lorem.").count) |
| 87 | + assert_equal(0, TypeScopes::Transaction.description_does_not_match("LOREM.", sensitive: false).count) |
| 88 | + assert_equal(2, TypeScopes::Transaction.description_does_not_match("LOREM.").count) |
| 89 | + end |
45 | 90 | end |
0 commit comments