[Groonga-commit] ranguba/groonga-client-model at b44dda5 [master] Use ActiveModel::Conversion

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Dec 7 14:21:06 JST 2016


Kouhei Sutou	2016-12-07 14:21:06 +0900 (Wed, 07 Dec 2016)

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

  Message:
    Use ActiveModel::Conversion

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

  Modified: lib/groonga_client_model/record.rb (+1 -20)
===================================================================
--- lib/groonga_client_model/record.rb    2016-12-07 11:55:04 +0900 (1958233)
+++ lib/groonga_client_model/record.rb    2016-12-07 14:21:06 +0900 (ce4ecfb)
@@ -18,6 +18,7 @@ module GroongaClientModel
   class Record
     extend ActiveModel::Naming
     include ActiveModel::Validations
+    include ActiveModel::Conversion
     include ActiveModel::AttributeMethods
     include ActiveModel::AttributeAssignment
 
@@ -150,30 +151,10 @@ module GroongaClientModel
       save
     end
 
-    def to_model
-      self
-    end
-
     def id
       _id
     end
 
-    def to_key
-      if persisted?
-        [id.to_s]
-      else
-        nil
-      end
-    end
-
-    def to_param
-      if persisted?
-        id.to_s
-      else
-        nil
-      end
-    end
-
     def new_record?
       @new_record
     end

  Modified: test/unit/test_record.rb (+28 -10)
===================================================================
--- test/unit/test_record.rb    2016-12-07 11:55:04 +0900 (1e2ad0b)
+++ test/unit/test_record.rb    2016-12-07 14:21:06 +0900 (3828f65)
@@ -15,20 +15,38 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 class TestRecord < Test::Unit::TestCase
-  class Memo < GroongaClientModel::Record
-    class << self
-      def columns
-        GroongaClientModel::Schema::Columns.new("_id" => {})
+  sub_test_case("ActiveModel") do
+    class EmptyModel < GroongaClientModel::Record
+      class << self
+        def columns
+          GroongaClientModel::Schema::Columns.new("_id" => {})
+        end
       end
     end
-  end
 
-  setup do
-    @memo = Memo.new
+    include ActiveModel::Lint::Tests
+
+    setup do
+      @model = EmptyModel.new
+    end
   end
 
-  test "#id" do
-    @memo._id = 29
-    assert_equal(29, @memo.id)
+  sub_test_case("readers") do
+    class Memo < GroongaClientModel::Record
+      class << self
+        def columns
+          GroongaClientModel::Schema::Columns.new("_id" => {})
+        end
+      end
+    end
+
+    setup do
+      @memo = Memo.new
+    end
+
+    test "#id" do
+      @memo._id = 29
+      assert_equal(29, @memo.id)
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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