Skip to content

Commit

Permalink
Handle transactions during testing to allow each test to be independe…
Browse files Browse the repository at this point in the history
…nt of the other ones.
  • Loading branch information
francois committed Oct 17, 2008
1 parent d24c7b6 commit 97a7f25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/test_helper.rb
Expand Up @@ -55,6 +55,29 @@ class Test::Unit::TestCase
# fixtures :all

# Add more helper methods to be used by all tests here...
def logger
Rails.logger
end

def self.logger
Rails.logger
end

setup do
@__transaction = DataMapper::Transaction.new(DataMapper.repository(:default))
@__transaction.begin

# FIXME: Should I really be calling #push_transaction like that, or is there a better way?
DataMapper.repository(:default).adapter.push_transaction(@__transaction)
end

teardown do
if @__transaction
DataMapper.repository(:default).adapter.pop_transaction
@__transaction.rollback
@__transaction = nil
end
end
end

Dir[File.join(Rails.root, "app", "models", "*")].each {|f| require f}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/article_test.rb
Expand Up @@ -5,4 +5,8 @@ def test_create
article = Article.create(:title => "First Post", :body => "This is my first-ever post", :published_at => Time.now.utc)
assert !article.new_record?
end

def test_database_is_empty
assert Article.all.empty?
end
end

0 comments on commit 97a7f25

Please sign in to comment.