Making after_commit hooks testable with transactional fixtures

275 views
Skip to first unread message

Gabe da Silveira

unread,
Oct 11, 2011, 3:57:04 PM10/11/11
to Ruby on Rails: Core
It's sort of annoying not to be able to test after_commit hooks with
transactional fixtures. Mat Brown came up with this solution:

http://outofti.me/post/4777884779/test-after-commit-hooks-with-transactional-fixtures

I am pretty uncomfortable having this monkey patch in my app given its
scope, so I'm wondering if there might be some way to fix this in
Rails proper. Before putting any time into this I wanted to get Core
feedback as to whether the essence of Mat's solution would be
acceptable, or if you anticipate too many problems, or if there is an
alternate approach worth pursuing...

Robert Pankowecki

unread,
Oct 11, 2011, 4:00:38 PM10/11/11
to rubyonra...@googlegroups.com
What's wrong with turning off transactional fixtures in the tests that
check after_commit/after_rollback functionality ? You can check what
you need and clean the db yourself in the test or teardown.

Robert Pankowecki

Gabe da Silveira

unread,
Oct 12, 2011, 5:35:46 PM10/12/11
to Ruby on Rails: Core
Massive overhead in instantiating the fixtures each time. If I were
to start from scratch I would certainly not depend on a large fixture
set, but at this point we depend on transactional fixtures for
performance.

On Oct 11, 2:00 pm, Robert Pankowecki <robert.pankowe...@gmail.com>
wrote:

Will Bryant

unread,
Oct 12, 2011, 5:53:39 PM10/12/11
to rubyonra...@googlegroups.com
You can turn transaction fixtures off for an individual set of tests though, and still run the rest of your test suite quickly.

I was actually asking if anyone wanted after_commit/rollback in their tests a few days ago, in the thread about transactional fixture bloating. No-one seemed to be interested though, so I didn't implement it.

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
>

Robert Pankowecki

unread,
Oct 13, 2011, 1:47:02 AM10/13/11
to rubyonra...@googlegroups.com
On Wed, Oct 12, 2011 at 11:53 PM, Will Bryant <will....@gmail.com> wrote:
> You can turn transaction fixtures off for an individual set of tests though

Exacyly what I mean.

class Test < ActiveSupport::TestCase
self.use_transactional_fixutures = false
end

Betelgeuse

unread,
Oct 13, 2011, 3:16:29 AM10/13/11
to Ruby on Rails: Core
I am interested at least. I use after_commit heavily with resque and
database cleaner is slower than transactional fixtures.
Reply all
Reply to author
Forward
0 new messages