Kouhei Sutou
null+****@clear*****
Fri Jan 27 10:26:28 JST 2017
Kouhei Sutou 2017-01-27 10:26:28 +0900 (Fri, 27 Jan 2017) New Revision: 738aa898dea4f695447033c16f29f2e0c40fdc7b https://github.com/ranguba/groonga-client-model/commit/738aa898dea4f695447033c16f29f2e0c40fdc7b Message: Add Record.create Modified files: lib/groonga_client_model/record.rb test/apps/rails5/test/models/post_test.rb test/unit/test_record.rb Modified: lib/groonga_client_model/record.rb (+12 -0) =================================================================== --- lib/groonga_client_model/record.rb 2017-01-27 09:57:08 +0900 (d2bfb7e) +++ lib/groonga_client_model/record.rb 2017-01-27 10:26:28 +0900 (73ab5dd) @@ -98,6 +98,18 @@ module GroongaClientModel match_columns(full_text_searchable_column_names) end + def create(attributes=nil) + if attributes.is_a?(Array) + attributes.collect do |attrs| + create(attrs) + end + else + record = new(attributes) + record.save + record + end + end + private def define_method_attribute(name) define_method(name) do Modified: test/apps/rails5/test/models/post_test.rb (+12 -3) =================================================================== --- test/apps/rails5/test/models/post_test.rb 2017-01-27 09:57:08 +0900 (6d9d463) +++ test/apps/rails5/test/models/post_test.rb 2017-01-27 10:26:28 +0900 (28b5ad3) @@ -1,7 +1,16 @@ require 'test_helper' class PostTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + include GroongaClientModel::TestHelper + + test ".create(Hash)" do + post = Post.create(:title => "Hello") + assert_equal("Hello", Post.find(post.id).title) + end + + test ".create([Hash])" do + posts = Post.create([{:title => "Hello1"}, {:title => "Hello2"}]) + assert_equal(["Hello1", "Hello2"], + posts.collect {|post| Post.find(post.id).title}) + end end Modified: test/unit/test_record.rb (+1 -1) =================================================================== --- test/unit/test_record.rb 2017-01-27 09:57:08 +0900 (a3d0d76) +++ test/unit/test_record.rb 2017-01-27 10:26:28 +0900 (e036d63) @@ -1,4 +1,4 @@ -# Copyright (C) 2016 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2016-2017 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 -------------- next part -------------- HTML����������������������������...Download