rroonga 1.2.9 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/Gemfile +1 -0
  2. data/Rakefile +1 -0
  3. data/bin/grntest-log-analyze +123 -0
  4. data/bin/groonga-query-log-extract +117 -0
  5. data/ext/groonga/rb-grn-accessor.c +7 -5
  6. data/ext/groonga/rb-grn-array-cursor.c +1 -1
  7. data/ext/groonga/rb-grn-array.c +34 -44
  8. data/ext/groonga/rb-grn-column.c +74 -38
  9. data/ext/groonga/rb-grn-context.c +19 -15
  10. data/ext/groonga/rb-grn-database.c +47 -42
  11. data/ext/groonga/rb-grn-double-array-trie-cursor.c +40 -0
  12. data/ext/groonga/rb-grn-double-array-trie.c +530 -0
  13. data/ext/groonga/rb-grn-encoding-support.c +1 -1
  14. data/ext/groonga/rb-grn-encoding.c +1 -1
  15. data/ext/groonga/rb-grn-exception.c +1 -1
  16. data/ext/groonga/rb-grn-expression-builder.c +1 -1
  17. data/ext/groonga/rb-grn-expression.c +63 -51
  18. data/ext/groonga/rb-grn-fix-size-column.c +7 -7
  19. data/ext/groonga/rb-grn-hash-cursor.c +1 -1
  20. data/ext/groonga/rb-grn-hash.c +42 -39
  21. data/ext/groonga/rb-grn-index-column.c +35 -31
  22. data/ext/groonga/rb-grn-index-cursor.c +1 -1
  23. data/ext/groonga/rb-grn-logger.c +23 -18
  24. data/ext/groonga/rb-grn-object.c +40 -27
  25. data/ext/groonga/rb-grn-operator.c +1 -1
  26. data/ext/groonga/rb-grn-patricia-trie-cursor.c +1 -1
  27. data/ext/groonga/rb-grn-patricia-trie.c +122 -90
  28. data/ext/groonga/rb-grn-plugin.c +8 -7
  29. data/ext/groonga/rb-grn-posting.c +1 -1
  30. data/ext/groonga/rb-grn-procedure.c +1 -1
  31. data/ext/groonga/rb-grn-query.c +12 -12
  32. data/ext/groonga/rb-grn-record.c +1 -1
  33. data/ext/groonga/rb-grn-snippet.c +26 -19
  34. data/ext/groonga/rb-grn-table-cursor-key-support.c +1 -1
  35. data/ext/groonga/rb-grn-table-cursor.c +4 -3
  36. data/ext/groonga/rb-grn-table-key-support.c +23 -23
  37. data/ext/groonga/rb-grn-table.c +268 -153
  38. data/ext/groonga/rb-grn-type.c +11 -7
  39. data/ext/groonga/rb-grn-utils.c +4 -1
  40. data/ext/groonga/rb-grn-variable-size-column.c +1 -1
  41. data/ext/groonga/rb-grn-variable.c +2 -2
  42. data/ext/groonga/rb-grn-view-accessor.c +1 -1
  43. data/ext/groonga/rb-grn-view-cursor.c +1 -1
  44. data/ext/groonga/rb-grn-view-record.c +1 -1
  45. data/ext/groonga/rb-grn-view.c +43 -34
  46. data/ext/groonga/rb-grn.h +6 -2
  47. data/ext/groonga/rb-groonga.c +1 -1
  48. data/lib/groonga.rb +4 -2
  49. data/lib/groonga/context.rb +16 -41
  50. data/lib/groonga/dumper.rb +6 -4
  51. data/lib/groonga/expression-builder.rb +52 -26
  52. data/lib/groonga/grntest-log.rb +206 -0
  53. data/lib/groonga/pagination.rb +21 -19
  54. data/lib/groonga/patricia-trie.rb +7 -10
  55. data/lib/groonga/posting.rb +1 -1
  56. data/lib/groonga/query-log.rb +348 -0
  57. data/lib/groonga/record.rb +47 -143
  58. data/lib/groonga/schema.rb +679 -406
  59. data/lib/groonga/view-record.rb +4 -10
  60. data/rroonga-build.rb +1 -1
  61. data/test/test-array.rb +25 -4
  62. data/test/test-column.rb +8 -8
  63. data/test/test-database.rb +2 -3
  64. data/test/test-double-array-trie.rb +164 -0
  65. data/test/test-expression-builder.rb +2 -2
  66. data/test/test-expression.rb +10 -9
  67. data/test/test-gqtp.rb +2 -2
  68. data/test/test-hash.rb +32 -8
  69. data/test/test-patricia-trie.rb +34 -10
  70. data/test/test-query-log.rb +258 -0
  71. data/test/test-record.rb +6 -5
  72. data/test/test-schema-create-table.rb +8 -0
  73. data/test/test-schema.rb +491 -234
  74. data/test/test-table.rb +17 -24
  75. metadata +123 -100
  76. data/ext/groonga/Makefile +0 -233
@@ -42,11 +42,11 @@ class PatriciaTrieTest < Test::Unit::TestCase
42
42
 
43
43
  def test_search
44
44
  users = Groonga::Array.create(:name => "Users")
45
- user_name = users.define_column("name", "ShortText")
45
+ users.define_column("name", "ShortText")
46
46
 
47
47
  bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
48
48
  :key_type => "ShortText")
49
- bookmark_user_id = bookmarks.define_column("user_id", users)
49
+ bookmarks.define_column("user_id", users)
50
50
 
51
51
  daijiro = users.add
52
52
  daijiro["name"] = "daijiro"
@@ -187,10 +187,10 @@ class PatriciaTrieTest < Test::Unit::TestCase
187
187
  def test_prefix_search
188
188
  paths = Groonga::PatriciaTrie.create(:name => "Paths",
189
189
  :key_type => 'ShortText')
190
- root_path = paths.add('/')
191
- tmp_path = paths.add('/tmp')
192
- usr_bin_path = paths.add('/usr/bin')
193
- usr_local_bin_path = paths.add('/usr/local/bin')
190
+ paths.add('/')
191
+ paths.add('/tmp')
192
+ paths.add('/usr/bin')
193
+ paths.add('/usr/local/bin')
194
194
 
195
195
  records = paths.prefix_search('/')
