test/test-schema.rb in groonga-0.0.5 vs test/test-schema.rb in groonga-0.0.6
- old
+ new
@@ -23,33 +23,53 @@
Groonga::Schema.create_table("<posts>") do |table|
end
assert_not_nil(context["<posts>"])
end
+ def test_create_table_force
+ Groonga::Schema.create_table("posts") do |table|
+ end
+ assert_raise(Groonga::InvalidArgument) do
+ Groonga::Schema.create_table("posts") do |table|
+ end
+ end
+ Groonga::Schema.create_table("posts", :force => true) do |table|
+ end
+ end
+
+ def test_remove_table
+ Groonga::Array.create(:name => "posts")
+ assert_not_nil(context["posts"])
+ Groonga::Schema.remove_table("posts")
+ assert_nil(context["posts"])
+ end
+
def test_define_hash
Groonga::Schema.create_table("<posts>", :type => :hash) do |table|
end
assert_kind_of(Groonga::Hash, context["<posts>"])
end
def test_define_hash_with_full_option
path = @tmp_dir + "hash.groonga"
tokenizer = context["<token:trigram>"]
+ type = Groonga::Type.new("Niku", :size => 29)
Groonga::Schema.create_table("<posts>",
:type => :hash,
:key_type => "integer",
:path => path.to_s,
- :value_size => 29,
+ :value_type => type,
:default_tokenizer => tokenizer) do |table|
end
table = context["<posts>"]
assert_equal("#<Groonga::Hash " +
"id: <#{table.id}>, " +
"name: <<posts>>, " +
"path: <#{path}>, " +
"domain: <#{context['<int>'].inspect}>, " +
- "range: <nil>, " +
+ "range: <#{type.inspect}>, " +
+ "flags: <>, " +
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
"size: <0>>",
table.inspect)
assert_equal(tokenizer, table.default_tokenizer)
end
@@ -60,26 +80,28 @@
assert_kind_of(Groonga::PatriciaTrie, context["<posts>"])
end
def test_define_patricia_trie_with_full_option
path = @tmp_dir + "patricia-trie.groonga"
+ type = Groonga::Type.new("Niku", :size => 29)
Groonga::Schema.create_table("<posts>",
:type => :patricia_trie,
:key_type => "integer",
:path => path.to_s,
- :value_size => 29,
+ :value_type => type,
:default_tokenizer => "<token:bigram>",
:key_normalize => true,
:key_with_sis => true) do |table|
end
table = context["<posts>"]
assert_equal("#<Groonga::PatriciaTrie " +
"id: <#{table.id}>, " +
"name: <<posts>>, " +
"path: <#{path}>, " +
"domain: <#{context['<int>'].inspect}>, " +
- "range: <nil>, " +
+ "range: <#{type.inspect}>, " +
+ "flags: <KEY_WITH_SIS|KEY_NORMALIZE|WITH_SECTION>, " +
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
"size: <0>>",
table.inspect)
assert_equal(context["<token:bigram>"], table.default_tokenizer)
end
@@ -90,22 +112,24 @@
assert_kind_of(Groonga::Array, context["<posts>"])
end
def test_define_array_with_full_option
path = @tmp_dir + "array.groonga"
+ type = Groonga::Type.new("Niku", :size => 29)
Groonga::Schema.create_table("<posts>",
:type => :array,
:path => path.to_s,
- :value_size => 29) do |table|
+ :value_type => type) do |table|
end
table = context["<posts>"]
assert_equal("#<Groonga::Array " +
"id: <#{table.id}>, " +
"name: <<posts>>, " +
"path: <#{path}>, " +
"domain: <nil>, " +
- "range: <nil>, " +
+ "range: <#{type.inspect}>, " +
+ "flags: <>, " +
"size: <0>>",
table.inspect)
end
def test_integer32_column
@@ -178,30 +202,81 @@
table.long_text :content
end
assert_equal(context["<longtext>"], context["<posts>.content"].range)
end
+ def test_remove_column
+ Groonga::Schema.create_table("posts") do |table|
+ table.long_text :content
+ end
+ assert_not_nil(context["posts.content"])
+
+ Groonga::Schema.change_table("posts") do |table|
+ table.remove_column("content")
+ end
+ assert_nil(context["posts.content"])
+ end
+
def test_index
assert_nil(context["<terms>.content"])
Groonga::Schema.create_table("<posts>") do |table|
table.long_text :content
end
Groonga::Schema.create_table("<terms>") do |table|
- table.index :posts_content, "<posts>.content"
+ table.index "<posts>.content"
end
assert_equal([context["<posts>.content"]],
- context["<terms>.posts_content"].sources)
+ context["<terms>.<posts>_content"].sources)
end
def test_dump
Groonga::Schema.define do |schema|
- schema.create_table("<posts>") do |table|
+ schema.create_table("posts") do |table|
table.short_text :title
end
end
assert_equal(<<-EOS, Groonga::Schema.dump)
-create_table("<posts>") do |table|
+create_table("posts") do |table|
table.short_text("title")
+end
+EOS
+ end
+
+ def test_reference_dump
+ Groonga::Schema.define do |schema|
+ schema.create_table("items") do |table|
+ table.short_text("title")
+ end
+
+ schema.create_table("users") do |table|
+ table.short_text("name")
+ end
+
+ schema.create_table("comments") do |table|
+ table.reference("item", "items")
+ table.reference("author", "users")
+ table.text("content")
+ table.time("issued")
+ end
+ end
+
+ assert_equal(<<-EOS, Groonga::Schema.dump)
+create_table("comments") do |table|
+ table.text("content")
+ table.time("issued")
+end
+
+create_table("items") do |table|
+ table.short_text("title")
+end
+
+create_table("users") do |table|
+ table.short_text("name")
+end
+
+change_table("comments") do |table|
+ table.reference("author", "users")
+ table.reference("item", "items")
end
EOS
end
end