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
@@ -0,0 +1,2 @@
1
+ class Site < ActiveGroonga::Base
2
+ end
data/test/run-test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,13 +17,30 @@
17
17
 
18
18
  # $VERBOSE = true
19
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")
20
+ require 'pathname'
21
+ require 'shellwords'
25
22
 
26
- if File.exist?(ruby_groonga_dir)
23
+ base_dir = Pathname(__FILE__).dirname.parent.expand_path
24
+ test_unit_dir = base_dir + "test-unit"
25
+ test_unit_notify_dir = base_dir + "test-unit-notify"
26
+ test_unit_repository_base = "http://test-unit.rubyforge.org/svn"
27
+ unless test_unit_dir.exist?
28
+ system("svn", "co", "#{test_unit_repository_base}/trunk",
29
+ test_unit_dir.to_s)
30
+ end
31
+ unless test_unit_notify_dir.exist?
32
+ test_unit_notify_repository = "#{test_unit_repository_base}/extensions/test-unit-notify/trunk/"
33
+ system("svn", "co",
34
+ test_unit_notify_repository.to_s,
35
+ test_unit_notify_dir.to_s) or exit(false)
36
+ system("svn", "up", test_unit_dir.to_s) or exit(false)
37
+ end
38
+
39
+ rroonga_dir = base_dir.parent + "rroonga"
40
+ lib_dir = base_dir + "lib"
41
+ test_dir = base_dir + "test"
42
+
43
+ if rroonga_dir.exist?
27
44
  make = nil
28
45
  if system("which gmake > /dev/null")
29
46
  make = "gmake"
@@ -31,13 +48,23 @@ if File.exist?(ruby_groonga_dir)
31
48
  make = "make"
32
49
  end
33
50
  if make
34
- system("cd #{ruby_groonga_dir.dump} && #{make} > /dev/null") or exit(1)
51
+ escaped_rroonga_dir = Shellwords.escape(rroonga_dir.to_s)
52
+ system("cd #{escaped_rroonga_dir} && #{make} > /dev/null") or exit(false)
35
53
  end
54
+ $LOAD_PATH.unshift(rroonga_dir + "ext" + "groonga")
55
+ $LOAD_PATH.unshift(rroonga_dir + "lib")
36
56
  end
37
57
 
38
- $LOAD_PATH.unshift(test_unit_dir)
58
+ $LOAD_PATH.unshift(test_unit_notify_dir + "lib")
59
+ $LOAD_PATH.unshift(test_unit_dir + "lib")
60
+
61
+ ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] = "10000"
39
62
 
40
63
  require 'test/unit'
64
+ require 'test/unit/notify'
65
+
66
+ ARGV.unshift("--priority-mode")
67
+ ARGV.unshift("--notify")
41
68
 
42
69
  $LOAD_PATH.unshift(lib_dir)
43
70
 
@@ -18,7 +18,10 @@ class TestAssociations < Test::Unit::TestCase
18
18
  include ActiveGroongaTestUtils
19
19
 
20
20
  def test_belongs_to
21
- groonga = Bookmark.find_by_uri("http://groonga.org/")
22
- assert_equal(User.find_by_name("daijiro"), groonga.user)
21
+ groonga = Bookmark.select do |record|
22
+ record.uri == "http://groonga.org/"
23
+ end.first
24
+ assert_equal(User.select {|record| record.name == "daijiro"}.first,
25
+ groonga.user)
23
26
  end
24
27
  end
data/test/test-base.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
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
@@ -17,19 +17,19 @@
17
17
  class TestBase < Test::Unit::TestCase
18
18
  include ActiveGroongaTestUtils
19
19
 
20
- def test_find
21
- bookmarks = Bookmark.find(:all)
20
+ def test_select
21
+ bookmarks = Bookmark.select
22
22
  assert_equal(["http://groonga.org/", "http://cutter.sourceforge.net/"].sort,
23
23
  bookmarks.collect(&:uri).sort)
