activegroonga 0.0.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/README.ja.rdoc +4 -1
  2. data/README.rdoc +4 -1
  3. data/Rakefile +18 -4
  4. data/lib/active_groonga.rb +25 -52
  5. data/lib/active_groonga/base.rb +164 -1480
  6. data/lib/active_groonga/callbacks.rb +26 -7
  7. data/lib/active_groonga/database.rb +55 -0
  8. data/lib/active_groonga/{dirty.rb → error.rb} +20 -10
  9. data/lib/active_groonga/locale/en.yml +5 -0
  10. data/lib/active_groonga/migration.rb +44 -113
  11. data/lib/active_groonga/migrator.rb +172 -0
  12. data/lib/active_groonga/persistence.rb +172 -0
  13. data/lib/active_groonga/railtie.rb +66 -0
  14. data/lib/active_groonga/railties/configurable.rb +47 -0
  15. data/lib/active_groonga/railties/groonga.rake +167 -0
  16. data/lib/active_groonga/result_set.rb +89 -0
  17. data/lib/active_groonga/schema.rb +54 -188
  18. data/lib/active_groonga/validations.rb +54 -5
  19. data/lib/active_groonga/vector.rb +64 -0
  20. data/lib/active_groonga/version.rb +3 -3
  21. data/lib/{active_groonga/aggregations.rb → rails/generators/active_groonga.rb} +17 -10
  22. data/lib/rails/generators/active_groonga/migration/column.rb +101 -0
  23. data/lib/rails/generators/active_groonga/migration/migration_generator.rb +53 -0
  24. data/lib/rails/generators/active_groonga/migration/templates/migration.rb +29 -0
  25. data/lib/rails/generators/active_groonga/model/model_generator.rb +60 -0
  26. data/lib/rails/generators/active_groonga/model/templates/migration.rb +16 -0
  27. data/lib/rails/generators/active_groonga/model/templates/model.rb +2 -0
  28. data/lib/rails/generators/active_groonga/model/templates/module.rb +5 -0
  29. data/test-unit-notify/COPYING +502 -0
  30. data/test-unit-notify/Rakefile +47 -0
  31. data/test-unit-notify/lib/test/unit/notify.rb +127 -0
  32. data/test-unit/COPYING +56 -0
  33. data/test-unit/GPL +340 -0
  34. data/test-unit/PSFL +271 -0
  35. data/test-unit/Rakefile +18 -5
  36. data/test-unit/html/bar.svg +153 -0
  37. data/test-unit/html/developer.svg +469 -0
  38. data/test-unit/html/favicon.ico +0 -0
  39. data/test-unit/html/favicon.svg +82 -0
  40. data/test-unit/html/heading-mark.svg +393 -0
  41. data/test-unit/html/index.html +235 -13
  42. data/test-unit/html/index.html.ja +258 -15
  43. data/test-unit/html/install.svg +636 -0
  44. data/test-unit/html/logo.svg +483 -0
  45. data/test-unit/html/test-unit.css +339 -0
  46. data/test-unit/html/tutorial.svg +559 -0
  47. data/test-unit/lib/test/unit.rb +29 -43
  48. data/test-unit/lib/test/unit/assertionfailederror.rb +11 -0
  49. data/test-unit/lib/test/unit/assertions.rb +202 -20
  50. data/test-unit/lib/test/unit/autorunner.rb +51 -20
  51. data/test-unit/lib/test/unit/collector.rb +1 -8
  52. data/test-unit/lib/test/unit/collector/dir.rb +1 -1
  53. data/test-unit/lib/test/unit/collector/load.rb +16 -9
  54. data/test-unit/lib/test/unit/color-scheme.rb +19 -3
  55. data/test-unit/lib/test/unit/diff.rb +240 -38
  56. data/test-unit/lib/test/unit/error.rb +4 -0
  57. data/test-unit/lib/test/unit/failure.rb +31 -5
  58. data/test-unit/lib/test/unit/notification.rb +8 -4
  59. data/test-unit/lib/test/unit/omission.rb +51 -3
  60. data/test-unit/lib/test/unit/pending.rb +4 -0
  61. data/test-unit/lib/test/unit/priority.rb +2 -3
  62. data/test-unit/lib/test/unit/testcase.rb +65 -7
  63. data/test-unit/lib/test/unit/testresult.rb +34 -2
  64. data/test-unit/lib/test/unit/ui/console/testrunner.rb +197 -45
  65. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +14 -0
  66. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +2 -12
  67. data/test-unit/lib/test/unit/ui/testrunner.rb +33 -0
  68. data/test-unit/lib/test/unit/util/backtracefilter.rb +1 -0
  69. data/test-unit/lib/test/unit/util/output.rb +31 -0
  70. data/test-unit/lib/test/unit/version.rb +1 -1
  71. data/test-unit/sample/{tc_adder.rb → test_adder.rb} +3 -1
  72. data/test-unit/sample/{tc_subtracter.rb → test_subtracter.rb} +3 -1
  73. data/test-unit/sample/test_user.rb +1 -0
  74. data/test-unit/test/collector/test-descendant.rb +2 -4
  75. data/test-unit/test/collector/test-load.rb +121 -8
  76. data/test-unit/test/collector/test_objectspace.rb +7 -5
  77. data/test-unit/test/run-test.rb +2 -0
  78. data/test-unit/test/test-color-scheme.rb +11 -2
  79. data/test-unit/test/test-diff.rb +48 -7
  80. data/test-unit/test/test-omission.rb +1 -1
  81. data/test-unit/test/test-testcase.rb +57 -20
  82. data/test-unit/test/test_assertions.rb +128 -13
  83. data/test-unit/test/ui/test_tap.rb +33 -0
  84. data/test-unit/test/util/test-output.rb +11 -0
  85. data/test/active-groonga-test-utils.rb +50 -36
  86. data/test/fixtures/site.rb +2 -0
  87. data/test/run-test.rb +36 -9
  88. data/test/test-associations.rb +5 -2
  89. data/test/test-base.rb +39 -31
  90. data/test/test-callbacks.rb +13 -3
  91. data/test/test-persistence.rb +53 -0
  92. data/{lib/active_groonga/observer.rb → test/test-result-set.rb} +14 -12
  93. data/test/test-schema.rb +85 -22
  94. data/{lib/active_groonga/rails_support.rb → test/test-validations.rb} +15 -13
  95. metadata +85 -52
  96. data/lib/active_groonga/associations.rb +0 -93
  97. data/lib/active_groonga/associations/belongs_to_association.rb +0 -25
  98. data/lib/active_groonga/attribute_methods.rb +0 -36
  99. data/lib/active_groonga/column.rb +0 -137
  100. data/lib/active_groonga/dynamic_record_expression_builder.rb +0 -40
  101. data/lib/active_groonga/reflection.rb +0 -30
  102. data/lib/active_groonga/schema_dumper.rb +0 -163
  103. data/lib/active_groonga/tasks.rb +0 -16
  104. data/lib/active_groonga/tasks/groonga.rake +0 -164
  105. data/lib/active_groonga/timestamp.rb +0 -30
  106. data/rails/README +0 -28
  107. data/rails/init.rb +0 -70
  108. data/rails_generators/index_table_groonga/USAGE +0 -23
  109. data/rails_generators/index_table_groonga/index_table_groonga_generator.rb +0 -44
  110. data/rails_generators/index_table_groonga/templates/migration.rb +0 -12
  111. data/rails_generators/migration_groonga/USAGE +0 -29
  112. data/rails_generators/migration_groonga/migration_groonga_generator.rb +0 -19
  113. data/rails_generators/migration_groonga/templates/migration.rb +0 -11
  114. data/rails_generators/model_groonga/USAGE +0 -28
  115. data/rails_generators/model_groonga/model_groonga_generator.rb +0 -45
  116. data/rails_generators/model_groonga/templates/fixtures.yml +0 -17
  117. data/rails_generators/model_groonga/templates/migration.rb +0 -16
  118. data/rails_generators/model_groonga/templates/model.rb +0 -2
  119. data/rails_generators/model_groonga/templates/unit_test.rb +0 -8
  120. data/test-unit/html/classic.html +0 -15
  121. data/test-unit/sample/ts_examples.rb +0 -7
  122. data/test/test-schema-dumper.rb +0 -48
