Skip to content

Commit

Permalink
Add spec for :index_names option.
Browse files Browse the repository at this point in the history
  • Loading branch information
oldgreen committed May 30, 2012
1 parent 229ea97 commit 4717e26
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions spec/extensions/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4717e26

Please sign in to comment.