Permalink
Browse files

Add spec for :index_names option.

  • Loading branch information...
1 parent 229ea97 commit 4717e2645275d9b2a73ad661694c5bbc336093fc @r-stu31 r-stu31 committed May 30, 2012
Showing with 118 additions and 0 deletions.
  1. +118 −0 spec/extensions/schema_dumper_spec.rb
View
118 spec/extensions/schema_dumper_spec.rb
@@ -340,6 +340,76 @@
END_MIG
end
+ it "should honor the :index_names => false option to not include names of indexes" do
+ @d.meta_def(:indexes) do |t|
+ {:i1=>{:columns=>[:c1], :unique=>false},
+ :t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
+ end
+ @d.dump_table_schema(:t1, :index_names=>false).should == "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1]\n index [:c2, :c1], :unique=>true\nend"
+ @d.dump_schema_migration(:index_names=>false).should == <<-END_MIG
+Sequel.migration do
+ up do
+ create_table(:t1, :ignore_index_errors=>true) do
+ primary_key :c1
+ String :c2, :size=>20
+
+ index [:c1]
+ index [:c2, :c1], :unique=>true
+ end
+
+ create_table(:t2, :ignore_index_errors=>true) do
+ Integer :c1, :null=>false
+ BigDecimal :c2, :null=>false
+
+ primary_key [:c1, :c2]
+
+ index [:c1]
+ index [:c2, :c1], :unique=>true
+ end
+ end
+
+ down do
+ drop_table(:t2, :t1)
+ end
+end
+END_MIG
+ end
+
+ it "should honor the :index_names => :namespace option to include names of indexes with prepended table name" do
+ @d.meta_def(:indexes) do |t|
+ {:i1=>{:columns=>[:c1], :unique=>false},
+ :t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
+ end
+ @d.dump_table_schema(:t1, :index_names=>:namespace).should == "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:t1_i1\n index [:c2, :c1], :unique=>true\nend"
+ @d.dump_schema_migration(:index_names=>:namespace).should == <<-END_MIG
+Sequel.migration do
+ up do
+ create_table(:t1, :ignore_index_errors=>true) do
+ primary_key :c1
+ String :c2, :size=>20
+
+ index [:c1], :name=>:t1_i1
+ index [:c2, :c1], :unique=>true
+ end
+
+ create_table(:t2, :ignore_index_errors=>true) do
+ Integer :c1, :null=>false
+ BigDecimal :c2, :null=>false
+
+ primary_key [:c1, :c2]
+
+ index [:c1], :name=>:t2_i1
+ index [:c2, :c1], :name=>:t2_t1_c2_c1_index, :unique=>true
+ end
+ end
+
+ down do
+ drop_table(:t2, :t1)
+ end
+end
+END_MIG
+ end
+
it "should honor the :indexes => false option to not include indexes" do
@d.meta_def(:indexes) do |t|
{:i1=>{:columns=>[:c1], :unique=>false},
@@ -404,6 +474,54 @@
END_MIG
end
+ it "should honor the :index_names => false option to not include names of indexes when dumping just indexes as a migration" do
+ @d.meta_def(:tables){|o| [:t1]}
+ @d.meta_def(:indexes) do |t|
+ {:i1=>{:columns=>[:c1], :unique=>false},
+ :t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
+ end
+ @d.dump_indexes_migration(:index_names=>false).should == <<-END_MIG
+Sequel.migration do
+ up do
+ add_index :t1, [:c1], :ignore_errors=>true
+ add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
+ end
+
+ down do
+ drop_index :t1, [:c1], :ignore_errors=>true
+ drop_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
+ end
+end
+END_MIG
+ end
+
+ it "should honor the :index_names => :namespace option to include names of indexes with prepended table name when dumping just indexes as a migration" do
+ @d.meta_def(:tables){|o| [:t1, :t2]}
+ @d.meta_def(:indexes) do |t|
+ {:i1=>{:columns=>[:c1], :unique=>false},
+ :t1_c2_c1_index=>{:columns=>[:c2, :c1], :unique=>true}}
+ end
+ @d.dump_indexes_migration(:index_names=>:namespace).should == <<-END_MIG
+Sequel.migration do
+ up do
+ add_index :t1, [:c1], :ignore_errors=>true, :name=>:t1_i1
+ add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
+
+ add_index :t2, [:c1], :ignore_errors=>true, :name=>:t2_i1
+ add_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t2_t1_c2_c1_index, :unique=>true
+ end
+
+ down do
+ drop_index :t2, [:c1], :ignore_errors=>true, :name=>:t2_i1
+ drop_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t2_t1_c2_c1_index, :unique=>true
+
+ drop_index :t1, [:c1], :ignore_errors=>true, :name=>:t1_i1
+ drop_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
+ end
+end
+END_MIG
+ end
+
it "should handle missing index parsing support when dumping index migration" do
@d.meta_def(:tables){|o| [:t1]}
@d.dump_indexes_migration.should == <<-END_MIG

0 comments on commit 4717e26

Please sign in to comment.