activegroonga 0.0.2 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/NEWS.ja.rdoc +4 -0
  2. data/NEWS.rdoc +4 -0
  3. data/README.ja.rdoc +1 -1
  4. data/README.rdoc +1 -1
  5. data/Rakefile +3 -4
  6. data/lib/active_groonga.rb +2 -0
  7. data/lib/active_groonga/base.rb +125 -99
  8. data/lib/active_groonga/column.rb +9 -0
  9. data/lib/active_groonga/dynamic_record_expression_builder.rb +40 -0
  10. data/lib/active_groonga/schema.rb +107 -204
  11. data/lib/active_groonga/schema_dumper.rb +40 -25
  12. data/lib/active_groonga/tasks/groonga.rake +2 -0
  13. data/lib/active_groonga/version.rb +1 -1
  14. data/rails_generators/index_table_groonga/USAGE +23 -0
  15. data/rails_generators/index_table_groonga/index_table_groonga_generator.rb +44 -0
  16. data/rails_generators/index_table_groonga/templates/migration.rb +12 -0
  17. data/rails_generators/migration_groonga/USAGE +29 -0
  18. data/rails_generators/migration_groonga/migration_groonga_generator.rb +19 -0
  19. data/rails_generators/migration_groonga/templates/migration.rb +11 -0
  20. data/test-unit/Rakefile +6 -1
  21. data/test-unit/lib/test/unit/autorunner.rb +26 -3
  22. data/test-unit/lib/test/unit/priority.rb +21 -1
  23. data/test-unit/lib/test/unit/testcase.rb +101 -36
  24. data/test-unit/lib/test/unit/ui/console/testrunner.rb +7 -4
  25. data/test-unit/test/{test_testcase.rb → test-testcase.rb} +30 -1
  26. data/test-unit/test/test_assertions.rb +1 -1
  27. data/test/active-groonga-test-utils.rb +25 -26
  28. data/test/test-base.rb +16 -6
  29. data/test/test-schema-dumper.rb +48 -0
  30. data/test/test-schema.rb +20 -4
  31. data/test/tmp/database/database.groonga +0 -0
  32. data/test/tmp/database/database.groonga.0000000 +0 -0
  33. data/test/tmp/database/database.groonga.0000100 +0 -0
  34. data/test/tmp/database/database.groonga.0000101 +0 -0
  35. metadata +19 -7
@@ -150,6 +150,8 @@ namespace :groonga do
150
150
  task :purge => :environment do
151
151
  ActiveGroonga::Base.setup_database(:test)
152
152
  ActiveGroonga::Base.database.remove
153
+ rm_rf(ActiveGroonga::Base.database_directory)
154
+ # FIXME: groonga isn't fully implemented remove for database.
153
155
  end
154
156
 
155
157
  desc 'Check for pending migrations and load the test schema'
@@ -17,7 +17,7 @@ module ActiveGroonga
17
17
  module VERSION
18
18
  MAJOR = 0
19
19
  MINOR = 0
20
- TINY = 2
20
+ TINY = 6
21
21
 
22
22
  STRING = [MAJOR, MINOR, TINY].join(".")
