activegroonga 0.0.1

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 (121) hide show
  1. data/AUTHORS +1 -0
  2. data/NEWS.ja.rdoc +5 -0
  3. data/NEWS.rdoc +5 -0
  4. data/README.ja.rdoc +49 -0
  5. data/README.rdoc +49 -0
  6. data/Rakefile +175 -0
  7. data/lib/active_groonga.rb +75 -0
  8. data/lib/active_groonga/aggregations.rb +30 -0
  9. data/lib/active_groonga/associations.rb +93 -0
  10. data/lib/active_groonga/associations/belongs_to_association.rb +25 -0
  11. data/lib/active_groonga/attribute_methods.rb +36 -0
  12. data/lib/active_groonga/base.rb +1579 -0
  13. data/lib/active_groonga/column.rb +107 -0
  14. data/lib/active_groonga/dirty.rb +30 -0
  15. data/lib/active_groonga/fixtures.rb +92 -0
  16. data/lib/active_groonga/migration.rb +150 -0
  17. data/lib/active_groonga/rails_support.rb +31 -0
  18. data/lib/active_groonga/reflection.rb +30 -0
  19. data/lib/active_groonga/schema.rb +314 -0
  20. data/lib/active_groonga/schema_dumper.rb +147 -0
  21. data/lib/active_groonga/tasks.rb +16 -0
  22. data/lib/active_groonga/tasks/groonga.rake +162 -0
  23. data/lib/active_groonga/test_case.rb +21 -0
  24. data/lib/active_groonga/test_help.rb +21 -0
  25. data/lib/active_groonga/timestamp.rb +30 -0
  26. data/lib/active_groonga/validations.rb +26 -0
  27. data/lib/active_groonga/version.rb +24 -0
  28. data/license/LGPL +504 -0
  29. data/rails/README +28 -0
  30. data/rails/init.rb +70 -0
  31. data/rails_generators/model_groonga/USAGE +28 -0
  32. data/rails_generators/model_groonga/model_groonga_generator.rb +45 -0
  33. data/rails_generators/model_groonga/templates/fixtures.yml +17 -0
  34. data/rails_generators/model_groonga/templates/migration.rb +16 -0
  35. data/rails_generators/model_groonga/templates/model.rb +2 -0
  36. data/rails_generators/model_groonga/templates/unit_test.rb +8 -0
  37. data/test-unit/Rakefile +35 -0
  38. data/test-unit/TODO +5 -0
  39. data/test-unit/bin/testrb +5 -0
  40. data/test-unit/html/classic.html +15 -0
  41. data/test-unit/html/index.html +25 -0
  42. data/test-unit/html/index.html.ja +27 -0
  43. data/test-unit/lib/test/unit.rb +342 -0
  44. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  45. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  46. data/test-unit/lib/test/unit/attribute.rb +125 -0
  47. data/test-unit/lib/test/unit/autorunner.rb +306 -0
  48. data/test-unit/lib/test/unit/collector.rb +43 -0
  49. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  50. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  51. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  52. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  53. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  54. data/test-unit/lib/test/unit/color.rb +96 -0
  55. data/test-unit/lib/test/unit/diff.rb +538 -0
  56. data/test-unit/lib/test/unit/error.rb +124 -0
  57. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  58. data/test-unit/lib/test/unit/failure.rb +110 -0
  59. data/test-unit/lib/test/unit/fixture.rb +176 -0
  60. data/test-unit/lib/test/unit/notification.rb +125 -0
  61. data/test-unit/lib/test/unit/omission.rb +143 -0
  62. data/test-unit/lib/test/unit/pending.rb +146 -0
  63. data/test-unit/lib/test/unit/priority.rb +161 -0
  64. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  65. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  66. data/test-unit/lib/test/unit/testcase.rb +360 -0
  67. data/test-unit/lib/test/unit/testresult.rb +89 -0
  68. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  69. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  70. data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
  71. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  72. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  73. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  74. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  75. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  76. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  77. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  78. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  79. data/test-unit/lib/test/unit/version.rb +7 -0
  80. data/test-unit/sample/adder.rb +13 -0
  81. data/test-unit/sample/subtracter.rb +12 -0
  82. data/test-unit/sample/tc_adder.rb +18 -0
  83. data/test-unit/sample/tc_subtracter.rb +18 -0
  84. data/test-unit/sample/test_user.rb +22 -0
  85. data/test-unit/sample/ts_examples.rb +7 -0
  86. data/test-unit/test/collector/test-descendant.rb +135 -0
  87. data/test-unit/test/collector/test-load.rb +333 -0
  88. data/test-unit/test/collector/test_dir.rb +406 -0
  89. data/test-unit/test/collector/test_objectspace.rb +98 -0
  90. data/test-unit/test/run-test.rb +13 -0
  91. data/test-unit/test/test-attribute.rb +86 -0
  92. data/test-unit/test/test-color-scheme.rb +56 -0
  93. data/test-unit/test/test-color.rb +47 -0
  94. data/test-unit/test/test-diff.rb +477 -0
  95. data/test-unit/test/test-emacs-runner.rb +60 -0
  96. data/test-unit/test/test-fixture.rb +287 -0
  97. data/test-unit/test/test-notification.rb +33 -0
  98. data/test-unit/test/test-omission.rb +81 -0
  99. data/test-unit/test/test-pending.rb +70 -0
  100. data/test-unit/test/test-priority.rb +119 -0
  101. data/test-unit/test/test_assertions.rb +1082 -0
  102. data/test-unit/test/test_error.rb +26 -0
  103. data/test-unit/test/test_failure.rb +33 -0
  104. data/test-unit/test/test_testcase.rb +478 -0
  105. data/test-unit/test/test_testresult.rb +113 -0
  106. data/test-unit/test/test_testsuite.rb +129 -0
  107. data/test-unit/test/testunit-test-util.rb +14 -0
  108. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  109. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  110. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  111. data/test-unit/test/util/test_observable.rb +102 -0
  112. data/test-unit/test/util/test_procwrapper.rb +36 -0
  113. data/test/active-groonga-test-utils.rb +234 -0
  114. data/test/fixtures/bookmark.rb +2 -0
  115. data/test/fixtures/task.rb +2 -0
  116. data/test/fixtures/user.rb +2 -0
  117. data/test/run-test.rb +51 -0
  118. data/test/test-associations.rb +24 -0
  119. data/test/test-base.rb +194 -0
  120. data/test/test-schema.rb +49 -0
  121. metadata +192 -0