@@ -1,4 +1,9 @@
1
1
  class TestUnitDiff < Test::Unit::TestCase
2
+ def test_binary_search_ranges
3
+ assert_found_binary_search_ranges(5, [1..2, 4..5, 7..9])
4
+ assert_not_found_binary_search_ranges(3, [1..2, 4..5, 7..9])
5
+ end
6
+
2
7
  def test_to_indexes
3
8
  assert_to_indexes({"abc def" => [0, 2], "abc" => [1]},
4
9
  ["abc def", "abc", "abc def"])
@@ -189,6 +194,21 @@ class TestUnitDiff < Test::Unit::TestCase
189
194
  assert_ratio(0.80, "efg", "eg")
190
195
  end
191
196
 
197
+ def test_1_length_readable_diff
198
+ differ = Test::Unit::Diff::ReadableDiffer.new(["0"], ["1"])
199
+ def differ.cut_off_ratio
200
+ 0
201
+ end
202
+ def differ.default_ratio
203
+ 0
204
+ end
205
+ assert_equal("- 0\n" +
206
+ "? ^\n" +
207
+ "+ 1\n" +
208
+ "? ^",
209
+ differ.diff.join("\n"))
210
+ end
211
+
192
212
  def test_same_contents_readable_diff
193
213
  assert_readable_diff(" aaa", ["aaa"], ["aaa"])
