I've just remembered another use case for this requested feature.

In Rails you can start the console inside a transaction with

rails console --sandbox

This is how it is implemented in Rails:

activerecord/lib/active_record/railties/console_sandbox.rb:

ActiveRecord::Base.connection.increment_open_transactions
ActiveRecord::Base.connection.begin_db_transaction
at_exit do
  ActiveRecord::Base.connection.rollback_db_transaction
  ActiveRecord::Base.connection.decrement_open_transactions
end

See how limited Sequel is by not allowing the start-finish of transactions in separate pieces of code?

Although this practice shouldn't be recommended, developers should be allowed to do this if they wanted to.

There are some situations, like the sandbox above and the RSpec before(:all), where this is very handy.

Sorry, I haven't tested your workaround over this limitation yet because I still couldn't find free time, but I thought I should mention this other use case now that I've remembered about it.

Cheers,
Rodrigo.

Em 24-04-2012 10:55, Rodrigo Rosenfeld Rosas escreveu:
Hello,

I can deal with transactions in RSpec using

around(:each){|example| DB.transaction(savepoint: true) { example.run; raise Sequel::Error::Rollback } }

By the way, shouldn't catch-throw be used instead of begin-raise-rescue? Well, maybe not since this will most probably be used for exceptional cases.

Moving on, the problem is that I'd like to have a set of records to be created for context, but only once or it would be too slow to run the spec.

But RSpec doesn't support an around(:all) and Sequel doesn't support the usage of transactions without the use of blocks.

I'd like to be able to do something like this:

context "some sample records exists" do
  before(:all) do
    @sample_records_transaction = DB.transaction(savepoint: true)
    create_sample_records
  end

after(:all) { @sample_records_transaction.rollback! } # or even raise Rollback

  # examples here
end

Could you please add support for using transactions this way?

Thanks in advance,
Rodrigo.


--
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to