23
23
  end
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Stubs out a new index table migration. Pass the index table name
3
+ and an optional tokenizer as an argument.
4
+
5
+ A migration class is generated in db/groonga/migrate prefixed by a timestamp of the current date and time.
6
+
7
+ Example:
8
+ `./script/generate index_table_groonga terms`
9
+
10
+ If the current date is May 14, 2008 and the current time 09:09:12, this creates the CreateTerms migration
11
+ db/groonga/migrate/20080514090912_create_terms.rb
12
+
13
+ `./script/generate index_table_groonga terms TokenMeCab`
14
+
15
+ This will create the CreateTerms in db/groonga/migrate/20080514090912_create_terms.rb with
16
+ this in the Up migration:
17
+
18
+ create_table :terms, :default_tokenizer => "TokenMeCab" do |t|
19
+ end
20
+
21
+ And this in the Down migration:
22
+
23
+ drop_table :terms
@@ -0,0 +1,44 @@
1
+ class IndexTableGroongaGenerator < Rails::Generator::NamedBase
2
+ default_options :type => nil, :tokenizer => nil
3
+
4
+ def manifest
5
+ record do |m|
6
+ m.migration_template 'migration.rb', 'db/groonga/migrate', :assigns => {
7
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
8
+ :type => (options[:type] || :patricia_trie).inspect,
9
+ :default_tokenizer_name => (options[:tokenizer] || "TokenBigram").inspect,
10
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
11
+ end
12
+ end
13
+
14
+ private
15
+ def banner
16
+ "Usage: #{$0} #{spec.name} index_table_name\n" +
17
+ " e.g.: #{$0} #{spec.name} terms"
18
+ end
19
+
20
+ def add_options!(opt)
21
+ opt.separator ''
22
+ opt.separator 'Options:'
23
+ opt.on("--type=TYPE", %w(array patricia_trie hash),
24
+ "Use TYPE as a table type") do |value|
25
+ options[:type] = value
26
+ end
27
+
28
+ opt.on("--tokenizer=TOKENIZER", %w(unigram bigram trigram mecab),
29
+ "Use TOKENIZER as a default tokenizer") do |value|
30
+ case value
31
+ when "unigram"
32
+ options[:tokenizer] = "TokenUnigram"
33
+ when "bigram"
34
+ options[:tokenizer] = "TokenBigram"
35
+ when "trigram"
36
+ options[:tokenizer] = "TokenTrigram"
37
+ when "mecab"
38
+ options[:tokenizer] = "TokenMacab"
39
+ else
40
+ options[:tokenizer] = value
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ class <%= migration_name %> < ActiveGroonga::Migration
2
+ def self.up
3
+ create_table :<%= table_name %>,
4
+ :type => <%= type %>,
5
+ :default_tokenizer => <%= default_tokenizer_name %> do |t|
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :<%= table_name %>
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Stubs out a new database migration. Pass the migration name, either
3
+ CamelCased or under_scored, and an optional list of attribute pairs as arguments.
4
+
5
+ A migration class is generated in db/groonga/migrate prefixed by a timestamp of the current date and time.
6
+
7
+ You can name your migration in either of these formats to generate add/remove
8
+ column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
9
+
10
+ Example:
11
+ `./script/generate migration_groonga AddSslFlag`
12
+
13
+ If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
14
+ db/groonga/migrate/20080514090912_add_ssl_flag.rb
15
+
16
+ `./script/generate migration_groonga AddTitleBodyToPost title:string body:text published:boolean`
17
+
18
+ This will create the AddTitleBodyToPost in db/groonga/migrate/20080514090912_add_title_body_to_post.rb with
19
+ this in the Up migration:
20
+
21
+ add_column :posts, :title, :string
22
+ add_column :posts, :body, :text
23
+ add_column :posts, :published, :boolean
24
+
25
+ And this in the Down migration:
26
+
27
+ remove_column :posts, :published
28
+ remove_column :posts, :body
29
+ remove_column :posts, :title
@@ -0,0 +1,19 @@
1
+ class MigrationGroongaGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/groonga/migrate', :assigns => get_local_assigns
5
+ end
6
+ end
7
+
8
+ private
9
+ def get_local_assigns
10
+ returning(assigns = {}) do
11
+ if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
12
+ assigns[:migration_action] = $1
13
+ assigns[:table_name] = $2.pluralize
14
+ else
15
+ assigns[:attributes] = []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ class <%= class_name.underscore.camelize %> < ActiveGroonga::Migration
2
+ def self.up<% attributes.each do |attribute| %>
3
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
4
+ <%- end %>
5
+ end
6
+
7
+ def self.down<% attributes.reverse.each do |attribute| %>
8
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
9
+ <%- end %>
10
+ end
11
+ end
data/test-unit/Rakefile CHANGED
@@ -1,12 +1,17 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
+ gem 'rdoc'
4
5
  require 'hoe'
5
6
  require './lib/test/unit/version.rb'
6
7
 
8
+ ENV["NODOT"] = "yes"
9
+
7
10
  version = Test::Unit::VERSION
8
11
  ENV["VERSION"] = version
9
- Hoe.new('test-unit', version) do |p|
12
+ Hoe.spec('test-unit') do |p|
13
+ Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
14
+ p.version = version
10
15
  p.developer('Kouhei Sutou', 'kou@cozmixng.org')
11
16
  p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
12
17
 
@@ -203,6 +203,13 @@ module Test
203
203
  end
204
204
  end
205
205
 
206
+ o.on("--default-priority=PRIORITY",
207
+ Priority.available_values,
208
+ "Uses PRIORITY as default priority",
209
+ "(#{keyword_display(Priority.available_values)})") do |priority|
210
+ Priority.default = priority
211
+ end
212
+
206
213
  o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
207
214
  "Appends directory list to $LOAD_PATH.") do |dirs|
208
215
  $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
@@ -220,6 +227,12 @@ module Test
220
227
  load_config(file)
221
228
  end
222
229
 
