null+****@clear*****
null+****@clear*****
2011年 12月 19日 (月) 17:11:14 JST
Kouhei Sutou 2011-12-19 08:11:14 +0000 (Mon, 19 Dec 2011) New Revision: c0ecbd3bbece9c9104bd4022f9e0261aeba502e8 Log: [shcema][table-create] report error for neither type nor table key. refs #915 refs #1210 Modified files: lib/db.c test/unit/http/test-http-schema.rb Modified: lib/db.c (+10 -5) =================================================================== --- lib/db.c 2011-12-19 08:06:14 +0000 (933c4de) +++ lib/db.c 2011-12-19 08:11:14 +0000 (a942fb5) @@ -734,12 +734,17 @@ grn_table_create(grn_ctx *ctx, const char *name, unsigned name_size, key_size = sizeof(grn_id); break; default : - /* - if (key_type == grn_type_any) { - key_size = sizeof(grn_id) + sizeof(grn_id); + { + int key_name_size; + char key_name[GRN_TABLE_MAX_KEY_SIZE]; + key_name_size = grn_obj_name(ctx, key_type, key_name, + GRN_TABLE_MAX_KEY_SIZE); + ERR(GRN_INVALID_ARGUMENT, + "[table][create] key must by type or table: <%.*s> (%.*s)", + name_size, name, key_name_size, key_name); + GRN_API_RETURN(NULL); } - */ - key_size = sizeof(grn_id); + break; } } else { key_size = (flags & GRN_OBJ_KEY_VAR_SIZE) ? GRN_TABLE_MAX_KEY_SIZE : sizeof(grn_id); Modified: test/unit/http/test-http-schema.rb (+8 -6) =================================================================== --- test/unit/http/test-http-schema.rb 2011-12-19 08:06:14 +0000 (c60d901) +++ test/unit/http/test-http-schema.rb 2011-12-19 08:11:14 +0000 (1dcdd72) @@ -361,12 +361,13 @@ class HTTPSchemaTest < Test::Unit::TestCase end def test_invalid_key_type - omit("should implement error case") response = get(command_path(:table_create, :name => "users", :key_type => "table_create")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "[table][create] " + + "key must by type or table: " + + "<users> (table_create)", response, :content_type => "application/json") @@ -485,13 +486,14 @@ class HTTPSchemaTest < Test::Unit::TestCase end def test_invalid_key_type - omit("should implement error case") response = get(command_path(:table_create, :name => "users", :flags => Table::PAT_KEY, :key_type => "table_create")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "[table][create] " + + "key must by type or table: " + + "<users> (table_create)", response, :content_type => "application/json")