database_cleaner-active_record icon indicating copy to clipboard operation
database_cleaner-active_record copied to clipboard

Problem with restarting a transaction when using transaction strategy

Open kenips opened this issue 11 years ago • 1 comments

I have a method like this:

def make_foo(bar, params)
  foo = nil 
  self.transaction do
    foo = self.create!(name: bar) rescue nil
  end
  unless foo
    self.transaction do
      foo = Something.find_by(name: bar).update(params) 
    end
  end
  foo
end

This method relies on a unique index on name to raise PG:Error, in which it will update the object instead. This is all fine until I use transaction in database_cleaner and it complains about


I tried using truncation for the test, and it somewhat works, but I'm just wondering if this is something that can be supported (sounds like nested transaction?)? Essentially I'd like to get the transaction to restart within the test, if that's possible.

kenips avatar May 28 '13 20:05 kenips

+1

zhenyuchen avatar Jun 03 '13 09:06 zhenyuchen