rails/rails — pull request #17256 by leemhenson (2014-10-14 17:45:16+00:00)
Title: support pg's tx access and deferrable modes via transaction(opts)

Hey hey. Long time lurker, first time committer.

I wanted support for postgresql's finer-grained transaction isolation controls:

http://www.postgresql.org/docs/9.3/static/sql-set-transaction.html

So I implemented it by offering the ability to pass a hash instead of just the isolation level symbol:

```ruby

Model.transaction(isolation: :serializable) do
# some important read-write stuff
end

Model.transaction(isolation: { level: :serializable, read_only: true, deferrable: true }) do
# some important but read-only stuff
end
```

Testing this stuff is pretty hard I guess, based on this comment:

https://github.com/musicglue/rails/blob/b010ad0ae1bb1e05b7495d460dade22751a59a8a/activerecord/test/cases/transaction_isolation_test.rb#L81

I've got a couple of specs that prove that the access mode works (ie. you can't write in a readonly transaction), but testing deferrable seems tricky.

What do you think?