194
214
  assert_readable_diff(" aaa\n" \
@@ -387,6 +407,18 @@ class TestUnitDiff < Test::Unit::TestCase
387
407
  end
388
408
 
389
409
  private
410
+ def assert_found_binary_search_ranges(numeric, ranges)
411
+ assert_true(Test::Unit::Diff::UTF8Line.send(:binary_search_ranges,
412
+ numeric,
413
+ ranges))
414
+ end
415
+
416
+ def assert_not_found_binary_search_ranges(numeric, ranges)
417
+ assert_false(Test::Unit::Diff::UTF8Line.send(:binary_search_ranges,
418
+ numeric,
419
+ ranges))
420
+ end
421
+
390
422
  def assert_to_indexes(expected, to, &junk_predicate)
391
423
  matcher = Test::Unit::Diff::SequenceMatcher.new([""], to, &junk_predicate)
392
424
  assert_equal(expected, matcher.instance_variable_get("@to_indexes"))
@@ -451,21 +483,30 @@ class TestUnitDiff < Test::Unit::TestCase
451
483
  from_start, from_end,
452
484
  to_start, to_end)
453
485
  differ = Test::Unit::Diff::ReadableDiffer.new(from, to)
454
- assert_equal(expected, differ.send(:diff_lines,
455
- from_start, from_end,
456
- to_start, to_end))
486
+ result = []
487
+ differ.instance_variable_set("@result", result)
488
+ differ.send(:diff_lines,
489
+ from_start, from_end,
490
+ to_start, to_end)
491
+ assert_equal(expected, result)
457
492
  end
458
493
 
459
494
  def assert_diff_line(expected, from_line, to_line)
460
495
  differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
461
- assert_equal(expected, differ.send(:diff_line, from_line, to_line))
496
+ result = []
497
+ differ.instance_variable_set("@result", result)
498
+ differ.send(:diff_line, from_line, to_line)
499
+ assert_equal(expected, result)
462
500
  end
463
501
 
464
502
  def assert_format_diff_point(expected, from_line, to_line, from_tags, to_tags)
465
503
  differ = Test::Unit::Diff::ReadableDiffer.new([""], [""])
466
- assert_equal(expected, differ.send(:format_diff_point,
467
- from_line, to_line,
468
- from_tags, to_tags))
504
+ result = []
505
+ differ.instance_variable_set("@result", result)
506
+ differ.send(:format_diff_point,
507
+ from_line, to_line,
508
+ from_tags, to_tags)
509
+ assert_equal(expected, result)
469
510
  end
470
511
 
471
512
  def assert_interesting_line(expected, from, to, from_start, to_start)
@@ -68,7 +68,7 @@ class TestUnitOmission < Test::Unit::TestCase
68
68
 
69
69
  def test_omit_with_condition_and_block
70
70
  result = _run_test("test_omit_with_block_and_condition")
71
- assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \
71
+ assert_equal("1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \
72
72
  "1 omissions, 0 notifications",
73
73
  result.to_s)
