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,36 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit'
6
+ require 'test/unit/util/procwrapper'
7
+
8
+ module Test
9
+ module Unit
10
+ module Util
11
+ class TC_ProcWrapper < TestCase
12
+ def munge_proc(&a_proc)
13
+ return a_proc
14
+ end
15
+ def setup
16
+ @original = proc {}
17
+ @munged = munge_proc(&@original)
18
+ @wrapped_original = ProcWrapper.new(@original)
19
+ @wrapped_munged = ProcWrapper.new(@munged)
20
+ end
21
+ def test_wrapping
22
+ assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped")
23
+ end
24
+ def test_hashing
25
+
26
+ assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped")
27
+ assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent")
28
+
29
+ a_hash = {@wrapped_original => @original}
30
+ assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash")
31
+ assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,234 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
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.
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 'fileutils'
18
+ require 'pathname'
19
+
20
+ require 'active_groonga'
21
+
22
+ module ActiveGroongaTestUtils
23
+ class << self
24
+ def included(base)
25
+ base.setup :setup_sand_box, :before => :prepend
26
+ base.teardown :teardown_sand_box, :after => :append
27
+ end
28
+ end
29
+
30
+ def setup_sand_box
31
+ Groonga::Context.default = nil
32
+ @context = Groonga::Context.default
33
+
34
+ setup_tmp_directory
35
+ setup_database_directory
36
+ setup_tables_directory
37
+ setup_metadata_directory
38
+
39
+ setup_database
40
+ setup_users_table
41
+ setup_bookmarks_table
42
+ setup_bookmarks_index_tables
43
+ setup_tasks_table
44
+
45
+ setup_user_records
46
+ setup_bookmark_records
47
+ setup_class
48
+ end
49
+
50
+ def setup_tmp_directory
51
+ @tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
52
+ FileUtils.rm_rf(@tmp_dir.to_s)
53
+ FileUtils.mkdir_p(@tmp_dir.to_s)
54
+ end
55
+
56
+ def setup_database_directory
57
+ @database_dir = @tmp_dir + "database"
58
+ FileUtils.mkdir_p(@database_dir.to_s)
59
+ ActiveGroonga::Base.database_directory = @database_dir.to_s
60
+ end
61
+
62
+ def setup_tables_directory
63
+ @tables_dir = @database_dir + "tables"
64
+ FileUtils.mkdir_p(@tables_dir.to_s)
65
+ end
66
+
67
+ def setup_metadata_directory
68
+ @metadata_dir = @database_dir + "metadata"
69
+ FileUtils.mkdir_p(@metadata_dir.to_s)
70
+ end
71
+
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
+ def setup_users_table
80
+ @users_path = @tables_dir + "users.groonga"
81
+ @users = Groonga::Array.create(:name => "<table:users>",
82
+ :path => @users_path.to_s)
83
+
84
+ columns_dir = @tables_dir + "users" + "columns"
85
+ columns_dir.mkpath
86
+
87
+ @name_column_path = columns_dir + "name.groonga"
88
+ @name_column = @users.define_column("name", "<shorttext>",
89
+ :path => @name_column_path.to_s)
90
+ end
91
+
92
+ def setup_bookmarks_table
93
+ @bookmarks_path = @tables_dir + "bookmarks.groonga"
94
+ @bookmarks = Groonga::Array.create(:name => "<table:bookmarks>",
95
+ :path => @bookmarks_path.to_s)
96
+
97
+ columns_dir = @tables_dir + "bookmarks" + "columns"
98
+ columns_dir.mkpath
99
+
100
+ @uri_column_path = columns_dir + "uri.groonga"
101
+ @uri_column = @bookmarks.define_column("uri", "<shorttext>",
102
+ :path => @uri_column_path.to_s)
103
+
104
+ @comment_column_path = columns_dir + "comment.groonga"
105
+ @comment_column =
106
+ @bookmarks.define_column("comment", "<text>",
107
+ :path => @comment_column_path.to_s)
108
+
109
+ @content_column_path = columns_dir + "content.groonga"
110
+ @content_column =
111
+ @bookmarks.define_column("content", "<longtext>",
112
+ :path => @content_column_path.to_s)
113
+
114
+ @user_column_path = columns_dir + "user.groonga"
115
+ @user_column =
116
+ @bookmarks.define_column("user", @users,
117
+ :path => @user_column_path.to_s)
118
+
119
+ define_timestamp(@bookmarks, columns_dir)
120
+ end
121
+
122
+ def define_timestamp(table, columns_dir)
123
+ created_at_column_path = columns_dir + "created_at.groonga"
124
+ table.define_column("created_at", "<time>",
125
+ :path => created_at_column_path.to_s)
126
+
127
+ updated_at_column_path = columns_dir + "updated_at.groonga"
128
+ table.define_column("updated_at", "<time>",
129
+ :path => updated_at_column_path.to_s)
130
+ end
131
+
132
+ def setup_bookmarks_index_tables
133
+ @index = @context["<metadata:index>"]
134
+
135
+ setup_bookmarks_content_index_table
136
+ end
137
+
138
+ def setup_bookmarks_content_index_table
139
+ bookmarks_index_dir = @metadata_dir + "index" + "bookmarks"
140
+ bookmarks_index_dir.mkpath
141
+
142
+ @bookmarks_content_index_column_path =
143
+ bookmarks_index_dir + "content.groonga"
144
+ path = @bookmarks_content_index_column_path.to_s
145
+ @bookmarks_content_index_column =
146
+ @index.define_column("bookmarks/content", @bookmarks,
147
+ :type => "index",
148
+ :with_section => true,
149
+ :with_weight => true,
150
+ :with_position => true,
151
+ :path => path)
152
+ @bookmarks_content_index_column.source = @content_column
153
+
154
+ record = ActiveGroonga::Schema.index_management_table.add
155
+ record["table"] = @bookmarks.name
156
+ record["column"] = "content"
157
+ record["index"] = @index.name
158
+ end
159
+
160
+ def setup_tasks_table
161
+ @tasks_path = @tables_dir + "tasks.groonga"
162
+ @tasks = Groonga::Array.create(:name => "<table:tasks>",
163
+ :path => @tasks_path.to_s)
164
+
165
+ columns_dir = @tables_dir + "tasks" + "columns"
166
+ columns_dir.mkpath
167
+
168
+ @name_column_path = columns_dir + "name.groonga"
169
+ @name_column = @tasks.define_column("name", "<shorttext>",
170
+ :path => @name_column_path.to_s)
171
+ end
172
+
173
+ def setup_user_records
174
+ @user_records = {}
175
+
176
+ @user_records[:daijiro] = create_user("daijiro")
177
+ @user_records[:gunyarakun] = create_user("gunyarakun")
178
+ end
179
+
180
+ def setup_bookmark_records
181
+ @bookmark_records = {}
182
+
183
+ @bookmark_records[:groonga] =
184
+ create_bookmark(@user_records[:daijiro],
185
+ "http://groonga.org/",
186
+ "fulltext search engine",
187
+ "<html><body>groonga</body></html>")
188
+
189
+ @bookmark_records[:cutter] =
190
+ create_bookmark(@user_records[:gunyarakun],
191
+ "http://cutter.sourceforge.net/",
192
+ "a unit testing framework for C",
193
+ "<html><body>Cutter</body></html>")
194
+ end
195
+
196
+ def setup_class
197
+ base_dir = Pathname(__FILE__).parent + "fixtures"
198
+ Object.class_eval do
199
+ remove_const(:User) if const_defined?(:User)
200
+ remove_const(:Bookmark) if const_defined?(:Bookmark)
201
+ remove_const(:Task) if const_defined?(:Task)
202
+ end
203
+ load((base_dir + 'user.rb').to_s)
204
+ load((base_dir + 'bookmark.rb').to_s)
205
+ load((base_dir + 'task.rb').to_s)
206
+ end
207
+
208
+ def teardown_sand_box
209
+ teardown_tmp_directory
210
+ end
211
+
212
+ def teardown_tmp_directory
213
+ FileUtils.rm_rf(@tmp_dir.to_s)
214
+ end
215
+
216
+ private
217
+ def create_user(name)
218
+ user = @users.add
219
+ user["name"] = name
220
+ user
221
+ end
222
+
223
+ def create_bookmark(user, uri, comment, content)
224
+ bookmark = @bookmarks.add
225
+ bookmark["uri"] = uri
226
+ bookmark["user"] = user
227
+ bookmark["comment"] = comment
228
+ bookmark["content"] = content
229
+ bookmark["created_at"] = Time.parse("2009-02-09 02:09:29")
230
+ bookmark["updated_at"] = Time.parse("2009-02-09 02:29:00")
231
+
232
+ bookmark
233
+ end
234
+ end
@@ -0,0 +1,2 @@
1
+ class Bookmark < ActiveGroonga::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Task < ActiveGroonga::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveGroonga::Base
2
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ # $VERBOSE = true
19
+
20
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
21
+ test_unit_dir = File.join(base_dir, "test-unit", "lib")
22
+ ruby_groonga_dir = File.expand_path(File.join(base_dir, "..", "groonga"))
23
+ lib_dir = File.join(base_dir, "lib")
24
+ test_dir = File.join(base_dir, "test")
25
+
26
+ if File.exist?(ruby_groonga_dir)
27
+ make = nil
28
+ if system("which gmake > /dev/null")
29
+ make = "gmake"
30
+ elsif system("which make > /dev/null")
31
+ make = "make"
32
+ end
33
+ if make
34
+ system("cd #{ruby_groonga_dir.dump} && #{make} > /dev/null") or exit(1)
35
+ end
36
+ end
37
+
38
+ $LOAD_PATH.unshift(test_unit_dir)
39
+
40
+ require 'test/unit'
41
+
42
+ $LOAD_PATH.unshift(lib_dir)
43
+
44
+ $LOAD_PATH.unshift(test_dir)
45
+ require 'active-groonga-test-utils'
46
+
47
+ Dir.glob("test/**/test{_,-}*.rb") do |file|
48
+ require file.sub(/\.rb$/, '')
49
+ end
50
+
51
+ exit Test::Unit::AutoRunner.run(false)
@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
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.
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
+ class TestAssociations < Test::Unit::TestCase
18
+ include ActiveGroongaTestUtils
19
+
20
+ def test_belongs_to
21
+ groonga = Bookmark.find_by_uri("http://groonga.org/")
22
+ assert_equal(User.find_by_name("daijiro"), groonga.user)
23
+ end
24
+ end
data/test/test-base.rb ADDED
@@ -0,0 +1,194 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
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.
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
+ class BaseTest < Test::Unit::TestCase
18
+ include ActiveGroongaTestUtils
19
+
20
+ def test_find
21
+ bookmarks = Bookmark.find(:all)
22
+ assert_equal(["http://groonga.org/", "http://cutter.sourceforge.net/"].sort,
23
+ bookmarks.collect(&:uri).sort)
24
+ end
25
+
26
+ def test_find_by_id
27
+ groonga = Bookmark.find(@bookmark_records[:groonga].id)
28
+ assert_equal("http://groonga.org/", groonga.uri)
29
+ end
30
+
31
+ def test_find_by_attribute
32
+ daijiro = User.find_by_name("daijiro")
33
+ assert_equal("daijiro", daijiro.name)
34
+ end
35
+
36
+ def test_create
37
+ assert_predicate(Task.count, :zero?)
38
+ send_mail = Task.new
39
+ send_mail.name = "send mails"
40
+ assert_nil(send_mail.id)
41
+ assert_true(send_mail.save)
42
+ assert_not_nil(send_mail.id)
43
+
44
+ reloaded_send_mail = Task.find(send_mail.id)
45
+ assert_equal("send mails", send_mail.name)
46
+ end
47
+
48
+ def test_update
49
+ groonga_id = @bookmark_records[:groonga].id
50
+ groonga = Bookmark.find(groonga_id)
51
+ groonga.comment = "a search engine"
52
+ assert_equal(groonga_id, groonga.id)
53
+ groonga.save
54
+ assert_not_nil(groonga_id, groonga.id)
55
+
56
+ reloaded_groonga = Bookmark.find(groonga.id)
57
+ assert_equal("a search engine", reloaded_groonga.comment)
58
+ end
59
+
60
+ def test_mass_assignments
61
+ google = Bookmark.new
62
+ google.attributes = {
63
+ "uri" => "http://google.com/",
64
+ "comment" => "a search engine"
65
+ }
66
+ assert_true(google.save)
67
+
68
+ reloaded_google = Bookmark.find(google.id)
69
+ assert_equal({
70
+ "uri" => "http://google.com/",
71
+ "comment" => "a search engine",
72
+ "content" => nil,
73
+ "user" => nil,
74
+ "created_at" => google.created_at,
75
+ "updated_at" => google.updated_at,
76
+ },
77
+ reloaded_google.attributes)
78
+ end
79
+
80
+ def test_mass_updates
81
+ groonga = Bookmark.find_by_uri("http://groonga.org/")
82
+ groonga.update_attributes({
83
+ "uri" => "http://google.com/",
84
+ "comment" => "a search engine",
85
+ })
86
+
87
+ google = Bookmark.find(groonga.id)
88
+ assert_equal({
89
+ "uri" => "http://google.com/",
90
+ "comment" => "a search engine",
91
+ "content" => groonga.content,
92
+ "user" => groonga.user,
93
+ "created_at" => groonga.created_at,
94
+ "updated_at" => groonga.updated_at,
95
+ },
96
+ google.attributes)
97
+ end
98
+
99
+ def test_destroy
100
+ before_count = Bookmark.count
101
+ Bookmark.find_by_uri("http://groonga.org/").destroy
102
+ assert_equal(before_count - 1, Bookmark.count)
103
+ end
104
+
105
+ def test_inspect
106
+ assert_equal("Bookmark(user: references, uri: string, " +
107
+ "updated_at: time, created_at: time, " +
108
+ "content: text, comment: text)",
109
+ Bookmark.inspect)
110
+
111
+ daijiro = User.find_by_name("daijiro")
112
+ groonga = Bookmark.find_by_uri("http://groonga.org/")
113
+ assert_equal("#<Bookmark user: #{daijiro.inspect}, " +
114
+ "uri: \"http://groonga.org/\", " +
115
+ "updated_at: \"2009-02-09 02:29:00\", " +
116
+ "created_at: \"2009-02-09 02:09:29\", " +
117
+ "content: \"<html><body>groonga</body></html>\", " +
118
+ "comment: \"fulltext search engine\">",
119
+ groonga.inspect)
120
+ end
121
+
122
+ def test_update_inverted_index
123
+ google = Bookmark.new
124
+ google.attributes = {
125
+ "uri" => "http://google.com/",
126
+ "comment" => "a search engine",
127
+ "content" => "<html><body>...Google...</body></html>",
128
+ }
129
+ google.save!
130
+
131
+ bookmarks = Bookmark.find_all_by_content("Google")
132
+ assert_equal([google], bookmarks)
133
+
134
+ google.content = "<html><body>...Empty...</body></html>"
135
+ google.save!
136
+
137
+ bookmarks = Bookmark.find_all_by_content("Google")
138
+ assert_equal([], bookmarks)
139
+
140
+ bookmarks = Bookmark.find_all_by_content("Empty")
141
+ assert_equal([google], bookmarks)
142
+ end
143
+
144
+ def test_update_index
145
+ daijiro = @user_records[:daijiro]
146
+ google = Bookmark.new
147
+ google.attributes = {
148
+ "uri" => "http://google.com/",
149
+ "user" => User.find(daijiro.id),
150
+ }
151
+ google.save!
152
+
153
+ bookmarks = Bookmark.find_all_by_user(daijiro)
154
+ assert_equal([Bookmark.find(@bookmark_records[:groonga].id), google],
155
+ bookmarks)
156
+ end
157
+
158
+ def test_find_reference_by_id
159
+ daijiro = @user_records[:daijiro]
160
+ bookmarks = Bookmark.find_all_by_user(daijiro.id)
161
+ assert_equal([Bookmark.find(@bookmark_records[:groonga])],
162
+ bookmarks)
163
+ end
164
+
165
+ def test_create
166
+ google = Bookmark.create("uri" => "http://google.com/",
167
+ "comment" => "a search engine",
168
+ "content" => "<html><body>...Google...</body></html>")
169
+
170
+
171
+ assert_equal([google], Bookmark.find_all_by_content("Google"))
172
+ end
173
+
174
+ def test_find_by_model
175
+ google = Bookmark.create("uri" => "http://google.com/",
176
+ "comment" => "a search engine")
177
+ assert_equal(google, Bookmark.find(google))
178
+ end
179
+
180
+ def test_timestamp
181
+ google = Bookmark.create("uri" => "http://google.com/",
182
+ "comment" => "a search engine")
183
+ assert_not_equal(Time.at(0), google.created_at)
184
+ assert_not_equal(Time.at(0), google.updated_at)
185
+ end
186
+
187
+ def test_reload
188
+ groonga = Bookmark.find_by_uri("http://groonga.org/")
189
+ groonga.comment = "changed!"
190
+ assert_equal("changed!", groonga.comment)
191
+ groonga.reload
192
+ assert_equal("fulltext search engine", groonga.comment)
193
+ end
194
+ end