[Groonga-commit] ranguba/groonga-client-model at a2eb636 [master] Record.find accepts record object

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Mon Mar 6 10:23:20 JST 2017


Kouhei Sutou	2017-03-06 10:23:20 +0900 (Mon, 06 Mar 2017)

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

  Message:
    Record.find accepts record object

  Modified files:
    lib/groonga_client_model/record.rb
    test/unit/test_record.rb

  Modified: lib/groonga_client_model/record.rb (+3 -0)
===================================================================
--- lib/groonga_client_model/record.rb    2017-03-06 10:22:10 +0900 (7f733ed)
+++ lib/groonga_client_model/record.rb    2017-03-06 10:23:20 +0900 (0a73f7e)
@@ -65,6 +65,9 @@ module GroongaClientModel
       end
 
       def find(id)
+        if id.respond_to?(:_id)
+          id = id._id
+        end
         record = select.filter("_id == %{id}", id: id).limit(1).first
         if record.nil?
           raise RecordNotFound.new("Record not found: _id: <#{id}>")

  Modified: test/unit/test_record.rb (+6 -6)
===================================================================
--- test/unit/test_record.rb    2017-03-06 10:22:10 +0900 (667d608)
+++ test/unit/test_record.rb    2017-03-06 10:23:20 +0900 (0cfe29d)
@@ -364,7 +364,7 @@ column_create timestamps updated_on COLUMN_SCALAR Time
     test("created_at") do
       now = Time.now
       timestamp = Timestamp.create
-      saved_timestamp = Timestamp.find(timestamp._id)
+      saved_timestamp = Timestamp.find(timestamp)
       assert do
         saved_timestamp.created_at > now
       end
@@ -373,7 +373,7 @@ column_create timestamps updated_on COLUMN_SCALAR Time
     test("created_on") do
       now = Time.now
       timestamp = Timestamp.create
-      saved_timestamp = Timestamp.find(timestamp._id)
+      saved_timestamp = Timestamp.find(timestamp)
       assert do
         saved_timestamp.created_on > now
       end
@@ -381,10 +381,10 @@ column_create timestamps updated_on COLUMN_SCALAR Time
 
     test("updated_at") do
       timestamp = Timestamp.create
-      saved_timestamp = Timestamp.find(timestamp._id)
+      saved_timestamp = Timestamp.find(timestamp)
       created_at = saved_timestamp.created_at
       saved_timestamp.save
-      updated_timestamp = Timestamp.find(timestamp._id)
+      updated_timestamp = Timestamp.find(timestamp)
       updated_timestamp.save
       assert do
         saved_timestamp.updated_at > created_at
@@ -393,10 +393,10 @@ column_create timestamps updated_on COLUMN_SCALAR Time
 
     test("updated_on") do
       timestamp = Timestamp.create
-      saved_timestamp = Timestamp.find(timestamp._id)
+      saved_timestamp = Timestamp.find(timestamp)
       created_on = saved_timestamp.created_on
       saved_timestamp.save
-      updated_timestamp = Timestamp.find(timestamp._id)
+      updated_timestamp = Timestamp.find(timestamp)
       updated_timestamp.save
       assert do
         saved_timestamp.updated_on > created_on
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る