spec/models/shard_spec.rb in switchman-0.0.1 vs spec/models/shard_spec.rb in switchman-1.0.0

- old
+ new

@@ -101,10 +101,34 @@ lambda { Shard.lookup('jacob') }.should raise_error(ArgumentError) end end describe ".with_each_shard" do + describe ":exception" do + it "should default to :raise" do + lambda { Shard.with_each_shard { raise "error" } }.should raise_error + end + + it "should :ignore" do + Shard.with_each_shard(exception: :ignore) { raise "error" }.should == [] + end + + it "should :defer" do + counter = 0 + lambda { Shard.with_each_shard(exception: :defer) { counter += 1; raise "error" } }.should raise_error + # called more than once + counter.should > 1 + end + + it "should call a proc" do + counter = 0 + Shard.with_each_shard(exception: -> { counter += 1 }) { raise "error" }.should == [] + # called more than once + counter.should > 1 + end + end + context "non-transactional" do self.use_transactional_fixtures = false it "should disconnect when switching among different database servers" do User.connection @@ -200,26 +224,23 @@ s.name s.should_not be_changed end it "should fall back to shard_name in the config if nil" do - db = DatabaseServer.new - db.config = { :adapter => 'mysql', :database => 'canvas', :shard_name => 'yoyoyo' } - shard = Shard.new(:database_server => db) + db = DatabaseServer.new(config: { adapter: 'mysql', database: 'canvas', shard_name: 'yoyoyo' }) + shard = Shard.new(database_server: db) shard.name.should == 'yoyoyo' end it "should fall back to the database_server if nil" do - db = DatabaseServer.new - db.config = { :adapter => 'mysql', :database => 'canvas' } - shard = Shard.new(:database_server => db) + db = DatabaseServer.new(config: { adapter: 'mysql', database: 'canvas' }) + shard = Shard.new(database_server: db) shard.name.should == 'canvas' end it "should get it from the postgres connection if not otherwise specified" do - db = DatabaseServer.create - db.config = { :adapter => 'postgresql', :database => 'notme' } - shard = Shard.new(:database_server => db) + db = DatabaseServer.create(config: { adapter: 'postgresql', database: 'notme' }) + shard = Shard.new(database_server: db) shard.database_server = db connection = mock() connection.stubs(:open_transactions).returns(0) connection.expects(:schemas).returns(['canvas', 'public']).once connection.expects(:schema_search_path=).with(nil).once