196
196
  assert_equal(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
@@ -213,10 +213,10 @@ class PatriciaTrieTest < Test::Unit::TestCase
213
213
  def test_prefix_cursor
214
214
  paths = Groonga::PatriciaTrie.create(:name => "Paths",
215
215
  :key_type => 'ShortText')
216
- root_path = paths.add('/')
217
- tmp_path = paths.add('/tmp')
218
- usr_bin_path = paths.add('/usr/bin')
219
- usr_local_bin_path = paths.add('/usr/local/bin')
216
+ paths.add('/')
217
+ paths.add('/tmp')
218
+ paths.add('/usr/bin')
219
+ paths.add('/usr/local/bin')
220
220
 
221
221
  assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
222
222
  paths, "/", {:order => :desc})
@@ -388,4 +388,28 @@ class PatriciaTrieTest < Test::Unit::TestCase
388
388
  bob_again = users.add("bob")
389
389
  assert_not_predicate(bob_again, :added?)
390
390
  end
391
+
392
+ def test_defrag
393
+ users = Groonga::PatriciaTrie.create(:name => "Users",
394
+ :key_type => "ShortText")
395
+ users.define_column("name", "ShortText")
396
+ users.define_column("address", "ShortText")
397
+ 1000.times do |i|
398
+ users.add("user #{i}",
399
+ :name => "user #{i}" * 1000,
400
+ :address => "address #{i}" * 1000)
401
+ end
402
+ assert_equal(7, users.defrag)
403
+ end
404
+
405
+ def test_rename
406
+ users = Groonga::PatriciaTrie.create(:name => "Users",
407
+ :key_type => "ShortText")
408
+ name = users.define_column("name", "ShortText")
409
+ address = users.define_column("address", "ShortText")
410
+
411
+ users.rename("People")
412
+ assert_equal(["People", "People.name", "People.address"],
413
+ [users.name, name.name, address.name])
414
+ end
391
415
  end
