test/parser_test.rb in kasket-0.7.8 vs test/parser_test.rb in kasket-0.8.0
- old
+ new
@@ -23,10 +23,20 @@
should "support cachable queries" do
assert @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`id` = 2) ')
assert @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`id` = 2) LIMIT 1')
end
+ should "support IN queries on id" do
+ parsed_query = @parser.parse('SELECT * FROM `posts` WHERE (`posts`.`id` IN (1,2,3))')
+ assert(parsed_query)
+ assert_equal([[:id, ['1', '2', '3']]], parsed_query[:attributes])
+ end
+
+ should "not support IN queries on other attributes" do
+ assert(!@parser.parse('SELECT * FROM `posts` WHERE (`posts`.`hest` IN (1,2,3))'))
+ end
+
should "support vaguely formatted queries" do
assert @parser.parse('SELECT * FROM "posts" WHERE (title = red AND blog_id = big)')
end
context "extract options" do
@@ -64,15 +74,10 @@
end
should "include the OR operator" do
assert !@parser.parse('SELECT * FROM `posts` WHERE (title = red OR blog_id = big) LIMIT 2')
end
-
- should "include the IN operator" do
- assert !@parser.parse('SELECT * FROM `posts` WHERE (id IN (1,2,3))')
- end
-
end
context "key generation" do
should "include the table name and version" do
assert_match(/^kasket-#{Kasket::Version::STRING}\/posts\/version=3558\//, @parser.parse('SELECT * FROM `posts` WHERE (id = 1)')[:key])
@@ -80,9 +85,16 @@
should "include all indexed attributes" do
assert_match(/id=1$/, @parser.parse('SELECT * FROM `posts` WHERE (id = 1)')[:key])
assert_match(/blog_id=2\/id=1$/, @parser.parse('SELECT * FROM `posts` WHERE (id = 1 AND blog_id = 2)')[:key])
assert_match(/id=1\/title='title'$/, @parser.parse("SELECT * FROM `posts` WHERE (id = 1 AND title = 'title')")[:key])
+ end
+
+ should "generate multiple keys on IN queries" do
+ keys = @parser.parse('SELECT * FROM `posts` WHERE (id IN (1,2))')[:key]
+ assert_instance_of(Array, keys)
+ assert_match(/id=1$/, keys[0])
+ assert_match(/id=2$/, keys[1])
end
context "when limit 1" do
should "add /first to the key if the index does not include id" do
assert_match(/title='a'\/first$/, @parser.parse("SELECT * FROM `posts` WHERE (title = 'a') LIMIT 1")[:key])