Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Fixed problem where transaction would be mismatched for the adapter
Browse files Browse the repository at this point in the history
[#1157 state:resolved]
  • Loading branch information
dkubb committed May 21, 2010
1 parent 4d17ca5 commit 7016de2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/dm-transactions/adapters/dm-do-adapter.rb
Expand Up @@ -75,7 +75,8 @@ def close_connection(connection)

# @api private
def transactions
Thread.current[:dm_transactions] ||= []
Thread.current[:dm_transactions] ||= {}
Thread.current[:dm_transactions][object_id] ||= []
end

# Retrieve the current connection for this Adapter.
Expand Down
39 changes: 37 additions & 2 deletions spec/public/dm-transactions_spec.rb
Expand Up @@ -93,8 +93,16 @@ class ::Default
it_should_behave_like 'A Resource supporting Strategic Eager Loading'
end

supported_by :postgres, :mysql, :sqlite3, :oracle, :sqlserver do
describe '#transaction' do
describe '#transaction' do
before :all do
class ::Author
include DataMapper::Resource

property :name, String, :key => true
end
end

supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
before do
@user_model.all.destroy!
end
Expand Down Expand Up @@ -148,6 +156,33 @@ def doit
it 'should return the last statement in the transaction block' do
@user_model.transaction { 1 }.should == 1
end

with_alternate_adapter do
before :all do
class ::Article
include DataMapper::Resource

def self.default_repository_name
:alternate
end

property :title, String, :key => true
end

DataMapper.auto_migrate!(:alternate)
end

it 'should work with other repositories' do
expect {
DataMapper.repository.transaction.commit do
Author.create(:name => 'Dan Kubb')

# save a resource to another repository
Article.create(:title => 'DataMapper Rocks!')
end
}.should_not raise_error
end
end
end
end
end

0 comments on commit 7016de2

Please sign in to comment.