[Proposal] Instance invoked blocks for ActionDispatch::Integration::Runner#open_session

31 views
Skip to first unread message

Chris Nicola

unread,
Aug 3, 2016, 4:12:24 PM8/3/16
to Ruby on Rails: Core
Currently the way `open_session` works requires you to change your test code to call everything on the passed in session in the block. I found this to be confusing and the documentation around how this work was a bit thin.

I ended up overriding `open_session` in our project so that it allowed for a block that takes no arguments and calls it as an instance_eval'd block on the session. I've linked to a gist with the code below and how it works.

I think this helps improve the consistency of the test code inside and outside of `open_session` blocks which was a sticking point for me while converting our old controller tests.


I'd be curious what people think of this approach. It also maintains the option of supplying an argument in the block and having it work the old way. This is similar to how the Sequel gem does blocks with virtual rows.

Francesco Belladonna

unread,
Aug 3, 2016, 7:54:10 PM8/3/16
to Ruby on Rails: Core
It seems reasonable, more readable in the way you propose.

Chris Nicola

unread,
Aug 4, 2016, 12:35:35 PM8/4/16
to Ruby on Rails: Core
So ignore this proposal, it needs more thought. Some further experimentation shows that this already does work in a block without a session argument. I'm not sure why it appeared that it did not before to me, but it was my mistake.
Reply all
Reply to author
Forward
0 new messages