74
74
  assert_fault_messages(["Should omit."], result.omissions)
@@ -7,6 +7,7 @@ require 'test/unit'
7
7
  module Test
8
8
  module Unit
9
9
  class TestTestCase < TestCase
10
+ self.test_order = :random
10
11
  def test_creation
11
12
  tc = Class.new(TestCase) do
12
13
  def test_with_arguments(arg1, arg2)
@@ -469,25 +470,68 @@ module Test
469
470
  end
470
471
 
471
472
  def test_defined_order
472
- keep_test_order do
473
- test_case = Class.new(Test::Unit::TestCase) do
474
- def test_z
475
- end
473
+ test_case = Class.new(Test::Unit::TestCase) do
474
+ def test_z
475
+ end
476
476
 
477
- def test_1
478
- end
477
+ def test_1
478
+ end
479
479
 
480
- def test_a
481
- end
480
+ def test_a
481
+ end
482
+ end
483
+
484
+ assert_equal(["test_1", "test_a", "test_z"],
485
+ test_case.suite.tests.collect {|test| test.method_name})
486
+
487
+ test_case.test_order = :defined
488
+ assert_equal(["test_z", "test_1", "test_a"],
489
+ test_case.suite.tests.collect {|test| test.method_name})
490
+ end
491
+
492
+ def test_declarative_style
493
+ test_case = Class.new(Test::Unit::TestCase) do
494
+ test "declarative style test definition" do
482
495
  end
483
496
 
484
- assert_equal(["test_1", "test_a", "test_z"],
485
- test_case.suite.tests.collect {|test| test.method_name})
497
+ test "include parenthesis" do
498
+ end
486
499
 
487
- test_case.test_order = :defined
488
- assert_equal(["test_z", "test_1", "test_a"],
489
- test_case.suite.tests.collect {|test| test.method_name})
500
+ test "1 + 2 = 3" do
501
+ end
490
502
  end
503
+
504
+ test_case.test_order = :defined
505
+
506
+ assert_equal(["test_declarative_style_test_definition",
507
+ "test_include_parenthesis",
508
+ "test_1_2_3"],
509
+ test_case.suite.tests.collect {|test| test.method_name})
510
+
511
+ assert_equal(["declarative style test definition",
512
+ "include parenthesis",
513
+ "1 + 2 = 3"],
514
+ test_case.suite.tests.collect {|test| test.description})
515
+ end
516
+
517
+ def test_redefine_method
518
+ test_case = Class.new(Test::Unit::TestCase) do
519
+ def test_name
520
+ end
521
+ alias_method :test_name2, :test_name
522
+
523
+ def test_name
524
+ end
525
+ end
526
+
527
+ suite = test_case.suite
528
+ assert_equal(["test_name", "test_name2"],
529
+ suite.tests.collect {|test| test.method_name})
530
+ result = TestResult.new
531
+ suite.run(result) {}
532
+ assert_equal("2 tests, 0 assertions, 0 failures, " +
533
+ "0 errors, 0 pendings, 0 omissions, 1 notifications",
534
+ result.summary)
491
535
  end
492
536
 
493
537
  private
@@ -495,13 +539,6 @@ module Test
495
539
  add_assertion
496
540
  raise AssertionFailedError.new(message) unless passed
497
541
  end
498
-
499
- def keep_test_order
500
- order = TestCase.test_order
501
- yield
502
- ensure
503
- TestCase.test_order = order
504
- end
505
542
  end
506
543
  end
507
544
  end
@@ -1,6 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
1
3
  # Author:: Nathaniel Talbott.
2
4
  # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
- # Copyright (c) 2009 Kouhei Sutou.
5
+ # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
4
6
  # License:: Ruby license.
5
7
 
6
8
  require 'test/unit'
@@ -248,32 +250,81 @@ EOM
248
250
 
249
251
  def test_assert_equal_with_large_string
250
252
  message = <<-EOM.chomp
251
- <#{("a\n" + "x" * 297).inspect}> expected but was
253
+ <#{("a\n" + "x" * 997).inspect}> expected but was
252
254
  <#{"x".inspect}>.
253
255
 
254
256
  diff:
255
257
  + x
256
258
  - a
257
- - #{"x" * 297}
259
+ - #{"x" * 997}
258
260
 
