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.
I have a method like this:
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.