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

Commit

Permalink
Makes #transaction method available on require 'dm-transactions'
Browse files Browse the repository at this point in the history
If dm-transactions is required explicitly, assume
that an adapter with builtin transaction support
will be used eventually.

[#1232 state:resolved]
  • Loading branch information
snusnu committed May 1, 2010
1 parent 627b43d commit eaca32f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/dm-transactions.rb
Expand Up @@ -344,13 +344,6 @@ def rollback_and_close_adapter(adapter)
module Adapter
extend Chainable

# @api private
def self.included(base)
[ :Repository, :Model, :Resource ].each do |name|
DataMapper.const_get(name).send(:include, Transaction.const_get(name))
end
end

# Produces a fresh transaction primitive for this Adapter
#
# Used by Transaction to perform its various tasks.
Expand Down Expand Up @@ -487,6 +480,11 @@ def transaction
model.transaction { |*block_args| yield(*block_args) }
end
end # module Resource

[ :Repository, :Model, :Resource ].each do |name|
DataMapper.const_get(name).send(:include, Transaction.const_get(name))
end

end # class Transaction

module Adapters
Expand Down
14 changes: 14 additions & 0 deletions spec/dm-transactions_spec.rb
Expand Up @@ -67,6 +67,20 @@ class ::Default
@paragraph_model = Blog::Paragraph
end

describe "require 'dm-transactions" do

it 'should not perform adapter setup' do
lambda { DataMapper.repository.adapter }.should raise_error(DataMapper::RepositoryNotSetupError)
end

%w[Repository Model Resource].each do |name|
it "should make #transaction available on DataMapper::#{name}" do
DataMapper.const_get(name).instance_methods.include?('transaction').should be_true
end
end

end

supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
before :all do
user = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test')
Expand Down

0 comments on commit eaca32f

Please sign in to comment.