259
261
  folded diff:
260
262
  + x
261
263
  - a
262
- - #{"x" * 78}
263
- - #{"x" * 78}
264
- - #{"x" * 78}
265
- - #{"x" * 63}
264
+ #{(["- " + ("x" * 78)] * 12).join("\n")}
265
+ - #{"x" * 61}
266
266
  EOM
267
267
  check_fails(message) do
268
- assert_equal("a\n" + "x" * 297, "x")
268
+ assert_equal("a\n" + "x" * 997, "x")
269
269
  end
270
270
 
271
271
  message = <<-EOM.chomp
272
- <#{("a\n" + "x" * 298).inspect}> expected but was
272
+ <#{("a\n" + "x" * 998).inspect}> expected but was
273
273
  <#{"x".inspect}>.
274
274
  EOM
275
275
  check_fails(message) do
276
- assert_equal("a\n" + "x" * 298, "x")
276
+ assert_equal("a\n" + "x" * 998, "x")
277
+ end
278
+ end
279
+
280
+ def test_assert_equal_with_max_diff_target_string_size
281
+ key = "TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"
282
+ before_value = ENV[key]
283
+ ENV[key] = "100"
284
+ begin
285
+ message = <<-EOM.chomp
286
+ <#{("a\n" + "x" * 97).inspect}> expected but was
287
+ <#{"x".inspect}>.
288
+
289
+ diff:
290
+ + x
291
+ - a
292
+ - #{"x" * 97}
293
+
294
+ folded diff:
295
+ + x
296
+ - a
297
+ #{(["- " + ("x" * 78)]).join("\n")}
298
+ - #{"x" * 19}
299
+ EOM
300
+ check_fails(message) do
301
+ assert_equal("a\n" + "x" * 97, "x")
302
+ end
303
+
304
+ message = <<-EOM.chomp
305
+ <#{("a\n" + "x" * 98).inspect}> expected but was
306
+ <#{"x".inspect}>.
307
+ EOM
308
+ check_fails(message) do
309
+ assert_equal("a\n" + "x" * 98, "x")
310
+ end
311
+ ensure
312
+ ENV[key] = before_value
313
+ end
314
+ end
315
+
316
+ def test_assert_equal_with_different_encoding
317
+ utf8_string = "こんにちは"
318
+ unless utf8_string.respond_to?(:force_encoding)
319
+ omit("encoding test is for Ruby >= 1.9")
320
+ end
321
+ ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
322
+ message = <<-EOM.chomp
323
+ <"こんにちは">("UTF-8") expected but was
324
+ <#{ascii_8bit_string.inspect}>("ASCII-8BIT").
325
+ EOM
326
+ check_fails(message) do
327
+ assert_equal(utf8_string, ascii_8bit_string)
277
328
  end
278
329
  end
279
330
 
@@ -777,13 +828,19 @@ EOM
777
828
  end
778
829
  assert_in_delta(0.1, float_thing, 0.1)
779
830
  }
780
- check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
831
+ check_fails("message.\n" +
832
+ "<0.5> expected but was\n" +
833
+ "<0.4> (tolerance <0.05>).\n" +
834
+ "\n" +
835
+ "Relation:\n" +
836
+ "<<0.4> < <0.5>-<0.05>(0.45) <= <0.5>+<0.05>(0.55)>") {
781
837
  assert_in_delta(0.5, 0.4, 0.05, "message")
782
838
  }
783
839
  object = Object.new
840
+ inspected_object = AssertionMessage.convert(object)
784
841
  check_fails("The arguments must respond to to_f; " +
785
842
  "the first float did not.\n" +
786
- "<#{object.inspect}>.respond_to?(:to_f) expected\n" +
843
+ "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
787
844
  "(Class: <Object>)") {
788
845
  assert_in_delta(object, 0.4, 0.1)
789
846
  }
@@ -1063,8 +1120,66 @@ EOM
1063
1120
  end
1064
1121
  end
1065
1122
 
