spec/replicat/replicable_spec.rb in replicat-0.0.1 vs spec/replicat/replicable_spec.rb in replicat-0.0.2
- old
+ new
@@ -1,16 +1,8 @@
require "spec_helper"
describe Replicat::Replicable do
- describe ".has_any_replication?" do
- context "with any replication in connection settings" do
- it "returns true" do
- Recipe.should have_any_replication
- end
- end
- end
-
describe ".connection_with_proxy" do
context "with non-replicable model" do
it "returns normal connection" do
User.connection.should_not be_a Replicat::Proxy
end
@@ -48,9 +40,51 @@
Recipe.first.should_not == nil
end
Recipe.using(:slave2) do
Recipe.first.should == nil
end
+ end
+ end
+
+ context "with no block" do
+ it "can be used as scope" do
+ Recipe.using(:slave1).create(title: "test")
+ Recipe.using(:slave1).first.should_not == nil
+ end
+ end
+
+ context "with scope" do
+ it "works well" do
+ Recipe.all.using(:slave1).create(title: "test")
+ Recipe.where(title: "test").using(:slave1).first.should_not == nil
+ end
+ end
+
+ context "with belongs_to association" do
+ let!(:ingredient) do
+ Ingredient.using(:slave1).create(name: "test", recipe_id: recipe.id)
+ end
+
+ let(:recipe) do
+ Recipe.using(:slave1).create(title: "test")
+ end
+
+ it "works well" do
+ Recipe.using(:slave1) { ingredient.recipe.should == recipe }
+ end
+ end
+
+ context "with has_many association" do
+ let!(:ingredient) do
+ Ingredient.using(:slave1) { Ingredient.create(name: "test", recipe_id: recipe.id) }
+ end
+
+ let(:recipe) do
+ Recipe.using(:slave1) { Recipe.create(title: "test") }
+ end
+
+ it "works well" do
+ Ingredient.using(:slave1) { recipe.ingredients.should == [ingredient] }
end
end
end
describe ".proxy" do