24
24
  end
25
25
 
26
- def test_find_by_id
26
+ def test_find
27
27
  groonga = Bookmark.find(@bookmark_records[:groonga].id)
28
28
  assert_equal("http://groonga.org/", groonga.uri)
29
29
  end
30
30
 
31
- def test_find_by_attribute
32
- daijiro = User.find_by_name("daijiro")
31
+ def test_select_by_attribute
32
+ daijiro = User.select {|record| record.name == "daijiro"}.first
33
33
  assert_equal("daijiro", daijiro.name)
34
34
  end
35
35
 
@@ -78,11 +78,14 @@ class TestBase < Test::Unit::TestCase
78
78
  end
79
79
 
80
80
  def test_mass_updates
81
- groonga = Bookmark.find_by_uri("http://groonga.org/")
81
+ groonga = Bookmark.select do |record|
82
+ record.uri == "http://groonga.org/"
83
+ end.first
82
84
  groonga.update_attributes({
83
85
  "uri" => "http://google.com/",
84
86
  "comment" => "a search engine",
85
87
  })
88
+ groonga.reload
86
89
 
87
90
  google = Bookmark.find(groonga.id)
88
91
  assert_equal({
@@ -98,22 +101,24 @@ class TestBase < Test::Unit::TestCase
98
101
 
99
102
  def test_destroy
100
103
  before_count = Bookmark.count
101
- Bookmark.find_by_uri("http://groonga.org/").destroy
104
+ Bookmark.select {|record| record.uri == "http://groonga.org/"}.first.destroy
102
105
  assert_equal(before_count - 1, Bookmark.count)
103
106
  end
104
107
 
105
108
  def test_inspect
106
- assert_equal("Bookmark(user: references, uri: string, " +
107
- "updated_at: time, created_at: time, " +
108
- "content: text, comment: text)",
109
+ assert_equal("Bookmark(user: users, uri: ShortText, " +
110
+ "updated_at: Time, created_at: Time, " +
111
+ "content: LongText, comment: Text)",
109
112
  Bookmark.inspect)
110
113
 
111
- daijiro = User.find_by_name("daijiro")
112
- groonga = Bookmark.find_by_uri("http://groonga.org/")
113
- assert_equal("#<Bookmark user: #{daijiro.inspect}, " +
114
+ daijiro = User.select {|record| record.name == "daijiro"}.first
115
+ groonga = Bookmark.select {|record| record.uri == "http://groonga.org/"}.first
116
+ assert_equal("#<Bookmark " +
117
+ "id: #{groonga.id}, " +
118
+ "user: #{daijiro.inspect}, " +
114
119
  "uri: \"http://groonga.org/\", " +
115
- "updated_at: \"2009-02-09 02:29:00\", " +
116
- "created_at: \"2009-02-09 02:09:29\", " +
120
+ "updated_at: 2009-02-09 02:29:00 +0900, " +
121
+ "created_at: 2009-02-09 02:09:29 +0900, " +
117
122
  "content: \"<html><body>groonga</body></html>\", " +
118
123
  "comment: \"fulltext search engine\">",
119
124
  groonga.inspect)
@@ -128,17 +133,17 @@ class TestBase < Test::Unit::TestCase
128
133
  }
129
134
  google.save!
130
135
 
131
- bookmarks = Bookmark.find(:all) {|record| record["content"] =~ "Google"}
132
- assert_equal([google], bookmarks)
136
+ bookmarks = Bookmark.select {|record| record["content"] =~ "Google"}
137
+ assert_equal([google], bookmarks.to_a)
133
138
 
134
139
  google.content = "<html><body>...Empty...</body></html>"
135
140
  google.save!
136
141
 
137
- bookmarks = Bookmark.find(:all) {|record| record["content"] =~ "Google"}
138
- assert_equal([], bookmarks)
142
+ bookmarks = Bookmark.select {|record| record["content"] =~ "Google"}
143
+ assert_equal([], bookmarks.to_a)
139
144
 
140
- bookmarks = Bookmark.find(:all) {|record| record["content"] =~ "Empty"}
141
- assert_equal([google], bookmarks)
145
+ bookmarks = Bookmark.select {|record| record["content"] =~ "Empty"}
146
+ assert_equal([google], bookmarks.to_a)
142
147
  end
143
148
 
144
149
  def test_update_index
@@ -150,25 +155,27 @@ class TestBase < Test::Unit::TestCase
150
155
  }
151
156
  google.save!
152
157
 
153
- bookmarks = Bookmark.find_all_by_user(daijiro)
158
+ bookmarks = Bookmark.select do |record|
159
+ record.user == daijiro
160
+ end
154
161
  assert_equal([Bookmark.find(@bookmark_records[:groonga].id), google],
155
- bookmarks)
162
+ bookmarks.to_a)
156
163
  end
157
164
 
158
165
  def test_find_reference_by_id
159
166
  daijiro = @user_records[:daijiro]
160
- bookmarks = Bookmark.find_all_by_user(daijiro.id)
167
+ bookmarks = Bookmark.select {|record| record.user == daijiro}
161
168
  assert_equal([Bookmark.find(@bookmark_records[:groonga])],
162
- bookmarks)
169
+ bookmarks.to_a)
163
170
  end