1123
+ def test_assert_alias_method
1124
+ object = Object.new
1125
+ class << object
1126
+ def original_method
1127
+ end
1128
+ alias_method :alias_method, :original_method
1129
+
1130
+ def other
1131
+ end
1132
+ end
1133
+
1134
+ check_nothing_fails do
1135
+ assert_alias_method(object, :alias_method, :original_method)
1136
+ end
1137
+
1138
+ check_nothing_fails do
1139
+ assert_alias_method(object, :original_method, :alias_method)
1140
+ end
1141
+
1142
+ check_fails("<#{object.method(:other).inspect}> is alias of\n" +
1143
+ "<#{object.method(:original_method).inspect}> expected") do
1144
+ assert_alias_method(object, :other, :original_method)
1145
+ end
1146
+
1147
+ inspected_object = AssertionMessage.convert(object)
1148
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1149
+ "(Class: <Object>)") do
1150
+ assert_alias_method(object, :nonexistent, :original_method)
1151
+ end
1152
+
1153
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1154
+ "(Class: <Object>)") do
1155
+ assert_alias_method(object, :alias_method, :nonexistent)
1156
+ end
1157
+ end
1158
+
1159
+ def test_assert_path_exist
1160
+ check_nothing_fails do
1161
+ assert_path_exist(__FILE__)
1162
+ end
1163
+
1164
+ nonexistent_file = __FILE__ + ".nonexistent"
1165
+ check_fails("<#{nonexistent_file.inspect}> expected to exist") do
1166
+ assert_path_exist(nonexistent_file)
1167
+ end
1168
+ end
1169
+
1170
+ def test_assert_path_not_exist
1171
+ nonexistent_file = __FILE__ + ".nonexistent"
1172
+ check_nothing_fails do
1173
+ assert_path_not_exist(nonexistent_file)
1174
+ end
1175
+
1176
+ check_fails("<#{__FILE__.inspect}> expected to not exist") do
1177
+ assert_path_not_exist(__FILE__)
1178
+ end
1179
+ end
1180
+
1066
1181
  private
1067
- def add_failure(message, location=caller)
1182
+ def add_failure(message, location=caller, options=nil)
1068
1183
  unless @catch_assertions
1069
1184
  super
1070
1185
  end
@@ -0,0 +1,33 @@
1
+ require 'stringio'
2
+ require 'test/unit/ui/tap/testrunner'
3
+
4
+ class TestTap < Test::Unit::TestCase
5
+ def test_run
6
+ fail_line = nil
7
+ test_case = Class.new(Test::Unit::TestCase) do
8
+ def test_success
9
+ assert_equal(3, 1 + 2)
10
+ end
11
+
12
+ def test_fail; assert_equal(3, 1 - 2); end; fail_line = __LINE__
13
+ end
14
+ output = StringIO.new
15
+ runner = Test::Unit::UI::Tap::TestRunner.new(test_case.suite,
16
+ :output => output)
17
+ result = runner.start; start_line = __LINE__
18
+ assert_equal(<<-EOR, output.string.gsub(/[\d\.]+ seconds/, "0.001 seconds"))
19
+ 1..2
20
+ not ok 1 - test_fail(): <3> expected but was
21
+ # Failure:
22
+ # test_fail()
23
+ # [#{__FILE__}:#{fail_line}:in `test_fail'
24
+ # #{__FILE__}:#{start_line}:in `test_run']:
25
+ # <3> expected but was
26
+ # <-1>.
27
+ ok 2 - test_success()
28
+ # Finished in 0.001 seconds.
29
+ # 2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
30
+ EOR
31
+ assert_true(result.passed?)
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+
3
+ class TestUnitOutput < Test::Unit::TestCase
4
+ def test_capture_output
5
+ assert_equal(["stdout\n", "stderr\n"],
6
+ capture_output do
7
+ puts("stdout")
8
+ warn("stderr")
9
+ end)
10
+ end
11
+ end
@@ -2,8 +2,7 @@
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
5
- # License as published by the Free Software Foundation; either
6
- # version 2.1 of the License.
5
+ # License version 2.1 as published by the Free Software Foundation.
7
6
  #
8
7
  # This library is distributed in the hope that it will be useful,
9
8
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -33,14 +32,15 @@ module ActiveGroongaTestUtils
33
32
 
34
33
  setup_tmp_directory
35
34
  setup_database_directory
35
+ setup_database
36
36
  setup_tables_directory
37
37
  setup_metadata_directory
38
38
 
