Kouhei Sutou
null+****@clear*****
Wed Jan 11 17:30:52 JST 2017
Kouhei Sutou 2017-01-11 17:30:52 +0900 (Wed, 11 Jan 2017) New Revision: 2b95e230b7e027269e43deb71bbb58ff0dc3dc7b https://github.com/ranguba/groonga-client/commit/2b95e230b7e027269e43deb71bbb58ff0dc3dc7b Message: Fix filter value escaption Modified files: lib/groonga/client/request/select.rb test/request/test-select.rb Modified: lib/groonga/client/request/select.rb (+5 -5) =================================================================== --- lib/groonga/client/request/select.rb 2017-01-11 17:23:35 +0900 (9afae71) +++ lib/groonga/client/request/select.rb 2017-01-11 17:30:52 +0900 (92465b1) @@ -304,9 +304,9 @@ module Groonga def escape_script_syntax_value(value) case value when Numeric - value + value.to_s when TrueClass, FalseClass - value + value.to_s when NilClass "null" when String @@ -317,7 +317,7 @@ module Groonga escaped_value = "[" value.each_with_index do |element, i| escaped_value << ", " if i > 0 - escaped_value << escape_filter_value(element) + escaped_value << escape_script_syntax_value(element) end escaped_value << "]" escaped_value @@ -325,9 +325,9 @@ module Groonga escaped_value = "{" value.each_with_index do |(k, v), i| escaped_value << ", " if i > 0 - escaped_value << escape_filter_value(k.to_s) + escaped_value << escape_script_syntax_value(k.to_s) escaped_value << ": " - escaped_value << escape_filter_value(v) + escaped_value << escape_script_syntax_value(v) end escaped_value << "}" escaped_value Modified: test/request/test-select.rb (+74 -0) =================================================================== --- test/request/test-select.rb 2017-01-11 17:23:35 +0900 (6e01434) +++ test/request/test-select.rb 2017-01-11 17:30:52 +0900 (3de02f5) @@ -19,6 +19,80 @@ class TestRequestSelect < Test::Unit::TestCase @request = Groonga::Client::Request::Select.new("posts") end + sub_test_case("#filter") do + def filter(*args) + @request.filter(*args).to_parameters + end + + test("Numeric") do + assert_equal({ + :table => "posts", + :filter => "rate == 5", + }, + filter("rate == %{rate}", :rate => 5)) + end + + test("true") do + assert_equal({ + :table => "posts", + :filter => "published == true", + }, + filter("published == %{published}", :published => true)) + end + + test("false") do + assert_equal({ + :table => "posts", + :filter => "published == false", + }, + filter("published == %{published}", :published => false)) + end + + test("nil") do + assert_equal({ + :table => "posts", + :filter => "function(null)", + }, + filter("function(%{arg})", :arg => nil)) + end + + test("String") do + assert_equal({ + :table => "posts", + :filter => "title == \"Hello\"", + }, + filter("title == %{title}", :title => "Hello")) + end + + test("Symbol") do + assert_equal({ + :table => "posts", + :filter => "title == \"Hello\"", + }, + filter("title == %{title}", :title => :Hello)) + end + + test("Array") do + assert_equal({ + :table => "posts", + :filter => "function([\"a\", 29])", + }, + filter("function(%{arg})", :arg => ["a", 29])) + end + + test("Hash") do + assert_equal({ + :table => "posts", + :filter => "function({\"string\": \"value\", \"number\": 29})", + }, + filter("function(%{options})", + :options => { + "string" => "value", + "number" => 29 + })) + end + end + sub_test_case("#drilldowns") do def drilldown @request.drilldowns("label") -------------- next part -------------- HTML����������������������������... 下载