@@ -0,0 +1,110 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ require 'test/unit/error'
8
+
9
+ module Test
10
+ module Unit
11
+
12
+ # A collection of tests which can be #run.
13
+ #
14
+ # Note: It is easy to confuse a TestSuite instance with
15
+ # something that has a static suite method; I know because _I_
16
+ # have trouble keeping them straight. Think of something that
17
+ # has a suite method as simply providing a way to get a
18
+ # meaningful TestSuite instance.
19
+ class TestSuite
20
+ attr_reader :name, :tests
21
+
22
+ STARTED = name + "::STARTED"
23
+ FINISHED = name + "::FINISHED"
24
+
25
+ # Creates a new TestSuite with the given name.
26
+ def initialize(name="Unnamed TestSuite", test_case=nil)
27
+ @name = name
28
+ @tests = []
29
+ @test_case = test_case
30
+ end
31
+
32
+ # Runs the tests and/or suites contained in this
33
+ # TestSuite.
34
+ def run(result, &progress_block)
35
+ yield(STARTED, name)
36
+ run_startup(result)
37
+ @tests.each do |test|
38
+ test.run(result, &progress_block)
39
+ end
40
+ run_shutdown(result)
41
+ yield(FINISHED, name)
42
+ end
43
+
44
+ # Adds the test to the suite.
45
+ def <<(test)
46
+ @tests << test
47
+ self
48
+ end
49
+
50
+ def delete(test)
51
+ @tests.delete(test)
52
+ end
53
+
54
+ # Retuns the rolled up number of tests in this suite;
55
+ # i.e. if the suite contains other suites, it counts the
56
+ # tests within those suites, not the suites themselves.
57
+ def size
58
+ total_size = 0
59
+ @tests.each { |test| total_size += test.size }
60
+ total_size
61
+ end
62
+
63
+ def empty?
64
+ tests.empty?
65
+ end
66
+
67
+ # Overridden to return the name given the suite at
68
+ # creation.
69
+ def to_s
70
+ @name
71
+ end
72
+
73
+ # It's handy to be able to compare TestSuite instances.
74
+ def ==(other)
75
+ return false unless(other.kind_of?(self.class))
76
+ return false unless(@name == other.name)
77
+ @tests == other.tests
78
+ end
79
+
80
+ private
81
+ def run_startup(result)
82
+ return if @test_case.nil? or !@test_case.respond_to?(:startup)
83
+ begin
84
+ @test_case.startup
85
+ rescue Exception
86
+ raise unless handle_exception($!, result)
87
+ end
88
+ end
89
+
90
+ def run_shutdown(result)
91
+ return if @test_case.nil? or !@test_case.respond_to?(:shutdown)
92
+ begin
93
+ @test_case.shutdown
94
+ rescue Exception
95
+ raise unless handle_exception($!, result)
96
+ end
97
+ end
98
+
99
+ def handle_exception(exception, result)
100
+ case exception
101
+ when *ErrorHandler::PASS_THROUGH_EXCEPTIONS
102
+ false
103
+ else
104
+ result.add_error(Error.new(@test_case.name, exception))
105
+ true
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,14 @@
1
+ module Test
2
+ module Unit
3
+ module UI
4
+ module Console
5
+ module OutputLevel
6
+ SILENT = 0
7
+ PROGRESS_ONLY = 1
8
+ NORMAL = 2
9
+ VERBOSE = 3
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,220 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ require 'test/unit/color-scheme'
8
+ require 'test/unit/ui/testrunner'
9
+ require 'test/unit/ui/testrunnermediator'
10
+ require 'test/unit/ui/console/outputlevel'
11
+
12
+ module Test
13
+ module Unit
14
+ module UI
15
+ module Console
16
+
17
+ # Runs a Test::Unit::TestSuite on the console.
18
+ class TestRunner < UI::TestRunner
19
+ include OutputLevel
20
+
21
+ # Creates a new TestRunner for running the passed
22
+ # suite. If quiet_mode is true, the output while
23
+ # running is limited to progress dots, errors and
24
+ # failures, and the final result. io specifies
25
+ # where runner output should go to; defaults to
26
+ # STDOUT.
27
+ def initialize(suite, options={})
28
+ super
29
+ @output_level = @options[:output_level] || NORMAL
30
+ @output = @options[:output] || STDOUT
31
+ @use_color = @options[:use_color]
32
+ @use_color = guess_color_availability if @use_color.nil?
33
+ @color_scheme = @options[:color_scheme] || ColorScheme.default
34
+ @reset_color = Color.new("reset")
35
+ @progress_row = 0
36
+ @progress_row_max = @options[:progress_row_max]
37
+ @progress_row_max ||= guess_progress_row_max
38
+ @already_outputted = false
39
+ @faults = []
40
+ end
41
+
42
+ # Begins the test run.
43
+ def start
44
+ setup_mediator
45
+ attach_to_mediator
46
+ return start_mediator
47
+ end
48
+
49
+ private
50
+ def setup_mediator
51
+ @mediator = create_mediator(@suite)
52
+ output_setup_end
53
+ end
54
+
55
+ def output_setup_end
56
+ suite_name = @suite.to_s
57
+ suite_name = @suite.name if @suite.kind_of?(Module)
58
+ output("Loaded suite #{suite_name}")
59
+ end
60
+
61
+ def create_mediator(suite)
62
+ return TestRunnerMediator.new(suite)
63
+ end
64
+
65
+ def attach_to_mediator
66
+ @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
67
+ @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
68
+ @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
69
+ @mediator.add_listener(TestCase::STARTED, &method(:test_started))
70
+ @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
71
+ end
72
+
73
+ def start_mediator
74
+ return @mediator.run_suite
75
+ end
76
+
77
+ def add_fault(fault)
78
+ @faults << fault
79
+ output_progress(fault.single_character_display, fault_color(fault))
80
+ @already_outputted = true
81
+ end
82
+
83
+ def started(result)
84
+ @result = result
85
+ output_started
86
+ end
87
+
88
+ def output_started
89
+ output("Started")
90
+ end
91
+
92
+ def finished(elapsed_time)
93
+ nl if output?(NORMAL) and !output?(VERBOSE)
94
+ nl
95
+ output("Finished in #{elapsed_time} seconds.")
96
+ @faults.each_with_index do |fault, index|
97
+ nl
98
+ output_single("%3d) " % (index + 1))
99
+ label, detail = format_fault(fault).split(/\r?\n/, 2)
100
+ output(label, fault_color(fault))
101
+ output(detail)
102
+ end
103
+ nl
104
+ output(@result, result_color)
105
+ end
106
+
107
+ def format_fault(fault)
108
+ fault.long_display
109
+ end
110
+
111
+ def test_started(name)
112
+ output_single(name + ": ", nil, VERBOSE)
113
+ end
114
+
115
+ def test_finished(name)
116
+ unless @already_outputted
117
+ output_progress(".", color("success"))
118
+ end
119
+ nl(VERBOSE)
120
+ @already_outputted = false
121
+ end
122
+
123
+ def nl(level=NORMAL)
124
+ output("", nil, level)
125
+ end
126
+
127
+ def output(something, color=nil, level=NORMAL)
128
+ return unless output?(level)
129
+ output_single(something, color, level)
130
+ @output.puts
131
+ end
132
+
133
+ def output_single(something, color=nil, level=NORMAL)
134
+ return false unless output?(level)
135
+ if @use_color and color
136
+ something = "%s%s%s" % [color.escape_sequence,
137
+ something,
138
+ @reset_color.escape_sequence]
139
+ end
140
+ @output.write(something)
141
+ @output.flush
142
+ true
143
+ end
144
+
145
+ def output_progress(mark, color=nil)
146
+ if output_single(mark, color, PROGRESS_ONLY)
147
+ return unless @progress_row_max > 0
148
+ @progress_row += mark.size
149
+ if @progress_row >= @progress_row_max
150
+ nl unless @output_level == VERBOSE
151
+ @progress_row = 0
152
+ end
153
+ end
154
+ end
155
+
156
+ def output?(level)
157
+ level <= @output_level
158
+ end
159
+
160
+ def color(name)
161
+ @color_scheme[name] || ColorScheme.default[name]
162
+ end
163
+
164
+ def fault_color(fault)
165
+ color(fault.class.name.split(/::/).last.downcase)
166
+ end
167
+
168
+ def result_color
169
+ if @result.passed?
170
+ if @result.pending_count > 0
171
+ color("pending")
172
+ elsif @result.omission_count > 0
173
+ color("omission")
174
+ elsif @result.notification_count > 0
175
+ color("notification")
176
+ else
177
+ color("success")
178
+ end
179
+ elsif @result.error_count > 0
180
+ color("error")
181
+ elsif @result.failure_count > 0
182
+ color("failure")
183
+ end
184
+ end
185
+
186
+ def guess_color_availability
187
+ return false unless @output.tty?
188
+ term = ENV["TERM"]
189
+ return true if term and (/term\z/ =~ term or term == "screen")
190
+ return true if ENV["EMACS"] == "t"
191
+ false
192
+ end
193
+
194
+ def guess_progress_row_max
195
+ term_width = guess_term_width
196
+ if term_width.zero?
197
+ if ENV["EMACS"] == "t"
198
+ -1
199
+ else
200
+ 79
201
+ end
202
+ else
203
+ term_width
204
+ end
205
+ end
206
+
207
+ def guess_term_width
208
+ Integer(ENV["TERM_WIDTH"] || 0)
209
+ rescue ArgumentError
210
+ 0
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+
218
+ if __FILE__ == $0
219
+ Test::Unit::UI::Console::TestRunner.start_command_line_test
220
+ end
@@ -0,0 +1,49 @@
1
+ require 'test/unit/ui/console/testrunner'
2
+
3
+ module Test
4
+ module Unit
5
+ module UI
6
+ module Emacs
7
+ class TestRunner < Console::TestRunner
8
+ private
9
+ def output_setup_end
10
+ end
11
+
12
+ def output_started
13
+ end
14
+
15
+ def format_fault(fault)
16
+ return super unless fault.respond_to?(:label)
17
+ format_method_name = "format_fault_#{fault.label.downcase}"
18
+ if respond_to?(format_method_name, true)
19
+ send(format_method_name, fault)
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ def format_fault_failure(failure)
26
+ if failure.location.size == 1
27
+ location = failure.location[0]
28
+ location_display = location.sub(/\A(.+:\d+).*/, ' [\\1]')
29
+ else
30
+ location_display = "\n" + failure.location.join("\n")
31
+ end
32
+ result = "#{failure.label}:\n"
33
+ result << "#{failure.test_name}#{location_display}:\n"
34
+ result << failure.message
35
+ result
36
+ end
37
+
38
+ def format_fault_error(error)
39
+ result = "#{error.label}:\n"
40
+ result << "#{error.test_name}:\n"
41
+ result << "#{error.message}\n"
42
+ result << error.backtrace.join("\n")
43
+ result
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ require 'test/unit/ui/testrunnerutilities'
2
+
3
+ module Test
4
+ module Unit
5
+ module UI
6
+ class TestRunner
7
+ extend TestRunnerUtilities
8
+
9
+ def initialize(suite, options={})
10
+ if suite.respond_to?(:suite)
11
+ @suite = suite.suite
12
+ else
13
+ @suite = suite
14
+ end
15
+ @options = options
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ #--
2
+ #
3
+ # Author:: Nathaniel Talbott.
4
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
+ # License:: Ruby license.
6
+
7
+ require 'test/unit'
8
+ require 'test/unit/util/observable'
9
+ require 'test/unit/testresult'
10
+
11
+ module Test
12
+ module Unit
13
+ module UI
14
+
15
+ # Provides an interface to write any given UI against,
16
+ # hopefully making it easy to write new UIs.
17
+ class TestRunnerMediator
18
+ RESET = name + "::RESET"
19
+ STARTED = name + "::STARTED"
20
+ FINISHED = name + "::FINISHED"
21
+
22
+ include Util::Observable
23
+
24
+ # Creates a new TestRunnerMediator initialized to run
25
+ # the passed suite.
26
+ def initialize(suite)
27
+ @suite = suite
28
+ end
29
+
30
+ # Runs the suite the TestRunnerMediator was created
31
+ # with.
32
+ def run_suite
33
+ Unit.run = true
34
+
35
+ result = create_result
36
+ result_listener = result.add_listener(TestResult::CHANGED) do |*args|
37
+ notify_listeners(TestResult::CHANGED, *args)
38
+ end
39
+ fault_listener = result.add_listener(TestResult::FAULT) do |*args|
40
+ notify_listeners(TestResult::FAULT, *args)
41
+ end
42
+
43
+ start_time = Time.now
44
+ begin
45
+ notify_listeners(RESET, @suite.size)
46
+ notify_listeners(STARTED, result)
47
+
48
+ @suite.run(result) do |channel, value|
49
+ notify_listeners(channel, value)
50
+ end
51
+ ensure
52
+ elapsed_time = Time.now - start_time
53
+ result.remove_listener(TestResult::FAULT, fault_listener)
54
+ result.remove_listener(TestResult::CHANGED, result_listener)
55
+ notify_listeners(FINISHED, elapsed_time)
56
+ end
57
+
58
+ result
59
+ end
60
+
61
+ private
62
+ # A factory method to create the result the mediator
63
+ # should run with. Can be overridden by subclasses if
64
+ # one wants to use a different result.
65
+ def create_result
66
+ TestResult.new
67
+ end
68
+
69
+ def measure_time
70
+ begin_time = Time.now
71
+ yield
72
+ Time.now - begin_time
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end