Sha256: 155bf141f7b939b2f53044d35e9b20e6804c4a1fdc7b913e252a2eeafd0e15fb

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

# transaction capable adapters
ADAPTERS = []
ADAPTERS << :postgres if HAS_POSTGRES
ADAPTERS << :mysql    if HAS_MYSQL
ADAPTERS << :sqlite3  if HAS_SQLITE3

if ADAPTERS.any?
  class Sputnik
    include DataMapper::Resource

    property :id, Serial
    property :name, DM::Text
  end

  describe DataMapper::Transaction do
    before :all do
      @repositories = []

      ADAPTERS.each do |name|
        @repositories << repository(name)
      end
    end

    before :each do
      ADAPTERS.each do |name|
        Sputnik.auto_migrate!(name)
      end
    end

    it "should commit changes to all involved adapters on a two phase commit" do
      DataMapper::Transaction.new(*@repositories) do
        ADAPTERS.each do |name|
          repository(name) { Sputnik.create(:name => 'hepp') }
        end
      end

      ADAPTERS.each do |name|
        repository(name) { Sputnik.all.size.should == 1 }
      end
    end

    it "should not commit any changes if the block raises an exception" do
      lambda do
        DataMapper::Transaction.new(*@repositories) do
          ADAPTERS.each do |name|
            repository(name) { Sputnik.create(:name => 'hepp') }
          end
          raise "plur"
        end
      end.should raise_error(Exception, /plur/)

      ADAPTERS.each do |name|
        repository(name) { Sputnik.all.size.should == 0 }
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rpbertp13-dm-core-0.9.11.1 spec/integration/transaction_spec.rb