164
171
 
165
- def test_create
172
+ def test_find_all_with_block
166
173
  google = Bookmark.create("uri" => "http://google.com/",
167
174
  "comment" => "a search engine",
168
175
  "content" => "<html><body>...Google...</body></html>")
169
176
 
170
177
  assert_equal([google],
171
- Bookmark.find(:all) {|record| record["content"] =~ "Google"})
178
+ Bookmark.select {|record| record["content"] =~ "Google"}.to_a)
172
179
  end
173
180
 
174
181
  def test_find_by_model
@@ -181,11 +188,12 @@ class TestBase < Test::Unit::TestCase
181
188
  google = Bookmark.create("uri" => "http://google.com/",
182
189
  "comment" => "a search engine")
183
190
  assert_not_equal(Time.at(0), google.created_at)
184
- assert_not_equal(Time.at(0), google.updated_at)
191
+ assert_equal(Time.at(0), google.updated_at)
185
192
  end
186
193
 
187
194
  def test_reload
188
- groonga = Bookmark.find_by_uri("http://groonga.org/")
195
+ records = Bookmark.select {|record| record.uri == "http://groonga.org/"}
196
+ groonga = records.first
189
197
  groonga.comment = "changed!"
190
198
  assert_equal("changed!", groonga.comment)
191
199
  groonga.reload
@@ -199,6 +207,6 @@ class TestBase < Test::Unit::TestCase
199
207
 
200
208
 
201
209
  assert_equal([google],
202
- Bookmark.find(:all) {|record| record.content =~ "Google"})
210
+ Bookmark.select {|record| record.content =~ "Google"}.to_a)
203
211
  end
204
212
  end
@@ -18,10 +18,20 @@ class TestCallbacks < Test::Unit::TestCase
18
18
  include ActiveGroongaTestUtils
19
19
 
20
20
  def test_before_save
21
- bookmark = Bookmark.new
22
- def bookmark.before_save
23
- @called = true
21
+ callbacked_bookmark_class = Class.new(Bookmark) do
22
+ class << self
23
+ def model_name
24
+ Bookmark.model_name
25
+ end
26
+ end
27
+
28
+ set_callback :save, :before, :before_save
29
+
30
+ def before_save
31
+ @called = true
32
+ end
24
33
  end
34
+ bookmark = callbacked_bookmark_class.new
25
35
  bookmark.instance_variable_set("@called", false)
26
36
  assert_equal(false, bookmark.instance_variable_get("@called"))
27
37
  bookmark.save
