Permalink
Browse files

Handle transactions during testing to allow each test to be independe…

…nt of the other ones.
  • Loading branch information...
francois committed Oct 17, 2008
1 parent d24c7b6 commit 97a7f253ff09aa18bc95ad549dccac15ae27e636
Showing with 27 additions and 0 deletions.
  1. +23 −0 test/test_helper.rb
  2. +4 −0 test/unit/article_test.rb
View
@@ -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}
@@ -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.