diff options
author | Jochen Topf <jochen@topf.org> | 2014-05-17 11:30:34 +0200 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2014-05-17 11:30:34 +0200 |
commit | c0120d1b6515783d956cbb77def951e8fe85d624 (patch) | |
tree | 7405e3ce45602733677e0f8f2c30ea398354867f /web/test | |
parent | b5670d4f86d71a8bc1e558c50cfd421d991dae26 (diff) | |
download | taginfo-c0120d1b6515783d956cbb77def951e8fe85d624.tar taginfo-c0120d1b6515783d956cbb77def951e8fe85d624.tar.gz |
Escape _ and % in SQL LIKE queries.
Fixes #40.
Diffstat (limited to 'web/test')
-rw-r--r-- | web/test/test_utils.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/web/test/test_utils.rb b/web/test/test_utils.rb new file mode 100644 index 0000000..7d0afce --- /dev/null +++ b/web/test/test_utils.rb @@ -0,0 +1,26 @@ +$: << 'lib' +require File.join(File.dirname(__FILE__), '..', 'lib', 'utils.rb') +require 'test/unit' + +class TestSql < Test::Unit::TestCase + + def test_like_escape + assert_equal 'x@%y', like_escape('x%y') + assert_equal 'x@_', like_escape('x_') + assert_equal '@@a', like_escape('@a') + assert_equal '', like_escape('') + assert_equal '', like_escape(nil) + end + + def test_like_prefix + assert_equal 'postal@_%', like_prefix('postal_') + assert_equal '@%foo%', like_prefix('%foo') + end + + def test_like_contains + assert_equal '%name%', like_contains('name') + assert_equal '%foo@_bar%', like_contains('foo_bar') + assert_equal '%@@123%', like_contains('@123') + end + +end |