@@ -0,0 +1,53 @@
1
+ # Copyright (C) 2010 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 TestPersistence < Test::Unit::TestCase
18
+ include ActiveGroongaTestUtils
19
+
20
+ def test_save_hash
21
+ key = "http://groonga.org/"
22
+ title = "groonga"
23
+
24
+ site = Site.new
25
+ site.key = key
26
+ site.title = title
27
+ assert_true(site.save)
28
+ found_site = Site.find(key)
29
+ assert_equal([key, title],
30
+ [found_site.key, found_site.title])
31
+ end
32
+
33
+ def test_create_hash
34
+ groonga = Site.create(:key => "http://groonga.org/",
35
+ :title => "groonga")
36
+ found_groonga = Site.find("http://groonga.org/")
37
+ assert_equal(["http://groonga.org/", "groonga"],
38
+ [found_groonga.key, found_groonga.title])
39
+ end
40
+
41
+ def test_update
42
+ groonga = Site.new
43
+ groonga.key = "http://groonga.org/"
44
+ assert_true(groonga.save)
45
+
46
+ groonga.title = "groonga"
47
+ assert_true(groonga.save)
48
+
49
+ reloaded_groonga = Site.find("http://groonga.org/")
50
+ assert_equal(["http://groonga.org/", "groonga"],
51
+ [reloaded_groonga.key, reloaded_groonga.title])
52
+ end
53
+ end
@@ -1,8 +1,9 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
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 version 2.1 as published by the Free Software Foundation.
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License.
6
7
  #
7
8
  # This library is distributed in the hope that it will be useful,
8
9
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,17 +14,18 @@
13
14
  # License along with this library; if not, write to the Free Software
14
15
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
16
 
16
- module ActiveGroonga
17
- module Observing
18
- class << self
19
- def included(base)
20
- base.class_eval do
21
- include ActiveRecord::Observing
22
- end
23
- end
24
- end
17
+ class TestResultSet < Test::Unit::TestCase
18
+ include ActiveGroongaTestUtils
19
+
20
+ def test_paginate
21
+ bookmarks = Bookmark.select
22
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
23
+ bookmarks.paginate(["uri"], :size => 1).collect(&:uri))
25
24
  end
26
25
 
27
- class Observer < ActiveRecord::Observer
26
+ def test_sort
27
+ bookmarks = Bookmark.select
28
+ assert_equal(["http://cutter.sourceforge.net/"].sort,
29
+ bookmarks.sort(["uri"], :limit => 1).collect(&:uri))
28
30
  end
29
31
  end
data/test/test-schema.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
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
@@ -18,60 +18,123 @@ class TestSchema < Test::Unit::TestCase
18
18
  include ActiveGroongaTestUtils
19
19
 
20
20
  def test_create_table
21
- table_file = @tables_dir + "posts.groonga"
21
+ table_file = @tables_dir + "posts"
22
22
  assert_not_predicate(table_file, :exist?)
23
- ActiveGroonga::Schema.create_table(:posts) do |table|
23
+ ActiveGroonga::Schema.define do |schema|
24
+ schema.create_table(:posts) do |table|
25
+ end
24
26
  end
25
27
  assert_predicate(table_file, :exist?)
26
28
  end
27
29
 
28
30
  def test_string_column
29
- column_file = @tables_dir + "posts" + "columns" + "title.groonga"
31
+ column_file = @tables_dir + "posts.columns" + "title"
30
32
  assert_not_predicate(column_file, :exist?)
31
- ActiveGroonga::Schema.create_table(:posts) do |table|
32
- table.string :title
33
+ ActiveGroonga::Schema.define do |schema|
34
+ schema.create_table(:posts) do |table|
35
+ table.string :title
36
+ end
33
37
  end
34
38
  assert_predicate(column_file, :exist?)
35
39
  end
36
40
 
37
41
  def test_reference_column
38
- ActiveGroonga::Schema.create_table(:categories) do |table|
39
- table.string :name
42
+ ActiveGroonga::Schema.define do |schema|
43
+ schema.create_table(:categories) do |table|
44
+ table.string(:name)
45
+ end
40
46
  end
