spec/integration/lhm_spec.rb in lhm-1.3.0 vs spec/integration/lhm_spec.rb in lhm-2.0.0
- old
+ new
@@ -11,12 +11,52 @@
before(:each) { connect_master! }
describe "changes" do
before(:each) do
table_create(:users)
+ table_create(:tracks)
+ table_create(:permissions)
end
+ describe "when providing a subset of data to copy" do
+
+ before do
+ execute("insert into tracks set id = 13, public = 0")
+ 11.times { |n| execute("insert into tracks set id = #{n + 1}, public = 1") }
+ 11.times { |n| execute("insert into permissions set track_id = #{n + 1}") }
+
+ Lhm.change_table(:permissions, :atomic_switch => false) do |t|
+ t.filter("inner join tracks on tracks.`id` = permissions.`track_id` and tracks.`public` = 1")
+ end
+ end
+
+ describe "when no additional data is inserted into the table" do
+
+ it "migrates the existing data" do
+ slave do
+ count_all(:permissions).must_equal(11)
+ end
+ end
+ end
+
+ describe "when additional data is inserted" do
+
+ before do
+ execute("insert into tracks set id = 14, public = 0")
+ execute("insert into tracks set id = 15, public = 1")
+ execute("insert into permissions set track_id = 14")
+ execute("insert into permissions set track_id = 15")
+ end
+
+ it "migrates all data" do
+ slave do
+ count_all(:permissions).must_equal(13)
+ end
+ end
+ end
+ end
+
it "should add a column" do
Lhm.change_table(:users, :atomic_switch => false) do |t|
t.add_column(:logins, "INT(12) DEFAULT '0'")
end
@@ -101,14 +141,24 @@
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)
+ t.remove_index([:username, :group])
end
slave do
- index?(:users, :index_users_on_reference).must_equal(false)
+ index?(:users, :index_with_a_custom_name).must_equal(false)
+ end
+ end
+
+ it "should remove an index with a custom name by name" do
+ Lhm.change_table(:users, :atomic_switch => false) do |t|
+ t.remove_index(:irrelevant_column_name, :index_with_a_custom_name)
+ end
+
+ slave do
+ index?(:users, :index_with_a_custom_name).must_equal(false)
end
end
it "should apply a ddl statement" do
Lhm.change_table(:users, :atomic_switch => false) do |t|