@@ -0,0 +1,258 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License version 2.1 as published by the Free Software Foundation.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ require "cgi"
18
+
19
+ module QueryLogTest
20
+ module CommandParseTestUtils
21
+ private
22
+ def command(name, parameters)
23
+ Groonga::QueryLog::Command.new(name, parameters)
24
+ end
25
+
26
+ def parse_http_path(command, parameters)
27
+ path = "/d/#{command}.json"
28
+ unless parameters.empty?
29
+ uri_parameters = parameters.collect do |key, value|
30
+ [CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
31
+ end
32
+ path << "?"
33
+ path << uri_parameters.join("&")
34
+ end
35
+ Groonga::QueryLog::Command.parse(path)
36
+ end
37
+
38
+ def parse_command_line(command, parameters)
39
+ command_line = "#{command} --output_type json"
40
+ parameters.each do |key, value|
41
+ if /"| / =~ value
42
+ escaped_value = '"' + value.gsub(/"/, '\"') + '"'
43
+ else
44
+ escaped_value = value
45
+ end
46
+ command_line << " --#{key} #{escaped_value}"
47
+ end
48
+ Groonga::QueryLog::Command.parse(command_line)
49
+ end
50
+ end
51
+
52
+ module HTTPCommandParseTestUtils
53
+ private
54
+ def parse(command, parameters={})
55
+ parse_http_path(command, parameters)
56
+ end
57
+ end
58
+
59
+ module CommandLineCommandParseTestUtils
60
+ private
61
+ def parse(command, parameters={})
62
+ parse_command_line(command, parameters)
63
+ end
64
+ end
65
+
66
+ module SelectCommandParseTests
67
+ include CommandParseTestUtils
68
+
69
+ def test_parameters
70
+ select = parse("select",
71
+ :table => "Users",
72
+ :filter => "age<=30")
73
+ assert_equal(command("select",
74
+ "table" => "Users",
75
+ "filter" => "age<=30",
76
+ "output_type" => "json"),
77
+ select)
78
+ end
79
+
80
+ def test_scorer
81
+ select = parse("select",
82
+ :table => "Users",
83
+ :filter => "age<=30",
84
+ :scorer => "_score = random()")
85
+ assert_equal("_score = random()", select.scorer)
86
+ end
87
+
88
+ def test_to_uri_format
89
+ select = parse("select",
90
+ :table => "Users",
91
+ :filter => "age<=30")
92
+ assert_equal("/d/select.json?filter=age%3C%3D30&table=Users",
93
+ select.to_uri_format)
94
+ end
95
+
96
+ def test_to_command_format
97
+ select = parse("select",
98
+ :table => "Users",
99
+ :filter => "age<=30")
100
+ assert_equal("select --filter \"age<=30\" " +
101
+ "--output_type \"json\" --table \"Users\"",
102
+ select.to_command_format)
103
+ end
104
+ end
105
+
106
+ module SelectCommandParseFilterTests
107
+ include CommandParseTestUtils
108
+
109
+ def test_parenthesis
110
+ filter = 'geo_in_rectangle(location,' +
111
+ '"35.73360x139.7394","62614x139.7714") && ' +
112
+ '((type == "たいやき" || type == "和菓子")) && ' +
113
+ 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
114
+ select = parse("select",
115
+ :table => "Users",
116
+ :filter => filter)
117
+ assert_equal(['geo_in_rectangle(location,' +
118
+ '"35.73360x139.7394","62614x139.7714")',
119
+ 'type == "たいやき"',
120
+ 'type == "和菓子"',
121
+ 'keyword @ "たいやき"',
122
+ 'keyword @ "白"',
123
+ 'keyword @ "養殖"'],
124
+ select.conditions)
125
+ end
126
+
127
+ def test_to_uri_format
128
+ filter = 'geo_in_rectangle(location,' +
129
+ '"35.73360x139.7394","62614x139.7714") && ' +
130
+ '((type == "たいやき" || type == "和菓子")) && ' +
131
+ 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
132
+ select = parse("select",
133
+ :table => "Users",
134
+ :filter => filter)
135
+ assert_equal("/d/select.json?filter=geo_in_rectangle%28location%2C" +
136
+ "%2235.73360x139.7394%22%2C%2262614x139.7714%22%29+" +
137
+ "%26%26+%28%28type+" +
138
+ "%3D%3D+%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+" +
139
+ "%7C%7C+type+%3D%3D+" +
140
+ "%22%E5%92%8C%E8%8F%93%E5%AD%90%22%29%29+" +
141
+ "%26%26+keyword+%40+" +
142
+ "%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+%26%21+" +
143
+ "keyword+%40+%22%E7%99%BD%22+%26%21+" +
144
+ "keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
145
+ select.to_uri_format)
146
+ end
147
+
148
+ def test_to_command_format
149
+ filter = 'geo_in_rectangle(location,' +
150
+ '"35.73360x139.7394","62614x139.7714") && ' +
151
+ '((type == "たいやき" || type == "和菓子")) && ' +
152
+ 'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
153
+ select = parse("select",
154
+ :table => "Users",
155
+ :filter => filter)
156
+ assert_equal("select " +
157
+ "--filter " +
158
+ "\"geo_in_rectangle(location," +
159
+ "\\\"35.73360x139.7394\\\",\\\"62614x139.7714\\\") && " +
160
+ "((type == \\\"たいやき\\\" || " +
161
+ "type == \\\"和菓子\\\")) && " +
162
+ "keyword @ \\\"たいやき\\\" &! keyword @ \\\"白\\\" &! " +
163
+ "keyword @ \\\"養殖\\\"\" " +
164
+ "--output_type \"json\" --table \"Users\"",
165
+ select.to_command_format)
166
+ end
167
+ end
168
+
169
+ class HTTPSelectCommandParseTest < Test::Unit::TestCase
170
+ include SelectCommandParseTests
171
+ include SelectCommandParseFilterTests
172
+ include HTTPCommandParseTestUtils
173
+
174
+ def test_uri_format?
175
+ command = parse("status")
176
+ assert_predicate(command, :uri_format?)
177
+ end
178
+
179
+ def test_command_format?
180
+ command = parse("status")
181
+ assert_not_predicate(command, :command_format?)
182
+ end
183
+ end
184
+
185
+ class CommandLineSelecCommandParseTest < Test::Unit::TestCase
186
+ include SelectCommandParseTests
187
+ include SelectCommandParseFilterTests
188
+ include CommandLineCommandParseTestUtils
189
+
190
+ def test_uri_format?
191
+ command = parse("status")
192
+ assert_not_predicate(command, :uri_format?)
193
+ end
194
+
195
+ def test_command_format?
196
+ command = parse("status")
197
+ assert_predicate(command, :command_format?)
198
+ end
199
+ end
200
+
201
+ class StatisticOperationParseTest < Test::Unit::TestCase
202
+ def test_context
203
+ operations = statistics.first.operations.collect do |operation|
204
+ [operation[:name], operation[:context]]
205
+ end
206
+ expected = [
207
+ ["filter", "local_name @ \"gsub\""],
208
+ ["filter", "description @ \"string\""],
209
+ ["select", nil],
210
+ ["sort", "_score"],
211
+ ["output", "_key"],
212
+ ["drilldown", "name"],
213
+ ["drilldown", "class"],
214
+ ]
215
+ assert_equal(expected, operations)
216
+ end
217
+
218
+ def test_n_records
219
+ operations = statistics.first.operations.collect do |operation|
220
+ [operation[:name], operation[:n_records]]
221
+ end
222
+ expected = [
223
+ ["filter", 15],
224
+ ["filter", 13],
225
+ ["select", 13],
226
+ ["sort", 10],
227
+ ["output", 10],
228
+ ["drilldown", 3],
229
+ ["drilldown", 2],
230
+ ]
231
+ assert_equal(expected, operations)
232
+ end
233
+
234
+ private
235
+ def log
236
+ <<-EOL
237
+ 2011-06-02 16:27:04.731685|5091e5c0|>/d/select.join?table=Entries&filter=local_name+%40+%22gsub%22+%26%26+description+%40+%22string%22&sortby=_score&output_columns=_key&drilldown=name,class
238
+ 2011-06-02 16:27:04.733539|5091e5c0|:000000001849451 filter(15)
239
+ 2011-06-02 16:27:04.734978|5091e5c0|:000000003293459 filter(13)
240
+ 2011-06-02 16:27:04.735012|5091e5c0|:000000003327415 select(13)
241
+ 2011-06-02 16:27:04.735096|5091e5c0|:000000003411824 sort(10)
242
+ 2011-06-02 16:27:04.735232|5091e5c0|:000000003547265 output(10)
243
+ 2011-06-02 16:27:04.735606|5091e5c0|:000000003921419 drilldown(3)
244
+ 2011-06-02 16:27:04.735762|5091e5c0|:000000004077552 drilldown(2)
245
+ 2011-06-02 16:27:04.735808|5091e5c0|<000000004123726 rc=0
246
+ EOL
247
+ end
248
+
249
+ def statistics
250
+ statistics = []
251
+ parser = Groonga::QueryLog::Parser.new
252
+ parser.parse(StringIO.new(log)) do |statistic|
253
+ statistics << statistic
254
+ end
255
+ statistics
256
+ end
257
+ end
258
+ end
data/test/test-record.rb CHANGED
@@ -168,12 +168,13 @@ class RecordTest < Test::Unit::TestCase
168
168
  end
169
169
 
170
170
  def test_delete
171
- bookmark1 = @bookmarks.add
172
- bookmark2 = @bookmarks.add
173
- bookmark3 = @bookmarks.add
171
+ bookmark_records = []
172
+ bookmark_records << @bookmarks.add
173
+ bookmark_records << @bookmarks.add
174
+ bookmark_records << @bookmarks.add
174
175
 
175
176
  assert_equal(3, @bookmarks.size)
176
- bookmark2.delete
177
+ bookmark_records[1].delete
177
178
  assert_equal(2, @bookmarks.size)
178
179
  end
179
180
 
@@ -375,7 +376,7 @@ class RecordTest < Test::Unit::TestCase
375
376
  end
376
377
 
377
378
  def test_select_result_attributes
378
- top_page_record = @bookmarks.add(top_page)
379
+ @bookmarks.add(top_page)
379
380
  select_result = @bookmarks.select
380
381
  select_result_result = select_result.first
381
382
 
@@ -102,6 +102,14 @@ module SchemaCreateTableTests
102
102
  def test_default_path
103
103
  Groonga::Schema.create_table("Posts", options) do |table|
104
104
  end
105
+ assert_equal("#{@database_path}.0000100",
106
+ context["Posts"].path)
107
+ end
108
+
109
+ def test_default_named_path
110
+ options_with_named_path = options.merge(:named_path => true)
111
+ Groonga::Schema.create_table("Posts", options_with_named_path) do |table|
112
+ end
105
113
  assert_equal("#{@database_path}.tables/Posts",
106
114
  context["Posts"].path)
107
115
  end
data/test/test-schema.rb CHANGED
@@ -70,120 +70,277 @@ class SchemaTest < Test::Unit::TestCase
70
70
  end
71
71
  end
72
72
 
73
- def test_define_hash
74
- Groonga::Schema.create_table("Posts", :type => :hash) do |table|
73
+ class DefineHashTest < self
74
+ def test_default
75
+ Groonga::Schema.create_table("Posts", :type => :hash) do |table|
76
+ end
77
+ posts = context["Posts"]
78
+ assert_kind_of(Groonga::Hash, posts)
79
+ assert_equal("#{@database_path}.0000100", posts.path)
80
+ end
81
+
82
+ def test_named_path
83
+ Groonga::Schema.create_table("Posts",
84
+ :type => :hash,
85
+ :named_path => true) do |table|
86
+ end
87
+ posts = context["Posts"]
88
+ assert_kind_of(Groonga::Hash, posts)
89
+ assert_equal("#{@database_path}.tables/Posts", posts.path)
90
+ end
91
+
92
+ def test_full_option
93
+ path = @tmp_dir + "hash.groonga"
94
+ tokenizer = context["TokenTrigram"]
95
+ Groonga::Schema.create_table("Posts",
96
+ :type => :hash,
97
+ :key_type => "integer",
98
+ :path => path.to_s,
99
+ :value_type => "UInt32",
100
+ :default_tokenizer => tokenizer,
101
+ :named_path => true) do |table|
102
+ end
103
+ table = context["Posts"]
104
+ assert_equal("#<Groonga::Hash " +
105
+ "id: <#{table.id}>, " +
106
+ "name: <Posts>, " +
107
+ "path: <#{path}>, " +
108
+ "domain: <Int32>, " +
109
+ "range: <UInt32>, " +
110
+ "flags: <>, " +
111
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
112
+ "size: <0>>",
113
+ table.inspect)
114
+ assert_equal(tokenizer, table.default_tokenizer)
115
+ end
116
+
117
+ def test_rename
118
+ Groonga::Schema.create_table("Posts", :type => :hash) do |table|
119
+ end
120
+ posts = context["Posts"]
121
+ assert_kind_of(Groonga::Hash, posts)
122
+ Groonga::Schema.rename_table("Posts", "Entries") do |table|
123
+ end
124
+ entries = context["Entries"]
125
+ assert_kind_of(Groonga::Hash, entries)
126
+ assert_equal("Entries", posts.name)
75
127
  end
76
- posts = context["Posts"]
77
- assert_kind_of(Groonga::Hash, posts)
78
- assert_equal("#{@database_path}.tables/Posts", posts.path)
79
128
  end
80
129
 
81
- def test_define_hash_with_full_option
82
- path = @tmp_dir + "hash.groonga"
83
- tokenizer = context["TokenTrigram"]
84
- Groonga::Schema.create_table("Posts",
85
- :type => :hash,
86
- :key_type => "integer",
87
- :path => path.to_s,
88
- :value_type => "UInt32",
89
- :default_tokenizer => tokenizer) do |table|
90
- end
91
- table = context["Posts"]
92
- assert_equal("#<Groonga::Hash " +
93
- "id: <#{table.id}>, " +
94
- "name: <Posts>, " +
95
- "path: <#{path}>, " +
96
- "domain: <Int32>, " +
97
- "range: <UInt32>, " +
98
- "flags: <>, " +
99
- "encoding: <#{Groonga::Encoding.default.inspect}>, " +
100
- "size: <0>>",
101
- table.inspect)
102
- assert_equal(tokenizer, table.default_tokenizer)
103
- end
104
-
105
- def test_define_patricia_trie
106
- Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
107
- end
108
- posts = context["Posts"]
109
- assert_kind_of(Groonga::PatriciaTrie, posts)
110
- assert_equal("#{@database_path}.tables/Posts", posts.path)
111
- end
112
-
113
- def test_define_patricia_trie_with_full_option
114
- path = @tmp_dir + "patricia-trie.groonga"
115
- Groonga::Schema.create_table("Posts",
116
- :type => :patricia_trie,
117
- :key_type => "integer",
118
- :path => path.to_s,
119
- :value_type => "Float",
120
- :default_tokenizer => "TokenBigram",
121
- :key_normalize => true,
122
- :key_with_sis => true) do |table|
123
- end
124
- table = context["Posts"]
125
- assert_equal("#<Groonga::PatriciaTrie " +
126
- "id: <#{table.id}>, " +
127
- "name: <Posts>, " +
128
- "path: <#{path}>, " +
129
- "domain: <Int32>, " +
130
- "range: <Float>, " +
131
- "flags: <KEY_WITH_SIS|KEY_NORMALIZE|WITH_SECTION>, " +
132
- "encoding: <#{Groonga::Encoding.default.inspect}>, " +
133
- "size: <0>>",
134
- table.inspect)
135
- assert_equal(context["TokenBigram"], table.default_tokenizer)
136
- end
137
-
138
- def test_define_array
139
- Groonga::Schema.create_table("Posts", :type => :array) do |table|
140
- end
141
- posts = context["Posts"]
142
- assert_kind_of(Groonga::Array, posts)
143
- assert_equal("#{@database_path}.tables/Posts", posts.path)
144
- end
145
-
146
- def test_define_array_with_full_option
147
- path = @tmp_dir + "array.groonga"
148
- Groonga::Schema.create_table("Posts",
149
- :type => :array,
150
- :path => path.to_s,
151
- :value_type => "Int32") do |table|
152
- end
153
- table = context["Posts"]
154
- assert_equal("#<Groonga::Array " +
155
- "id: <#{table.id}>, " +
156
- "name: <Posts>, " +
157
- "path: <#{path}>, " +
158
- "domain: <Int32>, " +
159
- "range: <Int32>, " +
160
- "flags: <>, " +
161
- "size: <0>>",
162
- table.inspect)
163
- end
164
-
165
- def test_column_with_full_option
166
- path = @tmp_dir + "column.groonga"
167
- type = Groonga::Type.new("Niku", :size => 29)
168
- Groonga::Schema.create_table("Posts") do |table|
169
- table.column("rate",
170
- type,
171
- :path => path.to_s,
172
- :persistent => true,
173
- :type => :vector,
174
- :compress => :lzo)
175
- end
176
-
177
- column_name = "Posts.rate"
178
- column = context[column_name]
179
- assert_equal("#<Groonga::VariableSizeColumn " +
180
- "id: <#{column.id}>, " +
181
- "name: <#{column_name}>, " +
182
- "path: <#{path}>, " +
183
- "domain: <Posts>, " +
184
- "range: <Niku>, " +
185
- "flags: <COMPRESS_LZO>>",
186
- column.inspect)
130
+ class DefinePatriciaTrieTest < self
131
+ def test_default
132
+ Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
133
+ end
134
+ posts = context["Posts"]
135
+ assert_kind_of(Groonga::PatriciaTrie, posts)
136
+ assert_equal("#{@database_path}.0000100", posts.path)
137
+ end
138
+
139
+ def test_named_path
140
+ Groonga::Schema.create_table("Posts",
141
+ :type => :patricia_trie,
142
+ :named_path => true) do |table|
143
+ end
144
+ posts = context["Posts"]
145
+ assert_kind_of(Groonga::PatriciaTrie, posts)
146
+ assert_equal("#{@database_path}.tables/Posts", posts.path)
147
+ end
148
+
149
+ def test_full_option
150
+ path = @tmp_dir + "patricia-trie.groonga"
151
+ Groonga::Schema.create_table("Posts",
152
+ :type => :patricia_trie,
153
+ :key_type => "integer",
154
+ :path => path.to_s,
155
+ :value_type => "Float",
156
+ :default_tokenizer => "TokenBigram",
157
+ :key_normalize => true,
158
+ :key_with_sis => true,
159
+ :named_path => true) do |table|
160
+ end
161
+ table = context["Posts"]
162
+ assert_equal("#<Groonga::PatriciaTrie " +
163
+ "id: <#{table.id}>, " +
164
+ "name: <Posts>, " +
165
+ "path: <#{path}>, " +
166
+ "domain: <Int32>, " +
167
+ "range: <Float>, " +
168
+ "flags: <KEY_WITH_SIS|KEY_NORMALIZE|WITH_SECTION>, " +
169
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
170
+ "size: <0>>",
171
+ table.inspect)
172
+ assert_equal(context["TokenBigram"], table.default_tokenizer)
173
+ end
174
+
175
+ def test_rename
176
+ Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
177
+ end
178
+ posts = context["Posts"]
179
+ assert_kind_of(Groonga::PatriciaTrie, posts)
180
+ Groonga::Schema.rename_table("Posts", "Entries") do |table|
181
+ end
182
+ entries = context["Entries"]
183
+ assert_kind_of(Groonga::PatriciaTrie, entries)
184
+ assert_equal("Entries", posts.name)
185
+ end
186
+ end
187
+
188
+ class DefineDoubleArrayTrieTest < self
189
+ def test_default
190
+ Groonga::Schema.create_table("Posts",
191
+ :type => :double_array_trie) do |table|
192
+ end
193
+ posts = context["Posts"]
194
+ assert_kind_of(Groonga::DoubleArrayTrie, posts)
195
+ assert_equal("#{@database_path}.0000100", posts.path)
196
+ end
197
+
198
+ def test_named_path
199
+ Groonga::Schema.create_table("Posts",
200
+ :type => :double_array_trie,
201
+ :named_path => true) do |table|
202
+ end
203
+ posts = context["Posts"]
204
+ assert_kind_of(Groonga::DoubleArrayTrie, posts)
205
+ assert_equal("#{@database_path}.tables/Posts", posts.path)
206
+ end
207
+
208
+ def test_full_option
209
+ path = @tmp_dir + "patricia-trie.groonga"
210
+ Groonga::Schema.create_table("Posts",
211
+ :type => :double_array_trie,
212
+ :key_type => "integer",
213
+ :path => path.to_s,
214
+ :value_type => "Float",
215
+ :default_tokenizer => "TokenBigram",
216
+ :key_normalize => true,
217
+ :named_path => true) do |table|
218
+ end
219
+ table = context["Posts"]
220
+ assert_equal("#<Groonga::DoubleArrayTrie " +
221
+ "id: <#{table.id}>, " +
222
+ "name: <Posts>, " +
223
+ "path: <#{path}>, " +
224
+ "domain: <Int32>, " +
225
+ "range: <Float>, " +
226
+ "flags: <KEY_NORMALIZE|WITH_SECTION>, " +
227
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
228
+ "size: <0>>",
229
+ table.inspect)
230
+ assert_equal(context["TokenBigram"], table.default_tokenizer)
231
+ end
232
+
233
+ def test_rename
234
+ Groonga::Schema.create_table("Posts", :type => :double_array_trie) do |table|
235
+ end
236
+ posts = context["Posts"]
237
+ assert_kind_of(Groonga::DoubleArrayTrie, posts)
238
+ Groonga::Schema.rename_table("Posts", "Entries") do |table|
239
+ end
240
+ entries = context["Entries"]
241
+ assert_kind_of(Groonga::DoubleArrayTrie, entries)
242
+ assert_equal("Entries", posts.name)
243
+ end
244
+ end
245
+
246
+ class DefineArrayTest < self
247
+ def test_default
248
+ Groonga::Schema.create_table("Posts", :type => :array) do |table|
249
+ end
250
+ posts = context["Posts"]
251
+ assert_kind_of(Groonga::Array, posts)
252
+ assert_equal("#{@database_path}.0000100", posts.path)
253
+ end
254
+
255
+ def test_named_path
256
+ Groonga::Schema.create_table("Posts",
257
+ :type => :array,
258
+ :named_path => true) do |table|
259
+ end
260
+ posts = context["Posts"]
261
+ assert_kind_of(Groonga::Array, posts)
262
+ assert_equal("#{@database_path}.tables/Posts", posts.path)
263
+ end
264
+
265
+ def test_full_option
266
+ path = @tmp_dir + "array.groonga"
267
+ Groonga::Schema.create_table("Posts",
268
+ :type => :array,
269
+ :path => path.to_s,
270
+ :value_type => "Int32",
271
+ :named_path => true) do |table|
272
+ end
273
+ table = context["Posts"]
274
+ assert_equal("#<Groonga::Array " +
275
+ "id: <#{table.id}>, " +
276
+ "name: <Posts>, " +
277
+ "path: <#{path}>, " +
278
+ "domain: <Int32>, " +
279
+ "range: <Int32>, " +
280
+ "flags: <>, " +
281
+ "size: <0>>",
282
+ table.inspect)
283
+ end
284
+
285
+ def test_rename
286
+ Groonga::Schema.create_table("Posts", :type => :array) do |table|
287
+ end
288
+ posts = context["Posts"]
289
+ assert_kind_of(Groonga::Array, posts)
290
+ Groonga::Schema.rename_table("Posts", "Entries") do |table|
291
+ end
292
+ entries = context["Entries"]
293
+ assert_kind_of(Groonga::Array, entries)
294
+ assert_equal("Entries", posts.name)
295
+ end
296
+ end
297
+
298
+ class DefineColumnTest < self
299
+ def test_default
300
+ Groonga::Schema.create_table("Posts") do |table|
301
+ table.column("rate", :int)
302
+ end
303
+
304
+ column_name = "Posts.rate"
305
+ column = context[column_name]
306
+ assert_kind_of(Groonga::FixSizeColumn, column)
307
+ assert_equal("#{@database_path}.0000101", column.path)
308
+ end
309
+
310
+ def test_named_path
311
+ Groonga::Schema.create_table("Posts") do |table|
312
+ table.column("rate", :int, :named_path => true)
313
+ end
314
+
315
+ column_name = "Posts.rate"
316
+ column = context[column_name]
317
+ assert_kind_of(Groonga::FixSizeColumn, column)
318
+ assert_equal("#{@database_path}.0000100.columns/rate", column.path)
319
+ end
320
+
321
+ def test_full_option
322
+ path = @tmp_dir + "column.groonga"
323
+ type = Groonga::Type.new("Niku", :size => 29)
324
+ Groonga::Schema.create_table("Posts") do |table|
325
+ table.column("rate",
326
+ type,
327
+ :path => path.to_s,
328
+ :persistent => true,
329
+ :type => :vector,
330
+ :compress => :lzo)
331
+ end
332
+
333
+ column_name = "Posts.rate"
334
+ column = context[column_name]
335
+ assert_equal("#<Groonga::VariableSizeColumn " +
336
+ "id: <#{column.id}>, " +
337
+ "name: <#{column_name}>, " +
338
+ "path: <#{path}>, " +
339
+ "domain: <Posts>, " +
340
+ "range: <Niku>, " +
341
+ "flags: <COMPRESS_LZO>>",
342
+ column.inspect)
343
+ end
187
344
  end
188
345
 
189
346
  def test_integer32_column
@@ -286,6 +443,19 @@ class SchemaTest < Test::Unit::TestCase
286
443
  assert_nil(context["Posts.content"])
287
444
  end
288
445
 
446
+ def test_rename_column
447
+ Groonga::Schema.create_table("Posts") do |table|
448
+ table.long_text :content
449
+ end
450
+ content = context["Posts.content"]
451
+ assert_equal("Posts.content", content.name)
452
+
453
+ Groonga::Schema.rename_column("Posts", "content", "body")
454
+ body = context["Posts.body"]
455
+ assert_equal("Posts.body", body.name)
456
+ assert_equal("Posts.body", content.name)
457
+ end
458
+
289
459
  def test_column_again
290
460
  Groonga::Schema.create_table("Posts") do |table|
291
461
  table.text :content
@@ -310,131 +480,167 @@ class SchemaTest < Test::Unit::TestCase
310
480
  end
311
481
  end
312
482
 
313
- def test_index
314
- assert_nil(context["Terms.content"])
315
- Groonga::Schema.create_table("Posts") do |table|
316
- table.long_text :content
483
+ class DefineIndexColumnTest < self
484
+ def test_default
485
+ assert_nil(context["Terms.content"])
486
+ Groonga::Schema.create_table("Posts") do |table|
487
+ table.long_text :content
488
+ end
489
+ Groonga::Schema.create_table("Terms") do |table|
490
+ table.index "Posts.content"
491
+ end
492
+ index_column = context["Terms.Posts_content"]
493
+ assert_equal([context["Posts.content"]],
494
+ index_column.sources)
495
+ assert_equal("#{@database_path}.0000103", index_column.path)
317
496
  end
318
- Groonga::Schema.create_table("Terms") do |table|
319
- table.index "Posts.content"
497
+
498
+ def test_named_path
499
+ assert_nil(context["Terms.content"])
500
+ Groonga::Schema.create_table("Posts") do |table|
501
+ table.long_text :content
502
+ end
503
+ Groonga::Schema.create_table("Terms") do |table|
504
+ table.index "Posts.content", :named_path => true
505
+ end
506
+ index_column = context["Terms.Posts_content"]
507
+ assert_equal([context["Posts.content"]],
508
+ index_column.sources)
509
+ assert_equal("#{@database_path}.0000102.columns/Posts_content",
510
+ index_column.path)
320
511
  end
321
- assert_equal([context["Posts.content"]],
322
- context["Terms.Posts_content"].sources)
323
- end
324
512
 
325
- def test_index_with_full_option
326
- path = @tmp_dir + "index-column.groonga"
327
- assert_nil(context["Terms.content"])
328
- index_column_name = "Posts_index"
513
+ def test_full_option
514
+ path = @tmp_dir + "index-column.groonga"
515
+ assert_nil(context["Terms.content"])
516
+ index_column_name = "Posts_index"
329
517
 
330
- Groonga::Schema.create_table("Posts") do |table|
331
- table.long_text :content
332
- end
333
- Groonga::Schema.create_table("Terms") do |table|
334
- table.index("Posts.content",
335
- :name => index_column_name,
336
- :path => path.to_s,
337
- :persistent => true,
338
- :with_section => true,
339
- :with_weight => true,
340
- :with_position => true)
341
- end
342
-
343
- posts = context["Posts"]
344
- terms = context["Terms"]
345
- full_index_column_name = "Terms.#{index_column_name}"
346
- index_column = context[full_index_column_name]
347
- assert_equal("#<Groonga::IndexColumn " +
348
- "id: <#{index_column.id}>, " +
349
- "name: <#{full_index_column_name}>, " +
350
- "path: <#{path}>, " +
351
- "domain: <Terms>, " +
352
- "range: <Posts>, " +
353
- "flags: <WITH_SECTION|WITH_WEIGHT|WITH_POSITION>>",
354
- index_column.inspect)
355
- end
356
-
357
- def test_index_again
358
- Groonga::Schema.create_table("Posts") do |table|
359
- table.long_text :content
360
- end
361
- Groonga::Schema.create_table("Terms") do |table|
362
- table.index "Posts.content"
518
+ Groonga::Schema.create_table("Posts") do |table|
519
+ table.long_text :content
520
+ end
521
+ Groonga::Schema.create_table("Terms") do |table|
522
+ table.index("Posts.content",
523
+ :name => index_column_name,
524
+ :path => path.to_s,
525
+ :persistent => true,
526
+ :with_section => true,
527
+ :with_weight => true,
528
+ :with_position => true,
529
+ :named_path => true)
530
+ end
531
+
532
+ full_index_column_name = "Terms.#{index_column_name}"
533
+ index_column = context[full_index_column_name]
534
+ assert_equal("#<Groonga::IndexColumn " +
535
+ "id: <#{index_column.id}>, " +
536
+ "name: <#{full_index_column_name}>, " +
537
+ "path: <#{path}>, " +
538
+ "domain: <Terms>, " +
539
+ "range: <Posts>, " +
540
+ "flags: <WITH_SECTION|WITH_WEIGHT|WITH_POSITION>>",
541
+ index_column.inspect)
363
542
  end
364
543
 
365
- assert_nothing_raised do
544
+ def test_again
545
+ Groonga::Schema.create_table("Posts") do |table|
546
+ table.long_text :content
547
+ end
366
548
  Groonga::Schema.create_table("Terms") do |table|
367
549
  table.index "Posts.content"
368
550
  end
369
- end
370
- end
371
551
 
372
- def test_index_again_with_difference_source
373
- Groonga::Schema.create_table("Posts") do |table|
374
- table.long_text :content
375
- table.short_text :name
376
- end
377
- Groonga::Schema.create_table("Terms") do |table|
378
- table.index "Posts.content"
552
+ assert_nothing_raised do
553
+ Groonga::Schema.create_table("Terms") do |table|
554
+ table.index "Posts.content"
555
+ end
556
+ end
379
557
  end
380
558
 
381
- assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
559
+ def test_again_with_difference_source
560
+ Groonga::Schema.create_table("Posts") do |table|
561
+ table.long_text :content
562
+ table.short_text :name
563
+ end
382
564
  Groonga::Schema.create_table("Terms") do |table|
383
- table.index "Posts.name", :name => "Posts_content"
565
+ table.index "Posts.content"
384
566
  end
385
- end
386
- end
387
567
 
388
- def test_index_key
389
- Groonga::Schema.create_table("Posts",
390
- :type => :hash,
391
- :key_type => "ShortText") do |table|
392
- end
393
- Groonga::Schema.create_table("Terms") do |table|
394
- table.index "Posts._key", :with_position => true
568
+ assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
569
+ Groonga::Schema.create_table("Terms") do |table|
570
+ table.index "Posts.name", :name => "Posts_content"
571
+ end
572
+ end
395
573
  end
396
574
 
397
- full_index_column_name = "Terms.Posts__key"
398
- index_column = context[full_index_column_name]
399
- assert_equal("#<Groonga::IndexColumn " +
400
- "id: <#{index_column.id}>, " +
401
- "name: <#{full_index_column_name}>, " +
402
- "path: <#{index_column.path}>, " +
403
- "domain: <Terms>, " +
404
- "range: <Posts>, " +
405
- "flags: <WITH_POSITION>>",
406
- index_column.inspect)
407
- end
575
+ def test_key
576
+ Groonga::Schema.create_table("Posts",
577
+ :type => :hash,
578
+ :key_type => "ShortText") do |table|
579
+ end
580
+ Groonga::Schema.create_table("Terms") do |table|
581
+ table.index "Posts._key", :with_position => true
582
+ end
408
583
 
409
- def test_index_key_again
410
- Groonga::Schema.create_table("Posts",
411
- :type => :hash,
412
- :key_type => "ShortText") do |table|
413
- end
414
- Groonga::Schema.create_table("Terms") do |table|
415
- table.index "Posts._key", :with_position => true
584
+ full_index_column_name = "Terms.Posts__key"
585
+ index_column = context[full_index_column_name]
586
+ assert_equal("#<Groonga::IndexColumn " +
587
+ "id: <#{index_column.id}>, " +
588
+ "name: <#{full_index_column_name}>, " +
589
+ "path: <#{index_column.path}>, " +
590
+ "domain: <Terms>, " +
591
+ "range: <Posts>, " +
592
+ "flags: <WITH_POSITION>>",
593
+ index_column.inspect)
416
594
  end
417
595
 
418
- assert_nothing_raised do
596
+ def test_key_again
597
+ Groonga::Schema.create_table("Posts",
598
+ :type => :hash,
599
+ :key_type => "ShortText") do |table|
600
+ end
419
601
  Groonga::Schema.create_table("Terms") do |table|
420
- table.index "Posts._key"
602
+ table.index "Posts._key", :with_position => true
421
603
  end
422
- end
423
- end
424
604
 
425
- def test_remove_index
426
- Groonga::Schema.create_table("Posts") do |table|
427
- table.long_text :content
605
+ assert_nothing_raised do
606
+ Groonga::Schema.create_table("Terms") do |table|
607
+ table.index "Posts._key"
608
+ end
609
+ end
428
610
  end
429
- Groonga::Schema.create_table("Terms") do |table|
430
- table.index "Posts.content"
611
+
612
+ def test_remove
613
+ Groonga::Schema.create_table("Posts") do |table|
614
+ table.long_text :content
615
+ end
616
+ Groonga::Schema.create_table("Terms") do |table|
617
+ table.index "Posts.content"
618
+ end
619
+ assert_equal([context["Posts.content"]],
620
+ context["Terms.Posts_content"].sources)
621
+ Groonga::Schema.change_table("Terms") do |table|
622
+ table.remove_index("Posts.content")
623
+ end
624
+ assert_nil(context["Terms.Posts_content"])
431
625
  end
432
- assert_equal([context["Posts.content"]],
433
- context["Terms.Posts_content"].sources)
434
- Groonga::Schema.change_table("Terms") do |table|
435
- table.remove_index("Posts.content")
626
+
627
+ def test_rename
628
+ Groonga::Schema.create_table("Posts") do |table|
629
+ table.long_text :content
630
+ end
631
+ Groonga::Schema.create_table("Terms") do |table|
632
+ table.index "Posts.content"
633
+ end
634
+ index = context["Terms.Posts_content"]
635
+ assert_equal([context["Posts.content"]], index.sources)
636
+ Groonga::Schema.change_table("Terms") do |table|
637
+ table.rename_column("Posts_content", "posts_content_index")
638
+ end
639
+ renamed_index = context["Terms.posts_content_index"]
640
+ assert_equal("Terms.posts_content_index", renamed_index.name)
641
+ assert_equal("Terms.posts_content_index", index.name)
642
+ assert_equal([context["Posts.content"]], renamed_index.sources)
436
643
  end
437
- assert_nil(context["Terms.Posts_content"])
438
644
  end
439
645
 
440
646
  def test_reference_guess
@@ -486,26 +692,6 @@ class SchemaTest < Test::Unit::TestCase
486
692
  assert_nil(Groonga::Context.default["TermsText.Items_text"])
487
693
  end
488
694
 
489
- def test_columns_directory_removed
490
- table = "Posts"
491
- dir = create_table_with_column(table)
492
-
493
- Groonga::Schema.remove_table(table)
494
-
495
- assert_table_removed(table)
496
- assert_directory_removed(dir)
497
- end
498
-
499
- def test_columns_directory_not_removed
500
- table = "Posts"
501
- dir = create_table_with_column(table)
502
-
503
- Groonga::Context.default[table].remove
504
-
505
- assert_table_removed(table)
506
- assert_directory_not_removed(dir)
507
- end
508
-
509
695
  def test_default_tokenizer_name_shortcut
510
696
  Groonga::Schema.define do |schema|
511
697
  schema.create_table("Terms",
@@ -531,13 +717,84 @@ class SchemaTest < Test::Unit::TestCase
531
717
  assert_equal(short_text, Groonga["Users"].domain)
532
718
  end
533
719
 
720
+ class RemoveTest < self
721
+ def test_tables_directory_removed_on_last_table_remove
722
+ table_name = "Posts"
723
+ Groonga::Schema.create_table(table_name, :named_path => true)
724
+ table = Groonga[table_name]
725
+ tables_directory = Pathname.new(table.path).dirname
726
+
727
+ assert_directory_not_removed(tables_directory)
728
+ Groonga::Schema.remove_table(table_name)
729
+ assert_directory_removed(tables_directory)
730
+ end
731
+
732
+ def test_tables_directory_not_removed_on_not_last_table_remove
733
+ table_name = "Posts"
734
+ Groonga::Schema.define(:named_path => true) do |schema|
735
+ schema.create_table(table_name)
736
+ schema.create_table("Users")
737
+ end
738
+
739
+ table = Groonga[table_name]
740
+ tables_directory = Pathname.new(table.path).dirname
741
+
742
+ assert_directory_not_removed(tables_directory)
743
+ Groonga::Schema.remove_table(table_name)
744
+ assert_directory_not_removed(tables_directory)
745
+ end
746
+
747
+ def test_columns_directory_removed
748
+ table = "Posts"
749
+ dir = create_table_with_column(table, :named_path => true)
750
+
751
+ Groonga::Schema.remove_table(table)
752
+
753
+ assert_table_removed(table)
754
+ assert_directory_removed(dir)
755
+ end
756
+ end
757
+
758
+ class ColumnRemoveTest < self
759
+ def test_columns_directory_removed_on_last_column_remove
760
+ Groonga::Schema.define(:named_path => true) do |schema|
761
+ schema.create_table("Posts") do |table|
762
+ table.short_text("title")
763
+ end
764
+ end
765
+
766
+ columns_directory = columns_directory_path(Groonga["Posts"])
767
+ assert_directory_not_removed(columns_directory)
768
+ Groonga::Schema.change_table("Posts") do |table|
769
+ table.remove_column("title")
770
+ end
771
+ assert_directory_removed(columns_directory)
772
+ end
773
+
774
+ def test_columns_directory_not_removed_on_not_last_column_remove
775
+ Groonga::Schema.define(:named_path => true) do |schema|
776
+ schema.create_table("Posts") do |table|
777
+ table.short_text("title")
778
+ table.short_text("body")
779
+ end
780
+ end
781
+
782
+ columns_directory = columns_directory_path(Groonga["Posts"])
783
+ assert_directory_not_removed(columns_directory)
784
+ Groonga::Schema.change_table("Posts") do |table|
785
+ table.remove_column("title")
786
+ end
787
+ assert_directory_not_removed(columns_directory)
788
+ end
789
+ end
790
+
534
791
  private
535
792
  def columns_directory_path(table)
536
793
  "#{table.path}.columns"
537
794
  end
538
795
 
539
- def create_table_with_column(name)
540
- Groonga::Schema.create_table(name) do |table|
796
+ def create_table_with_column(name, options={})
797
+ Groonga::Schema.create_table(name, options) do |table|
541
798
  table.integer64 :rate
542
799
  end
543
800
  context = Groonga::Context.default
@@ -545,11 +802,11 @@ class SchemaTest < Test::Unit::TestCase
545
802
  end
546
803
 
547
804
  def assert_directory_removed(dir)
548
- assert_false(File.exist?(dir))
805
+ assert_not_predicate(Pathname.new(dir), :exist?)
549
806
  end
550
807
 
551
808
  def assert_directory_not_removed(dir)
552
- assert_true(File.exist?(dir))
809
+ assert_predicate(Pathname.new(dir), :exist?)
553
810
  end
554
811
 
555
812
  def assert_table_removed(name)