41
47
 
42
- column_file = @tables_dir + "posts" + "columns" + "category.groonga"
48
+ column_file = @tables_dir + "posts.columns" + "category"
43
49
  assert_not_predicate(column_file, :exist?)
44
- ActiveGroonga::Schema.create_table(:posts) do |table|
45
- table.reference :category
50
+ ActiveGroonga::Schema.define do |schema|
51
+ schema.create_table(:posts) do |table|
52
+ table.reference(:category)
53
+ end
46
54
  end
47
55
  assert_predicate(column_file, :exist?)
48
56
  end
49
57
 
50
58
  def test_add_index
51
- columns_dir = @tables_dir + "words" + "columns" + "posts"
52
- index_file = columns_dir + "posts_content.groonga"
59
+ columns_dir = @tables_dir + "words.columns"
60
+ index_file = columns_dir + "posts_content"
53
61
  assert_not_predicate(index_file, :exist?)
54
62
 
55
- ActiveGroonga::Schema.create_table(:posts) do |table|
56
- table.string :content
57
- end
63
+ ActiveGroonga::Schema.define do |schema|
64
+ schema.create_table(:posts) do |table|
65
+ table.string(:content)
66
+ end
58
67
 
59
- ActiveGroonga::Schema.create_table(:words) do |table|
60
- table.index :posts, :content
68
+ schema.create_table(:words) do |table|
69
+ table.index(:posts, :content)
70
+ end
61
71
  end
62
72
 
63
73
  assert_predicate(index_file, :exist?)
64
74
  end
65
75
 
66
76
  def test_remove_column
67
- column_file = @tables_dir + "posts" + "columns" + "title.groonga"
77
+ column_file = @tables_dir + "posts.columns" + "title"
68
78
  assert_not_predicate(column_file, :exist?)
69
- ActiveGroonga::Schema.create_table(:posts) do |table|
70
- table.string :title
79
+ ActiveGroonga::Schema.define do |schema|
80
+ schema.create_table(:posts) do |table|
81
+ table.string(:title)
82
+ end
71
83
  end
72
84
  assert_predicate(column_file, :exist?)
73
85
 
74
- ActiveGroonga::Schema.remove_column(:posts, :title)
86
+ ActiveGroonga::Schema.define do |schema|
87
+ schema.remove_column(:posts, :title)
88
+ end
75
89
  assert_not_predicate(column_file, :exist?)
76
90
  end
91
+
92
+ def test_dump
93
+ assert_equal(<<-EOS, ActiveGroonga::Schema.dump)
94
+ ActiveGroonga::Schema.define(:version => 0) do |schema|
95
+ schema.instance_eval do
96
+ create_table("bookmarks",
97
+ :force => true) do |table|
98
+ table.text("comment")
99
+ table.long_text("content")
100
+ table.time("created_at")
101
+ table.time("updated_at")
102
+ table.short_text("uri")
103
+ end
104
+
105
+ create_table("sites",
106
+ :type => :hash,
107
+ :key_type => "ShortText",
108
+ :force => true) do |table|
109
+ table.unsigned_integer32("score")
110
+ table.short_text("title")
111
+ end
112
+
113
+ create_table("tasks",
114
+ :force => true) do |table|
115
+ table.short_text("name")
116
+ end
117
+
118
+ create_table("terms",
119
+ :type => :patricia_trie,
120
+ :key_type => "ShortText",
121
+ :force => true) do |table|
122
+ end
123
+
124
+ create_table("users",
125
+ :force => true) do |table|
126
+ table.short_text("name")
127
+ end
128
+
129
+ change_table("bookmarks") do |table|
130
+ table.reference("user", "users")
131
+ end
132
+
133
+ change_table("terms") do |table|
134
+ table.index("bookmarks", "content", :name => "bookmarks_content")
135
+ end
136
+ end
137
+ end
138
+ EOS
139
+ end
77
140
  end