39
- setup_database
40
39
  setup_users_table
41
40
  setup_bookmarks_table
42
41
  setup_bookmarks_index_tables
43
42
  setup_tasks_table
43
+ setup_sites_table
44
44
 
45
45
  setup_user_records
46
46
  setup_bookmark_records
@@ -54,66 +54,64 @@ module ActiveGroongaTestUtils
54
54
  end
55
55
 
56
56
  def setup_database_directory
57
- @database_dir = @tmp_dir + "database"
57
+ @database_dir = @tmp_dir + "groonga"
58
58
  FileUtils.mkdir_p(@database_dir.to_s)
59
- ActiveGroonga::Base.database_directory = @database_dir.to_s
59
+ end
60
+
61
+ def setup_database
62
+ @database_path = @database_dir + "database"
63
+ @database = Groonga::Database.create(:path => @database_path.to_s)
64
+ ActiveGroonga::Base.database_path = @database_path.to_s
60
65
  end
61
66
 
62
67
  def setup_tables_directory
63
- @tables_dir = @database_dir + "tables"
68
+ @tables_dir = Pathname("#{@database_path}.tables")
64
69
  FileUtils.mkdir_p(@tables_dir.to_s)
65
70
  end
66
71
 
67
72
  def setup_metadata_directory
68
- @metadata_dir = @database_dir + "metadata"
73
+ @metadata_dir = Pathname("#{@database_path}.metadata")
69
74
  FileUtils.mkdir_p(@metadata_dir.to_s)
70
75
  end
71
76
 
72
- def setup_database
73
- @database_path = @database_dir + "database.groonga"
74
- @database = Groonga::Database.create(:path => @database_path.to_s)
75
-
76
- ActiveGroonga::Schema.initialize_schema_management_tables
77
- end
78
-
79
77
  def setup_users_table
80
- @users_path = @tables_dir + "users.groonga"
78
+ @users_path = @tables_dir + "users"
81
79
  @users = Groonga::Array.create(:name => "users",
82
80
  :path => @users_path.to_s,
83
81
  :sub_records => true)
84
82
 
85
- columns_dir = @tables_dir + "users" + "columns"
83
+ columns_dir = @tables_dir + "users.columns"
86
84
  columns_dir.mkpath
87
85
 
88
- @name_column_path = columns_dir + "name.groonga"
86
+ @name_column_path = columns_dir + "name"
89
87
  @name_column = @users.define_column("name", "ShortText",
90
88
  :path => @name_column_path.to_s)
91
89
  end
92
90
 
93
91
  def setup_bookmarks_table
94
- @bookmarks_path = @tables_dir + "bookmarks.groonga"
92
+ @bookmarks_path = @tables_dir + "bookmarks"
95
93
  @bookmarks = Groonga::Array.create(:name => "bookmarks",
96
94
  :path => @bookmarks_path.to_s,
97
95
  :sub_records => true)
98
96
 
99
- columns_dir = @tables_dir + "bookmarks" + "columns"
97
+ columns_dir = @tables_dir + "bookmarks.columns"
100
98
  columns_dir.mkpath
101
99
 
102
- @uri_column_path = columns_dir + "uri.groonga"
100
+ @uri_column_path = columns_dir + "uri"
103
101
  @uri_column = @bookmarks.define_column("uri", "ShortText",
104
102
  :path => @uri_column_path.to_s)
105
103
 
106
- @comment_column_path = columns_dir + "comment.groonga"
104
+ @comment_column_path = columns_dir + "comment"
107
105
  @comment_column =
108
106
  @bookmarks.define_column("comment", "Text",
109
107
  :path => @comment_column_path.to_s)
110
108
 
111
- @content_column_path = columns_dir + "content.groonga"
109
+ @content_column_path = columns_dir + "content"
112
110
  @content_column =
113
111
  @bookmarks.define_column("content", "LongText",
114
112
  :path => @content_column_path.to_s)
115
113
 
116
- @user_column_path = columns_dir + "user.groonga"
114
+ @user_column_path = columns_dir + "user"
117
115
  @user_column =
118
116
  @bookmarks.define_column("user", @users,
119
117
  :path => @user_column_path.to_s)
@@ -122,31 +120,28 @@ module ActiveGroongaTestUtils
122
120
  end
