[Groonga-commit] ranguba/groonga-client-model at b24ad04 [master] Don't specify both _id and _key on load

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Dec 12 15:56:29 JST 2016


Kouhei Sutou	2016-12-12 15:56:29 +0900 (Mon, 12 Dec 2016)

  New Revision: b24ad04f0ca3896d23fde6bd64e40e68d612891f
  https://github.com/ranguba/groonga-client-model/commit/b24ad04f0ca3896d23fde6bd64e40e68d612891f

  Message:
    Don't specify both _id and _key on load

  Modified files:
    lib/groonga_client_model/load_value_generator.rb
    test/unit/test_load_value_generator.rb

  Modified: lib/groonga_client_model/load_value_generator.rb (+3 -0)
===================================================================
--- lib/groonga_client_model/load_value_generator.rb    2016-12-12 12:31:23 +0900 (4ccdc5c)
+++ lib/groonga_client_model/load_value_generator.rb    2016-12-12 15:56:29 +0900 (95a6960)
@@ -27,6 +27,9 @@ module GroongaClientModel
       @record.attributes.each do |name, value|
         load_value[name] = format_value(value)
       end
+      if load_value.key?("_id") and load_value.key?("_key")
+        load_value.delete("_id")
+      end
       load_value
     end
 

  Modified: test/unit/test_load_value_generator.rb (+8 -0)
===================================================================
--- test/unit/test_load_value_generator.rb    2016-12-12 12:31:23 +0900 (3026e2b)
+++ test/unit/test_load_value_generator.rb    2016-12-12 15:56:29 +0900 (66e883e)
@@ -30,6 +30,7 @@ class TestLoadValueGenerator < Test::Unit::TestCase
     class << self
       def columns
         GroongaClientModel::Schema::Columns.new(nil,
+                                                "_id" => {},
                                                 "_key" => {})
       end
     end
@@ -68,4 +69,11 @@ class TestLoadValueGenerator < Test::Unit::TestCase
     assert_equal({"tags" => ["important", "groonga"]},
                  @generator.generate)
   end
+
+  test "_id and _key" do
+    tag = Tag.new(_id: 10, _key: "important")
+    generator = GroongaClientModel::LoadValueGenerator.new(tag)
+    assert_equal({"_key" => "important"},
+                 generator.generate)
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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