spec/integration/lhm_spec.rb in lhm-1.0.3 vs spec/integration/lhm_spec.rb in lhm-1.1.0
- old
+ new
@@ -14,11 +14,11 @@
before(:each) do
table_create(:users)
end
it "should add a column" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_column(:logins, "INT(12) DEFAULT '0'")
end
slave do
table_read(:users).columns["logins"].must_equal({
@@ -30,71 +30,91 @@
end
it "should copy all rows" do
23.times { |n| execute("insert into users set reference = '#{ n }'") }
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_column(:logins, "INT(12) DEFAULT '0'")
end
slave do
count_all(:users).must_equal(23)
end
end
it "should remove a column" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.remove_column(:comment)
end
slave do
table_read(:users).columns["comment"].must_equal nil
end
end
it "should add an index" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_index([:comment, :created_at])
end
slave do
- key?(:users, [:comment, :created_at]).must_equal(true)
+ index_on_columns?(:users, [:comment, :created_at]).must_equal(true)
end
end
+ it "should add an index with a custom name" do
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
+ t.add_index([:comment, :created_at], :my_index_name)
+ end
+
+ slave do
+ index?(:users, :my_index_name).must_equal(true)
+ end
+ end
+
it "should add an index on a column with a reserved name" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_index(:group)
end
slave do
- key?(:users, :group).must_equal(true)
+ index_on_columns?(:users, :group).must_equal(true)
end
end
it "should add a unqiue index" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_unique_index(:comment)
end
slave do
- key?(:users, :comment, :unique).must_equal(true)
+ index_on_columns?(:users, :comment, :unique).must_equal(true)
end
end
it "should remove an index" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.remove_index([:username, :created_at])
end
slave do
- key?(:users, [:username, :created_at]).must_equal(false)
+ index_on_columns?(:users, [:username, :created_at]).must_equal(false)
end
end
+ it "should remove an index with a custom name" do
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
+ t.remove_index(:reference, :index_users_on_reference)
+ end
+
+ slave do
+ index?(:users, :index_users_on_reference).must_equal(false)
+ end
+ end
+
it "should apply a ddl statement" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.ddl("alter table %s add column flag tinyint(1)" % t.name)
end
slave do
table_read(:users).columns["flag"].must_equal({
@@ -104,11 +124,11 @@
})
end
end
it "should change a column" do
- Lhm.change_table(:users) do |t|
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
t.change_column(:comment, "varchar(20) DEFAULT 'none' NOT NULL")
end
slave do
table_read(:users).columns["comment"].must_equal({
@@ -120,11 +140,11 @@
end
it "should change the last column in a table" do
table_create(:small_table)
- Lhm.change_table(:small_table) do |t|
+ Lhm.change_table(:small_table, :atomic_switch => false) do |t|
t.change_column(:id, "int(5)")
end
slave do
table_read(:small_table).columns["id"].must_equal({
@@ -144,11 +164,12 @@
execute("insert into users set reference = '#{ 100 + n }'")
sleep(0.17)
end
end
- Lhm.change_table(:users, :stride => 10, :throttle => 97) do |t|
+ options = { :stride => 10, :throttle => 97, :atomic_switch => false }
+ Lhm.change_table(:users, options) do |t|
t.add_column(:parallel, "INT(10) DEFAULT '0'")
end
insert.join
@@ -165,10 +186,11 @@
execute("delete from users where id = '#{ n + 1 }'")
sleep(0.17)
end
end
- Lhm.change_table(:users, :stride => 10, :throttle => 97) do |t|
+ options = { :stride => 10, :throttle => 97, :atomic_switch => false }
+ Lhm.change_table(:users, options) do |t|
t.add_column(:parallel, "INT(10) DEFAULT '0'")
end
delete.join