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.

https://gist.github.com/chrisnicola/597725f548287f7e6f129567e8ab6f62

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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to