123
121
 
124
122
  def define_timestamp(table, columns_dir)
125
- created_at_column_path = columns_dir + "created_at.groonga"
123
+ created_at_column_path = columns_dir + "created_at"
126
124
  table.define_column("created_at", "Time",
127
125
  :path => created_at_column_path.to_s)
128
126
 
129
- updated_at_column_path = columns_dir + "updated_at.groonga"
127
+ updated_at_column_path = columns_dir + "updated_at"
130
128
  table.define_column("updated_at", "Time",
131
129
  :path => updated_at_column_path.to_s)
132
130
  end
133
131
 
134
132
  def setup_bookmarks_index_tables
135
- @terms_path = @tables_dir + "terms.groonga"
133
+ @terms_path = @tables_dir + "terms"
136
134
  @terms = Groonga::PatriciaTrie.create(:name => "terms",
137
135
  :key_type => "ShortText",
138
136
  :path => @terms_path.to_s,
139
137
  :default_tokenizer => "TokenBigram")
140
138
 
141
- columns_dir = @tables_dir + "terms" + "columns"
142
- bookmarks_index_dir = columns_dir + "bookmarks"
143
- bookmarks_index_dir.mkpath
144
-
145
- @bookmarks_content_index_column_path =
146
- bookmarks_index_dir + "content.groonga"
139
+ columns_dir = @tables_dir + "terms.columns"
140
+ columns_dir.mkpath
141
+ @bookmarks_content_index_column_path = columns_dir + "bookmarks_content"
147
142
  path = @bookmarks_content_index_column_path.to_s
148
143
  @bookmarks_content_index_column =
149
- @terms.define_index_column("bookmarks/content", @bookmarks,
144
+ @terms.define_index_column("bookmarks_content", @bookmarks,
150
145
  :with_section => true,
151
146
  :with_weight => true,
152
147
  :with_position => true,
@@ -155,19 +150,36 @@ module ActiveGroongaTestUtils
155
150
  end
156
151
 
157
152
  def setup_tasks_table
158
- @tasks_path = @tables_dir + "tasks.groonga"
153
+ @tasks_path = @tables_dir + "tasks"
159
154
  @tasks = Groonga::Array.create(:name => "tasks",
160
155
  :path => @tasks_path.to_s,
161
156
  :sub_records => true)
162
157
 
163
- columns_dir = @tables_dir + "tasks" + "columns"
158
+ columns_dir = @tables_dir + "tasks.columns"
164
159
  columns_dir.mkpath
165
160
 
166
- @name_column_path = columns_dir + "name.groonga"
161
+ @name_column_path = columns_dir + "name"
167
162
  @name_column = @tasks.define_column("name", "ShortText",
168
163
  :path => @name_column_path.to_s)
169
164
  end
170
165
 
166
+ def setup_sites_table
167
+ @sites_path = @tables_dir + "sites"
168
+ @sites = Groonga::Hash.create(:name => "sites",
169
+ :key_type => "ShortText",
170
+ :path => @sites_path.to_s)
171
+
172
+ columns_dir = @tables_dir + "sites.columns"
173
+ columns_dir.mkpath
174
+
175
+ @title_column_path = columns_dir + "title"
176
+ @title_column = @sites.define_column("title", "ShortText",
177
+ :path => @title_column_path.to_s)
178
+ @score_column_path = columns_dir + "score"
179
+ @score_column = @sites.define_column("score", "UInt32",
180
+ :path => @score_column_path.to_s)
181
+ end
182
+
171
183
  def setup_user_records
172
184
  @user_records = {}
173
185
 
@@ -197,10 +209,12 @@ module ActiveGroongaTestUtils
197
209
  remove_const(:User) if const_defined?(:User)
198
210
  remove_const(:Bookmark) if const_defined?(:Bookmark)
199
211
  remove_const(:Task) if const_defined?(:Task)
212
+ remove_const(:Site) if const_defined?(:Site)
200
213
  end
201
214
  load((base_dir + 'user.rb').to_s)
202
215
  load((base_dir + 'bookmark.rb').to_s)
203
216
  load((base_dir + 'task.rb').to_s)
217
+ load((base_dir + 'site.rb').to_s)
204
218
  end
205
219
 
206
220
  def teardown_sand_box