spec/octopus/migration_spec.rb in ar-octopus-0.0.1 vs spec/octopus/migration_spec.rb in ar-octopus-0.0.2
- old
+ new
@@ -1,53 +1,43 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Octopus::Migration do
it "should run just in the master shard" do
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 1)
-
- User.using(:master).find_by_name("Master").should_not be_nil
- User.using(:canada).find_by_name("Master").should be_nil
-
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, 1)
+ migrating_to_version 1 do
+ User.using(:master).find_by_name("Master").should_not be_nil
+ User.using(:canada).find_by_name("Master").should be_nil
+ end
end
it "should run on specific shard" do
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 2)
-
- User.using(:master).find_by_name("Sharding").should be_nil
- User.using(:canada).find_by_name("Sharding").should_not be_nil
-
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, 2)
+ migrating_to_version 2 do
+ User.using(:master).find_by_name("Sharding").should be_nil
+ User.using(:canada).find_by_name("Sharding").should_not be_nil
+ end
end
it "should run on specifieds shards" do
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 3)
-
- User.using(:brazil).find_by_name("Both").should_not be_nil
- User.using(:canada).find_by_name("Both").should_not be_nil
-
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, 3)
+ migrating_to_version 3 do
+ User.using(:brazil).find_by_name("Both").should_not be_nil
+ User.using(:canada).find_by_name("Both").should_not be_nil
+ end
end
it "should run on specified group" do
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 4)
-
- User.using(:canada).find_by_name("Group").should_not be_nil
- User.using(:brazil).find_by_name("Group").should_not be_nil
- User.using(:russia).find_by_name("Group").should_not be_nil
-
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, 4)
+ migrating_to_version 4 do
+ User.using(:canada).find_by_name("Group").should_not be_nil
+ User.using(:brazil).find_by_name("Group").should_not be_nil
+ User.using(:russia).find_by_name("Group").should_not be_nil
+ end
end
it "should run on multiples groups" do
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 5)
-
- User.using(:canada).where(:name => "MultipleGroup").all.size.should == 2
- User.using(:brazil).where(:name => "MultipleGroup").all.size.should == 2
- User.using(:russia).where(:name => "MultipleGroup").all.size.should == 2
-
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT, 5)
+ migrating_to_version 5 do
+ User.using(:canada).where(:name => "MultipleGroup").all.size.should == 2
+ User.using(:brazil).where(:name => "MultipleGroup").all.size.should == 2
+ User.using(:russia).where(:name => "MultipleGroup").all.size.should == 2
+ end
end
describe "should raise a exception when" do
it "you specify a invalid shard name" do
lambda { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 6) }.should raise_error("Nonexistent Shard Name: amazing_shard")
@@ -64,16 +54,29 @@
it "you specify a invalid group name, even if you have multiple groups, and one of them are right" do
lambda { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, 9) }.should raise_error("Nonexistent Group Name: invalid_group")
end
end
- describe "when using replication" do
+ describe "when using replication" do
it "should run writes on master when you use replication" do
- pending()
+ using_enviroment :production_replicated do
+ migrating_to_version 10 do
+ Cat.using(:master).where(:name => "Replication").first.should_not be_nil
+ Cat.where(:name => "Replication").first.should be_nil
+ end
+ end
end
it "should run in all shards, master or another shards" do
- pending()
+ using_enviroment :production_replicated do
+ migrating_to_version 11 do
+ [:slave4, :slave1, :slave2, :slave3].each do |sym|
+ Cat.using(sym).find_by_name("Slaves").should_not be_nil
+ end
+
+ Cat.using(:master).find_by_name("Slaves").should be_nil
+ end
+ end
end
end
end