As penance, I dug a little. It looks like you'd need to spin up a block-less version of active_record/connection_adapters/abstract/database_statements.rb #transaction (rails 2.3.x). Could be painful because that method 'aint simple.<div>
<br></div><div>However. I wonder. If you're on 1.9 could something cunning be done with Fibers being passed into the block form of transaction ?</div><div><br></div><div>However(again) might it be easier to just:</div>
<div><br></div><div>Before(:all) do</div><div> # create whatever</div><div>end</div><div><br></div><div>After(:all) do</div><div> # destroy whatever </div><div> # or</div><div> # use database_cleaner to truncate the DB</div>
<div>end</div><div><br></div><div>?<br><div class="gmail_quote">On 8 October 2010 12:07, Murray Steele <span dir="ltr"><<a href="mailto:murray.steele@gmail.com">murray.steele@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Ecch. Actually reading the linked-to article reveals what you're trying to do. My comment is pointless. Ignore me. I wasn't here.<div><div></div><div class="h5"><br><br><div class="gmail_quote">On 8 October 2010 12:03, Murray Steele <span dir="ltr"><<a href="mailto:murray.steele@gmail.com" target="_blank">murray.steele@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I thought that RSpec (via rspec-rails) respected the use_transactional_fixtures (e.g. wrap all the specs in a transaction) stuff in ActiveSupport::TestCase? Am I wrong?<div>
<div></div><div><br><br><div class="gmail_quote">On 8 October 2010 11:40, Matthew Willson <span dir="ltr"><<a href="mailto:matthew@playlouder.com" target="_blank">matthew@playlouder.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can't speak for datamapper, or for RSpec infact, but here's a little test mixin we use with Sequel and test/spec in case a similar approach works.<br>
<br>
module TransactionalTestCase<br>
def run(*args, &block)<br>
database.transaction do<br>
super<br>
raise Sequel::Error::Rollback<br>
end<br>
end<br>
end<br>
<div><div></div><div><br>
On 8 Oct 2010, at 11:32, Tim Cowlishaw wrote:<br>
<br>
> Hey all,<br>
><br>
> I stumbled across Xavier Shay's article on setting up RSpec to use<br>
> transactional before(:all) blocks with datamapper the other day<br>
> (<a href="http://rhnh.net/2010/10/06/transactional-before-all-with-rspec-and-datamapper" target="_blank">http://rhnh.net/2010/10/06/transactional-before-all-with-rspec-and-datamapper</a>),<br>
> which is convenient as it's something I've been meaning to do for ages<br>
> on one of our codebases that has a rather large test suite with lots<br>
> of setup in before(:each) blocks. Therefore, I thought I'd spend a bit<br>
> of time trying to get his solution working with ActiveRecord, rather<br>
> than Datamapper. However, because ActiveRecord's transaction interface<br>
> requires you to pass a block to the transaction method, containing the<br>
> work to be done within the transaction, rather than offering<br>
> transaction.begin and transaction.rollback methods a la datamapper,<br>
> this is a little trickier than expected. There is<br>
> ActiveRecord::Base.connection.begin_db_transaction, and<br>
> ActiveRecord::Base.rollback_db_transaction, but these don't handle<br>
> emulating nesting transactions with savepoints as<br>
> ActiveRecord::Base.transaction does, meaning I'd have to reimplement<br>
> that seperately - not an insurmountable task, but a sufficiently<br>
> complex bit of work to make me nervous. Therefore, has anyone run into<br>
> a similar need (to make before(:all) blocks transactional in rspec)<br>
> before? if so, how did you manage it?<br>
><br>
> Cheers,<br>
><br>
> Tim<br>
> _______________________________________________<br>
> Chat mailing list<br>
> <a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
> <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br>
</div></div><font color="#888888">--<br>
Matthew Willson<br>
Development Lead, MSP / Playlouder<br>
</font><div><div></div><div><br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br></div>