[Groonga-commit] ranguba/groonga-client-model at dd0597d [master] Add some column migration tests

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Fri Mar 3 09:06:41 JST 2017


Kouhei Sutou	2017-03-03 09:06:41 +0900 (Fri, 03 Mar 2017)

  New Revision: dd0597d26146972f0ebf8a005cb8da6983e788fe
  https://github.com/ranguba/groonga-client-model/commit/dd0597d26146972f0ebf8a005cb8da6983e788fe

  Message:
    Add some column migration tests

  Modified files:
    lib/groonga_client_model/migration.rb
    test/unit/test_migration.rb

  Modified: lib/groonga_client_model/migration.rb (+4 -0)
===================================================================
--- lib/groonga_client_model/migration.rb    2017-03-03 08:54:53 +0900 (bf99578)
+++ lib/groonga_client_model/migration.rb    2017-03-03 09:06:41 +0900 (20a4262)
@@ -219,6 +219,10 @@ module GroongaClientModel
       def text(column_name, options={})
         @migration.add_column(@table_name, column_name, :text, options)
       end
+
+      def long_text(column_name, options={})
+        @migration.add_column(@table_name, column_name, :long_text, options)
+      end
     end
   end
 end

  Modified: test/unit/test_migration.rb (+122 -15)
===================================================================
--- test/unit/test_migration.rb    2017-03-03 08:54:53 +0900 (d585066)
+++ test/unit/test_migration.rb    2017-03-03 09:06:41 +0900 (1482732)
@@ -25,45 +25,152 @@ class TestMigration < Test::Unit::TestCase
     GroongaClientModel::Client.open(&block)
   end
 
-  def migrate(direction)
+  def normalize_report(report)
+    report.gsub(/[0-9]+\.[0-9]+s/, "0.0s")
+  end
+
+  def dump
+    open_client do |client|
+      client.dump.body
+    end
+  end
+
+  def assert_migrate(expected_up_report,
+                     expected_down_report,
+                     expected_dump)
     migration_class = Class.new(GroongaClientModel::Migration) do |klass|
       define_method(:change) do
         yield(self)
       end
     end
-    output = StringIO.new
+
+    up_output = StringIO.new
     open_client do |client|
       migration = migration_class.new(client)
-      migration.output = output
+      migration.output = up_output
       migration.up
     end
-    normalize_report(output.string)
-  end
+    assert_equal(expected_up_report, normalize_report(up_output.string))
 
-  def normalize_report(report)
-    report.gsub(/[0-9]+\.[0-9]+s/, "0.0s")
-  end
+    assert_equal(expected_dump, dump)
 
-  def dump
+    down_output = StringIO.new
     open_client do |client|
-      client.dump.body
+      migration = migration_class.new(client)
+      migration.output = down_output
+      migration.down
     end
+    assert_equal(expected_down_report, normalize_report(down_output.string))
+
+    assert_equal("", dump)
   end
 
   sub_test_case("#create_table") do
     test("default") do
-      report = migrate(:up) do |migration|
+      expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY", :key_type=>nil})
+   -> 0.0s
+      REPORT
+      expected_down_report = <<-REPORT
+-- remove_table(:posts)
+   -> 0.0s
+      REPORT
+      expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+      DUMP
+      assert_migrate(expected_up_report,
+                     expected_down_report,
+                     expected_dump) do |migration|
         migration.instance_eval do
           create_table(:posts)
         end
       end
-      assert_equal(<<-REPORT, report)
+    end
+
+    sub_test_case("columns") do
+      sub_test_case("#short_text") do
+        test("default") do
+          expected_up_report = <<-REPORT
 -- create_table(:posts, {:type=>"TABLE_NO_KEY", :key_type=>nil})
    -> 0.0s
-      REPORT
-      assert_equal(<<-DUMP.chomp, dump)
+-- add_column(:posts, :title, {:flags=>["COLUMN_SCALAR"], :value_type=>"ShortText"})
+   -> 0.0s
+          REPORT
+          expected_down_report = <<-REPORT
+-- remove_table(:posts)
+   -> 0.0s
+          REPORT
+          expected_dump = <<-DUMP.chomp
 table_create posts TABLE_NO_KEY
-      DUMP
+column_create posts title COLUMN_SCALAR ShortText
+          DUMP
+          assert_migrate(expected_up_report,
+                         expected_down_report,
+                         expected_dump) do |migration|
+            migration.instance_eval do
+              create_table(:posts) do |table|
+                table.short_text(:title)
+              end
+            end
+          end
+        end
+      end
+
+      sub_test_case("#text") do
+        test("default") do
+          expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY", :key_type=>nil})
+   -> 0.0s
+-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"Text"})
+   -> 0.0s
+          REPORT
+          expected_down_report = <<-REPORT
+-- remove_table(:posts)
+   -> 0.0s
+          REPORT
+          expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+column_create posts content COLUMN_SCALAR Text
+          DUMP
+          assert_migrate(expected_up_report,
+                         expected_down_report,
+                         expected_dump) do |migration|
+            migration.instance_eval do
+              create_table(:posts) do |table|
+                table.text(:content)
+              end
+            end
+          end
+        end
+      end
+
+      sub_test_case("#long_text") do
+        test("default") do
+          expected_up_report = <<-REPORT
+-- create_table(:posts, {:type=>"TABLE_NO_KEY", :key_type=>nil})
+   -> 0.0s
+-- add_column(:posts, :content, {:flags=>["COLUMN_SCALAR"], :value_type=>"LongText"})
+   -> 0.0s
+          REPORT
+          expected_down_report = <<-REPORT
+-- remove_table(:posts)
+   -> 0.0s
+          REPORT
+          expected_dump = <<-DUMP.chomp
+table_create posts TABLE_NO_KEY
+column_create posts content COLUMN_SCALAR LongText
+          DUMP
+          assert_migrate(expected_up_report,
+                         expected_down_report,
+                         expected_dump) do |migration|
+            migration.instance_eval do
+              create_table(:posts) do |table|
+                table.long_text(:content)
+              end
+            end
+          end
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index