spec/octopus/model_spec.rb in ar-octopus-0.0.1 vs spec/octopus/model_spec.rb in ar-octopus-0.0.2

- old
+ new

@@ -28,30 +28,30 @@ User.using(:alone_shard).count.should == 1 User.using(:canada).count.should == 0 User.using(:brazil).count.should == 0 User.count.should == 0 end - + describe "passing a block" do it "should allow queries be executed inside the block, ponting to a specific shard" do - User.using(:canada) do - User.create(:name => "oi") - end + User.using(:canada) do + User.create(:name => "oi") + end - User.using(:canada).count.should == 1 - User.using(:master).count.should == 0 - User.count.should == 0 - end + User.using(:canada).count.should == 1 + User.using(:master).count.should == 0 + User.count.should == 0 + end - it "should allow execute queries inside a model" do - u = User.new - u.awesome_queries() - User.using(:canada).count.should == 1 - User.count.should == 0 - end + it "should allow execute queries inside a model" do + u = User.new + u.awesome_queries() + User.using(:canada).count.should == 1 + User.count.should == 0 + end end - + describe "when you have a relationship" do it "should find all models in the specified shard" do pending() # brazil_client = Client.using(:brazil).create!(:name => "Brazil Client") # master_client = Client.create!(:name => "Master Client") @@ -61,62 +61,41 @@ # c = Client.using(:brazil).find_by_name("Brazil Client") # Client.using(:master).create!(:name => "teste") # c.items.should == [item_brazil] end end - + describe "raising errors" do it "should raise a error when you specify a shard that doesn't exist" do lambda { User.using(:crazy_shard) }.should raise_error("Nonexistent Shard Name: crazy_shard") end end end describe "using a postgresql shard" do - after(:each) do - User.using(:postgresql_shard).delete_all - end - it "should update the Arel Engine" do User.using(:postgresql_shard).arel_engine.connection.adapter_name.should == "PostgreSQL" User.using(:alone_shard).arel_engine.connection.adapter_name.should == "MySQL" end - + it "should works with writes and reads" do - pending() - #u = User.using(:postgresql_shard).create!(:name => "PostgreSQL User") - # #User.using(:postgresql_shard).arel_table.columns.should == "" - # User.using(:postgresql_shard).scoped.should == "" - # User.using(:alone_shard).find(:all).should == [] + u = User.using(:postgresql_shard).create!(:name => "PostgreSQL User") + User.using(:postgresql_shard).all.should == [u] + User.using(:alone_shard).find(:all).should == [] end end - + describe "#replicated_model method" do - before(:each) do - Octopus.stub!(:env).and_return("production_replicated") - @proxy = Octopus::Proxy.new(Octopus.config()) - #TODO - This is ugly, but is better than mocking - ActiveRecord::Base.class_eval("@@connection_proxy = nil") - #TODO - This is ugly, but is better than mocking - end - - after(:each) do - #TODO - One little Kitten dies each time this code is executed. - ActiveRecord::Base.class_eval("@@connection_proxy = nil") - end - it "should be replicated" do - ActiveRecord::Base.connection_proxy.replicated.should be_true + using_enviroment :production_replicated do + ActiveRecord::Base.connection_proxy.replicated.should be_true + end end - + it "should mark the Cat model as replicated" do - Cat.all.should == [] - ActiveRecord::Base.connection_proxy.replicated_models.first.should == "Cat" - end - end - - describe "#sharded_by method" do - it "should send all queries to the specify shard" do - pending() + using_enviroment :production_replicated do + Cat.all.should == [] + ActiveRecord::Base.connection_proxy.replicated_models.first.should == "Cat" + end end end end \ No newline at end of file