230
+ o.on("--order=ORDER", TestCase::AVAILABLE_ORDERS,
231
+ "Run tests in a test case in ORDER order.",
232
+ "(#{keyword_display(TestCase::AVAILABLE_ORDERS)})") do |order|
233
+ TestCase.test_order = order
234
+ end
235
+
223
236
  ADDITIONAL_OPTIONS.each do |option_builder|
224
237
  option_builder.call(self, o)
225
238
  end
@@ -251,10 +264,20 @@ module Test
251
264
  end
252
265
 
253
266
  def keyword_display(keywords)
254
- keywords.collect do |keyword, _|
267
+ keywords = keywords.collect do |keyword, _|
255
268
  keyword.to_s
256
- end.uniq.sort.collect do |keyword|
257
- keyword.sub(/^(.)([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')
269
+ end.uniq.sort
270
+
271
+ i = 0
272
+ keywords.collect do |keyword|
273
+ if (i > 0 and keyword[0] == keywords[i - 1][0]) or
274
+ ((i < keywords.size - 1) and (keyword[0] == keywords[i + 1][0]))
275
+ n = 2
276
+ else
277
+ n = 1
278
+ end
279
+ i += 1
280
+ keyword.sub(/^(.{#{n}})([A-Za-z]+)(?=\w*$)/, '\\1[\\2]')
258
281
  end.join(", ")
259
282
  end
260
283
 
@@ -26,6 +26,19 @@ module Test
26
26
  def disable
27
27
  @@enabled = false
28
28
  end
29
+
30
+ @@default = :normal
31
+ def default
32
+ @@default || :normal
33
+ end
34
+
35
+ def default=(default)
36
+ @@default = default
37
+ end
38
+
39
+ def available_values
40
+ Checker.available_priorities
41
+ end
29
42
  end
30
43
 
31
44
  class Checker
@@ -36,7 +49,7 @@ module Test
36
49
  end
37
50
 
38
51
  def need_to_run?(test)
39
- priority = test[:priority] || :normal
52
+ priority = test[:priority] || Priority.default
40
53
  if have_priority?(priority)
41
54
  send(priority_check_method_name(priority), test)
42
55
  else
@@ -44,6 +57,13 @@ module Test
44
57
  end
45
58
  end
46
59
 
60
+ def available_priorities
61
+ methods(false).collect do |name|
62
+ /\Arun_priority_(.+)\?\z/ =~ name.to_s
63
+ $1
64
+ end.compact
65
+ end
66
+
47
67
  def run_priority_must?(test)
48
68
  true
49
69
  end
@@ -1,7 +1,9 @@
1
1
  #--
2
2
  #
3
3
  # Author:: Nathaniel Talbott.
4
- # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
4
+ # Copyright::
5
+ # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
+ # * Copyright (c) 2008-2009 Kouhei Sutou <tt><kou@clear-code.com></tt>
5
7
  # License:: Ruby license.
6
8
 
7
9
  require 'test/unit/attribute'
@@ -60,14 +62,14 @@ module Test
60
62
  # end
61
63
  #
62
64
  # Here is a call order:
63
- # * startup
64
- # * setup
65
- # * test_my_method1
66
- # * teardown
67
- # * setup
68
- # * test_my_method2
69
- # * teardown
70
- # * shutdown
65
+ # * startup
66
+ # * setup
67
+ # * test_my_method1
68
+ # * teardown
69
+ # * setup
70
+ # * test_my_method2
71
+ # * teardown
72
+ # * shutdown
71
73
  class TestCase
72
74
  include Attribute
73
75
  include Fixture
@@ -81,24 +83,29 @@ module Test
81
83
  include Assertions
82
84
  include Util::BacktraceFilter
83
85
 
84
- STARTED = name + "::STARTED"
85
- FINISHED = name + "::FINISHED"
86
+ STARTED = name + "::STARTED" # :nodoc:
87
+ FINISHED = name + "::FINISHED" # :nodoc:
86
88
 
87
- DESCENDANTS = []
89
+ DESCENDANTS = [] # :nodoc:
90
+ AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
88
91
 
89
92
  class << self
90
- def inherited(sub_class)
93
+ def inherited(sub_class) # :nodoc:
91
94
  DESCENDANTS << sub_class
92
95
  end
93
96
 
97
+ @@added_methods = []
98
+ def method_added(name) # :nodoc:
99
+ super
100
+ @@added_methods << name.to_s
101
+ end
102
+
94
103
  # Rolls up all of the test* methods in the fixture into
95
104
  # one suite, creating a new instance of the fixture for
96
105
  # each method.
97
106
  def suite
98
- method_names = public_instance_methods(true).collect {|name| name.to_s}
99
- tests = method_names.delete_if {|method_name| method_name !~ /^test./}
100
107
  suite = TestSuite.new(name, self)
101
- tests.sort.each do |test|
108
+ collect_test_names.each do |test|
102
109
  catch(:invalid_test) do
103
110
  suite << new(test)
104
111
  end
@@ -137,11 +144,11 @@ module Test
137
144
  # end
138
145
  #
139
146
  # Here is a call order:
140
- # * startup
141
- # * setup
142
- # * test_my_class1 (or test_my_class2)
143
- # * setup
144
- # * test_my_class2 (or test_my_class1)
147
+ # * startup
148
+ # * setup
149
+ # * test_my_class1 (or test_my_class2)
150
+ # * setup
151
+ # * test_my_class2 (or test_my_class1)
145
152
  #
146
153
  # Note that you should not assume test order. Tests
147
154
  # should be worked in any order.
@@ -173,16 +180,74 @@ module Test
173
180
  # end
174
181
  #
175
182
  # Here is a call order:
176
- # * test_my_class1 (or test_my_class2)
177
- # * teardown
178
- # * test_my_class2 (or test_my_class1)
179
- # * teardown
180
- # * shutdown
183
+ # * test_my_class1 (or test_my_class2)
184
+ # * teardown
185
+ # * test_my_class2 (or test_my_class1)
186
+ # * teardown
187
+ # * shutdown
181
188
  #
182
189
  # Note that you should not assume test order. Tests
183
190
  # should be worked in any order.
184
191
  def shutdown
185
192
  end
193
+
194
+ @@test_order = AVAILABLE_ORDERS.first
195
+
196
+ # Returns the current test order. This returns
197
+ # +:alphabetic+ by default.
198
+ def test_order
199
+ @@test_order
200
+ end
201
+
202
+ # Sets the current test order.
203
+ #
204
+ # Here are the available _order_:
205
+ # [:alphabetic]
206
+ # Default. Tests are sorted in alphabetic order.
207
+ # [:random]
208
+ # Tests are sorted in random order.
209
+ # [:defined]
210
+ # Tests are sorted in defined order.
211
+ def test_order=(order)
212
+ @@test_order = order
213
+ end
214
+
215
+ # :stopdoc:
216
+ private
217
+ def collect_test_names
218
+ method_names = public_instance_methods(true).collect do |name|
219
+ name.to_s
220
+ end
221
+ test_names = method_names.find_all do |method_name|
222
+ method_name =~ /^test./
223
+ end
224
+ send("sort_test_names_in_#{test_order}_order", test_names)
225
+ end
226
+
227
+ def sort_test_names_in_alphabetic_order(test_names)
228
+ test_names.sort
229
+ end
230
+
231
+ def sort_test_names_in_random_order(test_names)
232
+ test_names.sort_by {rand(test_names.size)}
233
+ end
234
+
235
+ def sort_test_names_in_defined_order(test_names)
236
+ test_names.sort do |test1, test2|
237
+ test1_defined_order = @@added_methods.index(test1)
238
+ test2_defined_order = @@added_methods.index(test2)
239
+ if test1_defined_order and test2_defined_order
240
+ test1_defined_order <=> test2_defined_order
241
+ elsif test1_defined_order
242
+ 1
243
+ elsif test2_defined_order
244
+ -1
245
+ else
246
+ test1 <=> test2
247
+ end
248
+ end
249
+ end
250
+ # :startdoc:
186
251
  end
187
252
 
188
253
  attr_reader :method_name
@@ -225,7 +290,7 @@ module Test
225
290
  result.add_run
226
291
  yield(FINISHED, name)
227
292
  ensure
228
- @_result = nil
293
+ # @_result = nil # For test-spec's after_all :<
229
294
  end
230
295
  end
231
296
 
@@ -255,10 +320,10 @@ module Test
255
320
  # end
256
321
  #
257
322
  # Here is a call order:
258
- # * setup
259
- # * my_setup1
260
- # * my_setup2
261
- # * test_my_class
323
+ # * setup
324
+ # * my_setup1
325
+ # * my_setup2
326
+ # * test_my_class
262
327
  def setup
263
328
  end
264
329
 
@@ -288,13 +353,13 @@ module Test
288
353
  # end
289
354
  #
290
355
  # Here is a call order:
291
- # * test_my_class
292
- # * my_teardown2
293
- # * my_teardown1
294
- # * teardown
356
+ # * test_my_class
357
+ # * my_teardown2
358
+ # * my_teardown1
359
+ # * teardown
295
360
  def teardown
296
361
  end
297
-
362
+
298
363
  def default_test
299
364
  flunk("No tests were specified")
300
365
  end