[Groonga-commit] ranguba/groonga-client-rails at 286100f [master] Accept Array for match_columns

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Mar 27 15:02:05 JST 2016


Kouhei Sutou	2016-03-27 15:02:05 +0900 (Sun, 27 Mar 2016)

  New Revision: 286100f84cca9ae3cadff3f68d8c8c54d9f8088d
  https://github.com/ranguba/groonga-client-rails/commit/286100f84cca9ae3cadff3f68d8c8c54d9f8088d

  Message:
    Accept Array for match_columns

  Added files:
    test/unit/request_test.rb
  Copied files:
    test/unit/run-test.rb
      (from test/run-test.rb)
    test/unit/test_helper.rb
      (from test/run-test.rb)
  Modified files:
    lib/groonga/client/searcher/request.rb
    test/run-test.rb

  Modified: lib/groonga/client/searcher/request.rb (+17 -3)
===================================================================
--- lib/groonga/client/searcher/request.rb    2016-03-23 14:51:40 +0900 (2b9b77e)
+++ lib/groonga/client/searcher/request.rb    2016-03-27 15:02:05 +0900 (8968b7a)
@@ -14,6 +14,8 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "active_support/core_ext/object/blank"
+
 module Groonga
   class Client
     class Searcher
@@ -87,9 +89,21 @@ module Groonga
         end
 
         def to_parameters
-          {
-            match_columns: @match_columns,
-          }
+          if @match_columns.blank?
+            {}
+          else
+            case @match_columns
+            when ::Array
+              match_columns = @match_columns.join(", ")
+            when Symbol
+              match_columns = @match_columns.to_s
+            else
+              match_columns = @match_columns
+            end
+            {
+              match_columns: match_columns,
+            }
+          end
         end
       end
 

  Modified: test/run-test.rb (+8 -1)
===================================================================
--- test/run-test.rb    2016-03-23 14:51:40 +0900 (db331ed)
+++ test/run-test.rb    2016-03-27 15:02:05 +0900 (cbdee18)
@@ -18,8 +18,15 @@
 
 require "rbconfig"
 
+unless system(RbConfig.ruby, "test/unit/run-test.rb", *ARGV)
+  exit(false)
+end
+
 Dir.glob("#{__dir__}/fixtures/*") do |test_application|
   Dir.chdir(test_application) do
-    system(RbConfig.ruby, "-S", "rake", "test", "TESTOPTS=#{ARGV.join(' ')}")
+    unless system(RbConfig.ruby, "-S", "rake",
+                  "test", "TESTOPTS=#{ARGV.join(' ')}")
+      exit(false)
+    end
   end
 end

  Added: test/unit/request_test.rb (+59 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/request_test.rb    2016-03-27 15:02:05 +0900 (50dd40a)
@@ -0,0 +1,59 @@
+# Copyright (C) 2016  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require_relative "test_helper"
+
+class MatchColumnsRequestTest < Test::Unit::TestCase
+  def match_columns_request(match_columns)
+    Groonga::Client::Searcher::MatchColumnsRequest.new(match_columns)
+  end
+
+  def test_nil
+    assert_equal({},
+                 match_columns_request(nil).to_parameters)
+  end
+
+  def test_string
+    assert_equal({
+                   :match_columns => "title",
+                 },
+                 match_columns_request("title").to_parameters)
+  end
+
+  def test_empty_string
+    assert_equal({},
+                 match_columns_request("").to_parameters)
+  end
+
+  def test_symbol
+    assert_equal({
+                   :match_columns => "title",
+                 },
+                 match_columns_request(:title).to_parameters)
+  end
+
+  def test_array
+    assert_equal({
+                   :match_columns => "title, body",
+                 },
+                 match_columns_request(["title", "body"]).to_parameters)
+  end
+
+  def test_empty_array
+    assert_equal({},
+                 match_columns_request([]).to_parameters)
+  end
+end

  Copied: test/unit/run-test.rb (+6 -6) 80%
===================================================================
--- test/run-test.rb    2016-03-23 14:51:40 +0900 (db331ed)
+++ test/unit/run-test.rb    2016-03-27 15:02:05 +0900 (0ce3b09)
@@ -16,10 +16,10 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "rbconfig"
+require "test-unit"
 
-Dir.glob("#{__dir__}/fixtures/*") do |test_application|
-  Dir.chdir(test_application) do
-    system(RbConfig.ruby, "-S", "rake", "test", "TESTOPTS=#{ARGV.join(' ')}")
-  end
-end
+$VERBOSE = true
+
+$LOAD_PATH.unshift(File.join(__dir__, "..", "..", "lib"))
+
+exit(Test::Unit::AutoRunner.run(true, __dir__))

  Copied: test/unit/test_helper.rb (+1 -7) 80%
===================================================================
--- test/run-test.rb    2016-03-23 14:51:40 +0900 (db331ed)
+++ test/unit/test_helper.rb    2016-03-27 15:02:05 +0900 (0f4d4a1)
@@ -16,10 +16,4 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "rbconfig"
-
-Dir.glob("#{__dir__}/fixtures/*") do |test_application|
-  Dir.chdir(test_application) do
-    system(RbConfig.ruby, "-S", "rake", "test", "TESTOPTS=#{ARGV.join(' ')}")
-  end
-end
+require "groonga/client/searcher"
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index